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('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 name = newContact.name
let number = validNumber let number = validNumber
let email = newContact.email let email = newContact.email

View File

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

View File

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

View File

@ -29,6 +29,8 @@ const UpdateContactService = async ({
}: Request): Promise<Contact> => { }: Request): Promise<Contact> => {
const { email, name, number, extraInfo } = contactData; const { email, name, number, extraInfo } = contactData;
// console.log('email, name, number, extraInfo: ', email, name, number, extraInfo)
const contact = await Contact.findOne({ const contact = await Contact.findOne({
where: { id: contactId }, where: { id: contactId },
attributes: ["id", "name", "number", "email", "profilePicUrl"], attributes: ["id", "name", "number", "email", "profilePicUrl"],
@ -59,6 +61,22 @@ 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({ await contact.update({
name, name,
number, number,

View File

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