86 lines
1.3 KiB
JavaScript
86 lines
1.3 KiB
JavaScript
// app/utils/users/createBusinessCustomer.util.js
|
|
|
|
const db = require("../../models");
|
|
|
|
const {
|
|
generateBusinessCustomerId,
|
|
} = require("../idGen.util");
|
|
|
|
const BusinessCustomer = db.BusinessCustomer;
|
|
|
|
|
|
/**
|
|
* Create business-customer-specific details
|
|
*/
|
|
const createBusinessCustomerDetails = async (
|
|
userId,
|
|
businessData,
|
|
transaction
|
|
) => {
|
|
|
|
const {
|
|
businessName,
|
|
businessRegistrationNumber,
|
|
businessType,
|
|
contactName,
|
|
phoneNumber,
|
|
businessEmail,
|
|
expectedMonthlyVolume,
|
|
note,
|
|
} = businessData;
|
|
|
|
|
|
if (
|
|
!businessName ||
|
|
!businessRegistrationNumber ||
|
|
!businessType ||
|
|
!contactName ||
|
|
!phoneNumber ||
|
|
!businessEmail ||
|
|
!expectedMonthlyVolume
|
|
) {
|
|
throw new Error(
|
|
"Required business customer details are missing"
|
|
);
|
|
}
|
|
|
|
|
|
const businessCustomer =
|
|
await BusinessCustomer.create(
|
|
{
|
|
business_customer_id:
|
|
generateBusinessCustomerId(),
|
|
|
|
user_id:
|
|
userId,
|
|
|
|
businessName,
|
|
|
|
businessRegistrationNumber,
|
|
|
|
businessType,
|
|
|
|
contactName,
|
|
|
|
phoneNumber,
|
|
|
|
businessEmail,
|
|
|
|
expectedMonthlyVolume,
|
|
|
|
note:
|
|
note || null,
|
|
},
|
|
{
|
|
transaction,
|
|
}
|
|
);
|
|
|
|
|
|
return businessCustomer;
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
createBusinessCustomerDetails,
|
|
}; |