mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
fix: apps throws an error when importing contacts from phone
This commit is contained in:
@@ -35,7 +35,7 @@ const ListContactsService = async ({
|
||||
where: whereCondition,
|
||||
limit,
|
||||
offset,
|
||||
order: [["createdAt", "DESC"]]
|
||||
order: [["name", "ASC"]]
|
||||
});
|
||||
|
||||
const hasMore = count > offset + contacts.length;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import AppError from "../../errors/AppError";
|
||||
import GetDefaultWhatsApp from "../../helpers/GetDefaultWhatsApp";
|
||||
import { getWbot } from "../../libs/wbot";
|
||||
import Contact from "../../models/Contact";
|
||||
@@ -22,7 +21,20 @@ const ImportContactsService = async (): Promise<void> => {
|
||||
if (phoneContacts) {
|
||||
await Promise.all(
|
||||
phoneContacts.map(async ({ number, name }) => {
|
||||
await Contact.create({ number, name });
|
||||
if (!number) {
|
||||
return null;
|
||||
}
|
||||
if (!name) {
|
||||
name = number;
|
||||
}
|
||||
|
||||
const numberExists = await Contact.findOne({
|
||||
where: { number }
|
||||
});
|
||||
|
||||
if (numberExists) return null;
|
||||
|
||||
return Contact.create({ number, name });
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user