fix: Fixed the problem when do not save contacts when receive messages

This commit is contained in:
Davidson Gomes
2023-07-08 07:15:34 -03:00
parent 437803da07
commit eca4285ea8
6 changed files with 124 additions and 12 deletions

View File

@@ -53,6 +53,40 @@ export class ContactRepository extends Repository {
}
}
public async update(
data: ContactRaw,
instanceName: string,
saveDb = false,
): Promise<IInsert> {
try {
if (this.dbSettings.ENABLED && saveDb) {
const contact = await this.contactModel.findOneAndUpdate(
{ id: data.id },
{ ...data },
);
return { insertCount: contact ? 1 : 0 };
}
const store = this.configService.get<StoreConf>('STORE');
if (store.CONTACTS) {
this.writeStore({
path: join(this.storePath, 'contacts', instanceName),
fileName: data.id,
data,
});
return { insertCount: 1 };
}
return { insertCount: 0 };
} catch (error) {
return error;
} finally {
data = undefined;
}
}
public async find(query: ContactQuery): Promise<ContactRaw[]> {
try {
if (this.dbSettings.ENABLED) {