mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
finished contact migration to typescript
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
import AppError from "../../errors/AppError";
|
||||
import Contact from "../../models/Contact";
|
||||
|
||||
interface ExtraInfo {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface Request {
|
||||
name: string;
|
||||
number: string;
|
||||
email?: string;
|
||||
extraInfo?: ExtraInfo[];
|
||||
}
|
||||
|
||||
const CreateContactService = async ({
|
||||
name,
|
||||
number,
|
||||
email
|
||||
email,
|
||||
extraInfo
|
||||
}: Request): Promise<Contact> => {
|
||||
const numberExists = await Contact.findOne({
|
||||
where: { number }
|
||||
@@ -20,11 +27,17 @@ const CreateContactService = async ({
|
||||
throw new AppError("A contact with this number already exists.");
|
||||
}
|
||||
|
||||
const contact = await Contact.create({
|
||||
name,
|
||||
number,
|
||||
email
|
||||
});
|
||||
const contact = await Contact.create(
|
||||
{
|
||||
name,
|
||||
number,
|
||||
email,
|
||||
extraInfo
|
||||
},
|
||||
{
|
||||
include: ["extraInfo"]
|
||||
}
|
||||
);
|
||||
|
||||
return contact;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user