edit contact form
This commit is contained in:
@@ -58,7 +58,29 @@ router.put(
|
||||
authorize('contacts', 'contacts', 'update'),
|
||||
[
|
||||
param('id').isUUID(),
|
||||
body('email').optional().isEmail(),
|
||||
body('type')
|
||||
.optional()
|
||||
.isIn([
|
||||
'INDIVIDUAL',
|
||||
'COMPANY',
|
||||
'HOLDING',
|
||||
'GOVERNMENT',
|
||||
'ORGANIZATION',
|
||||
'EMBASSIES',
|
||||
'BANK',
|
||||
'UNIVERSITY',
|
||||
'SCHOOL',
|
||||
'UN',
|
||||
'NGO',
|
||||
'INSTITUTION',
|
||||
]),
|
||||
body('email')
|
||||
.optional({ values: 'falsy' })
|
||||
.custom((value) => {
|
||||
if (value === null || value === undefined || value === '') return true
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
|
||||
})
|
||||
.withMessage('Invalid email format'),
|
||||
validate,
|
||||
],
|
||||
contactsController.update
|
||||
|
||||
@@ -328,46 +328,50 @@ class ContactsService {
|
||||
|
||||
// Update contact
|
||||
const contact = await prisma.contact.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name: data.name,
|
||||
nameAr: data.nameAr,
|
||||
email: data.email,
|
||||
phone: data.phone,
|
||||
mobile: data.mobile,
|
||||
website: data.website,
|
||||
companyName: data.companyName,
|
||||
companyNameAr: data.companyNameAr,
|
||||
taxNumber: data.taxNumber,
|
||||
commercialRegister: data.commercialRegister,
|
||||
address: data.address,
|
||||
city: data.city,
|
||||
country: data.country,
|
||||
postalCode: data.postalCode,
|
||||
categories: data.categories ? {
|
||||
set: data.categories.map(id => ({ id }))
|
||||
} : undefined,
|
||||
tags: data.tags,
|
||||
employeeId: data.employeeId !== undefined ? (data.employeeId || null) : undefined,
|
||||
source: data.source,
|
||||
status: data.status,
|
||||
rating: data.rating,
|
||||
customFields: data.customFields,
|
||||
where: { id },
|
||||
data: {
|
||||
type: data.type,
|
||||
name: data.name,
|
||||
nameAr: data.nameAr,
|
||||
email: data.email === '' || data.email === undefined ? null : data.email,
|
||||
phone: data.phone,
|
||||
mobile: data.mobile,
|
||||
website: data.website,
|
||||
companyName: data.companyName,
|
||||
companyNameAr: data.companyNameAr,
|
||||
taxNumber: data.taxNumber,
|
||||
commercialRegister: data.commercialRegister,
|
||||
address: data.address,
|
||||
city: data.city,
|
||||
country: data.country,
|
||||
postalCode: data.postalCode,
|
||||
categories: data.categories
|
||||
? {
|
||||
set: data.categories.map((id) => ({ id })),
|
||||
}
|
||||
: undefined,
|
||||
tags: data.tags,
|
||||
employeeId:
|
||||
data.employeeId !== undefined ? (data.employeeId || null) : undefined,
|
||||
source: data.source,
|
||||
status: data.status,
|
||||
rating: data.rating,
|
||||
customFields: data.customFields,
|
||||
},
|
||||
include: {
|
||||
categories: true,
|
||||
parent: true,
|
||||
employee: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true,
|
||||
uniqueEmployeeId: true,
|
||||
},
|
||||
include: {
|
||||
categories: true,
|
||||
parent: true,
|
||||
employee: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true,
|
||||
uniqueEmployeeId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Log audit
|
||||
await AuditLogger.log({
|
||||
|
||||
Reference in New Issue
Block a user