mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: support delete many attachments
This commit is contained in:
parent
90efbf54e5
commit
ba729de340
@ -146,24 +146,23 @@ export class MessageService extends BaseService<
|
||||
>,
|
||||
criteria: TFilterQuery<Attachment>,
|
||||
) {
|
||||
// todo: handle deleteMany
|
||||
try {
|
||||
this.logger.log(
|
||||
'deleting attachment messages containing deleted images',
|
||||
criteria,
|
||||
);
|
||||
const foundAttachment = await this.attachmentService.findOne(criteria);
|
||||
if (!foundAttachment) {
|
||||
return;
|
||||
const foundAttachments = await this.attachmentService.find(criteria);
|
||||
|
||||
for (const attachment of foundAttachments) {
|
||||
await this.updateMany(
|
||||
{
|
||||
'message.attachment.payload.id': attachment.id,
|
||||
},
|
||||
{
|
||||
['message.attachment.payload.id' as any]: null,
|
||||
},
|
||||
);
|
||||
}
|
||||
await this.updateMany(
|
||||
{
|
||||
'message.attachment.payload.id': criteria._id,
|
||||
},
|
||||
{
|
||||
['message.attachment.payload.id' as any]: null,
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
'Unable to cleanup old messages with attachment ids',
|
||||
|
Loading…
Reference in New Issue
Block a user