feat: implement profile data validation and upsert functionality for company and personal profiles
This commit is contained in:
parent
2296b521db
commit
5cef174e7f
@ -148,25 +148,38 @@ class CompanyUserRepository {
|
||||
registrationNumber,
|
||||
businessType,
|
||||
iban,
|
||||
accountHolderName
|
||||
accountHolderName,
|
||||
companyName
|
||||
} = profileData;
|
||||
|
||||
await conn.query(
|
||||
`UPDATE company_profiles SET
|
||||
address = ?, zip_code = ?, city = ?, country = ?, branch = ?, number_of_employees = ?,
|
||||
registration_number = ?, business_type = ?, account_holder_name = ?
|
||||
WHERE user_id = ?`,
|
||||
`INSERT INTO company_profiles (
|
||||
user_id, company_name, registration_number, address, zip_code, city, country,
|
||||
branch, number_of_employees, business_type, account_holder_name
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
company_name = VALUES(company_name),
|
||||
registration_number = VALUES(registration_number),
|
||||
address = VALUES(address),
|
||||
zip_code = VALUES(zip_code),
|
||||
city = VALUES(city),
|
||||
country = VALUES(country),
|
||||
branch = VALUES(branch),
|
||||
number_of_employees = VALUES(number_of_employees),
|
||||
business_type = VALUES(business_type),
|
||||
account_holder_name = VALUES(account_holder_name)`,
|
||||
[
|
||||
address,
|
||||
zip_code,
|
||||
city,
|
||||
country, // Add country to parameter list
|
||||
branch,
|
||||
numberOfEmployees,
|
||||
registrationNumber,
|
||||
businessType,
|
||||
accountHolderName,
|
||||
userId
|
||||
userId,
|
||||
companyName,
|
||||
registrationNumber || null,
|
||||
address || null,
|
||||
zip_code || null,
|
||||
city || null,
|
||||
country || null,
|
||||
branch || null,
|
||||
numberOfEmployees || null,
|
||||
businessType || null,
|
||||
accountHolderName || null
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@ -108,13 +108,35 @@ class PersonalUserRepository {
|
||||
iban // Added field
|
||||
} = profileData;
|
||||
|
||||
const firstName =
|
||||
profileData.firstName ||
|
||||
profileData.first_name ||
|
||||
'';
|
||||
const lastName =
|
||||
profileData.lastName ||
|
||||
profileData.last_name ||
|
||||
'';
|
||||
|
||||
await conn.query(
|
||||
`UPDATE personal_profiles SET
|
||||
date_of_birth = ?, nationality = ?, address = ?, zip_code = ?, city = ?, country = ?,
|
||||
phone_secondary = ?, emergency_contact_name = ?, emergency_contact_phone = ?,
|
||||
account_holder_name = ?
|
||||
WHERE user_id = ?`,
|
||||
`INSERT INTO personal_profiles (
|
||||
user_id, first_name, last_name, date_of_birth, nationality, address, zip_code, city, country,
|
||||
phone_secondary, emergency_contact_name, emergency_contact_phone, account_holder_name
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
date_of_birth = VALUES(date_of_birth),
|
||||
nationality = VALUES(nationality),
|
||||
address = VALUES(address),
|
||||
zip_code = VALUES(zip_code),
|
||||
city = VALUES(city),
|
||||
country = VALUES(country),
|
||||
phone_secondary = VALUES(phone_secondary),
|
||||
emergency_contact_name = VALUES(emergency_contact_name),
|
||||
emergency_contact_phone = VALUES(emergency_contact_phone),
|
||||
account_holder_name = VALUES(account_holder_name)`,
|
||||
[
|
||||
userId,
|
||||
firstName,
|
||||
lastName,
|
||||
dateOfBirth,
|
||||
nationality,
|
||||
address,
|
||||
@ -124,8 +146,7 @@ class PersonalUserRepository {
|
||||
phoneSecondary,
|
||||
emergencyContactName,
|
||||
emergencyContactPhone,
|
||||
accountHolderName,
|
||||
userId
|
||||
accountHolderName
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@ -5,6 +5,28 @@ class CompanyProfileService {
|
||||
static async completeProfile(userId, profileData, unitOfWork) {
|
||||
logger.info('CompanyProfileService.completeProfile:start', { userId });
|
||||
try {
|
||||
const conn = unitOfWork.connection;
|
||||
|
||||
const required = [
|
||||
{ key: 'companyName', label: 'Company name' },
|
||||
{ key: 'address', label: 'Street & number' },
|
||||
{ key: 'zip_code', label: 'Postal code' },
|
||||
{ key: 'city', label: 'City' },
|
||||
{ key: 'country', label: 'Country' },
|
||||
{ key: 'registrationNumber', label: 'VAT' },
|
||||
{ key: 'accountHolderName', label: 'Account holder' },
|
||||
{ key: 'iban', label: 'IBAN' }
|
||||
];
|
||||
|
||||
for (const field of required) {
|
||||
const value = (profileData[field.key] || '').toString().trim();
|
||||
if (!value) {
|
||||
throw new Error(`${field.label} is required.`);
|
||||
}
|
||||
}
|
||||
|
||||
profileData.companyName = (profileData.companyName || '').toString().trim();
|
||||
|
||||
// Pass all profileData including country to repository
|
||||
const repo = new CompanyUserRepository(unitOfWork);
|
||||
await repo.updateProfileAndMarkCompleted(userId, profileData);
|
||||
|
||||
@ -5,6 +5,33 @@ class PersonalProfileService {
|
||||
static async completeProfile(userId, profileData, unitOfWork) {
|
||||
logger.info('PersonalProfileService.completeProfile:start', { userId });
|
||||
try {
|
||||
const required = [
|
||||
{ key: 'dateOfBirth', label: 'Date of birth' },
|
||||
{ key: 'nationality', label: 'Nationality' },
|
||||
{ key: 'address', label: 'Street & house number' },
|
||||
{ key: 'zip_code', label: 'Postal code' },
|
||||
{ key: 'city', label: 'City' },
|
||||
{ key: 'country', label: 'Country' },
|
||||
{ key: 'accountHolderName', label: 'Account holder' },
|
||||
{ key: 'iban', label: 'IBAN' }
|
||||
];
|
||||
|
||||
for (const field of required) {
|
||||
const value = (profileData[field.key] || '').toString().trim();
|
||||
if (!value) {
|
||||
throw new Error(`${field.label} is required.`);
|
||||
}
|
||||
}
|
||||
|
||||
profileData.dateOfBirth = profileData.dateOfBirth.toString().trim();
|
||||
profileData.nationality = profileData.nationality.toString().trim();
|
||||
profileData.address = profileData.address.toString().trim();
|
||||
profileData.zip_code = profileData.zip_code.toString().trim();
|
||||
profileData.city = profileData.city.toString().trim();
|
||||
profileData.country = profileData.country.toString().trim();
|
||||
profileData.accountHolderName = profileData.accountHolderName.toString().trim();
|
||||
profileData.iban = profileData.iban.toString().trim();
|
||||
|
||||
const repo = new PersonalUserRepository(unitOfWork);
|
||||
await repo.updateProfileAndMarkCompleted(userId, profileData);
|
||||
logger.info('PersonalProfileService.completeProfile:profile_completed', { userId });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user