Commit de correção de validação.

pull/21/head
adriano 2023-04-04 09:30:28 -03:00
parent 3c3a8107ac
commit 6d9bef094f
5 changed files with 35 additions and 10 deletions

View File

@ -108,6 +108,12 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
console.log('xxxxxxxxxxx profilePicUrl: ',profilePicUrl)
// console.log(`newContact.name: ${newContact.name}\n
// newContact.number: ${newContact.number}\n
// newContact.email: ${newContact.email}\n
// newContact.extraInfo: ${newContact.extraInfo}`)
let name = newContact.name
let number = validNumber
let email = newContact.email

View File

@ -41,7 +41,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
try {
await QuickAnswerSchema.validate(newQuickAnswer);
} catch (err) {
} catch (err:any) {
throw new AppError(err.message);
}
@ -79,7 +79,7 @@ export const update = async (
try {
await schema.validate(quickAnswerData);
} catch (err) {
} catch (err: any) {
throw new AppError(err.message);
}

View File

@ -23,7 +23,8 @@ const CreateContactService = async ({
email = "",
profilePicUrl='',
extraInfo = []
}: Request): Promise<Contact> => {
}: Request): Promise<Contact> => {
const numberExists = await Contact.findOne({
where: { number }
});

View File

@ -21,7 +21,7 @@ interface Request {
contactData: ContactData;
contactId: string;
}
const UpdateContactService = async ({
contactData,
@ -29,6 +29,8 @@ const UpdateContactService = async ({
}: Request): Promise<Contact> => {
const { email, name, number, extraInfo } = contactData;
// console.log('email, name, number, extraInfo: ', email, name, number, extraInfo)
const contact = await Contact.findOne({
where: { id: contactId },
attributes: ["id", "name", "number", "email", "profilePicUrl"],
@ -55,18 +57,34 @@ const UpdateContactService = async ({
}
})
);
}
}
const oldNumber = contact.number
const oldNumber = contact.number
//Solução para o erro tcp_wrap.cc
// console.log('----------> oldNumber: ', oldNumber)
if (number) {
const numberExists = await Contact.findOne({
where: { number }
});
if (numberExists) {
throw new AppError("ERR_DUPLICATED_CONTACT");
}
}
//
await contact.update({
name,
number,
email
});
});
//TEST DEL
await updateTicketsByContactsCache(oldNumber, contact.name, contact.number)
await updateTicketsByContactsCache(oldNumber, contact.name, contact.number)
//
@ -75,7 +93,7 @@ const UpdateContactService = async ({
include: ["extraInfo"]
});
// console.log('contactcontactcontactcontact: ',flatten(JSON.parse(JSON.stringify(contact))))
await updateContactCacheById(contact.id, JSON.parse(JSON.stringify(contact)))

View File

@ -44,7 +44,7 @@ const UpdateUserService = async ({
try {
await schema.validate({ email, password, profile, name });
} catch (err) {
} catch (err: any) {
throw new AppError(err.message);
}