fix: when deleting a message in whatsapp, delete the message in chatwoot too

The message model schema was changed. Old format in message model was field chatwootMessageId. Now we have a document chatwoot with new properties.

I cant find a simple way to create a migration function up then the old field was no migrate to new format.
This commit is contained in:
jaison-x
2023-12-20 17:53:37 -03:00
parent 060a945aea
commit 07e8449379
4 changed files with 100 additions and 26 deletions

View File

@@ -10,6 +10,12 @@ class Key {
participant?: string;
}
class ChatwootMessage {
messageId?: number;
inboxId?: number;
conversationId?: number;
}
export class MessageRaw {
_id?: string;
key?: Key;
@@ -22,7 +28,7 @@ export class MessageRaw {
source?: 'android' | 'web' | 'ios';
source_id?: string;
source_reply_id?: string;
chatwootMessageId?: string;
chatwoot?: ChatwootMessage;
}
const messageSchema = new Schema<MessageRaw>({
@@ -40,10 +46,14 @@ const messageSchema = new Schema<MessageRaw>({
source: { type: String, minlength: 3, enum: ['android', 'web', 'ios'] },
messageTimestamp: { type: Number, required: true },
owner: { type: String, required: true, minlength: 1 },
chatwootMessageId: { type: String, required: false },
chatwoot: {
messageId: { type: Number },
inboxId: { type: Number },
conversationId: { type: Number },
},
});
messageSchema.index({ chatwootMessageId: 1, owner: 1 });
messageSchema.index({ 'chatwoot.messageId': 1, owner: 1 });
messageSchema.index({ 'key.id': 1 });
messageSchema.index({ 'key.id': 1, owner: 1 });
messageSchema.index({ owner: 1 });