Commit de correção de validação.
parent
3c3a8107ac
commit
6d9bef094f
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ const CreateContactService = async ({
|
|||
profilePicUrl='',
|
||||
extraInfo = []
|
||||
}: Request): Promise<Contact> => {
|
||||
|
||||
const numberExists = await Contact.findOne({
|
||||
where: { number }
|
||||
});
|
||||
|
|
|
@ -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"],
|
||||
|
@ -59,6 +61,22 @@ const UpdateContactService = async ({
|
|||
|
||||
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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue