finished contact migration to typescript

This commit is contained in:
canove
2020-09-19 21:41:28 -03:00
parent 5b54c4df41
commit 70c391e8ef
4 changed files with 235 additions and 230 deletions

View File

@@ -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;
};