55 lines
769 B
JavaScript
55 lines
769 B
JavaScript
//app/utils/users/createCustomerDetails.util.js
|
|
|
|
const db = require("../../models");
|
|
|
|
const { generateCustomerId } = require("../idGen.util");
|
|
|
|
const Customer = db.Customer;
|
|
|
|
const createCustomerDetails = async (
|
|
userId,
|
|
customerData,
|
|
transaction
|
|
) => {
|
|
|
|
const {
|
|
address,
|
|
phoneNumber,
|
|
} = customerData;
|
|
|
|
|
|
if (!address || !phoneNumber) {
|
|
throw new Error(
|
|
"Address and phone number are required for customer"
|
|
);
|
|
}
|
|
|
|
|
|
const customer = await Customer.create(
|
|
{
|
|
customer_id:
|
|
generateCustomerId(),
|
|
|
|
user_id:
|
|
userId,
|
|
|
|
address:
|
|
address,
|
|
|
|
phoneNumber:
|
|
phoneNumber,
|
|
},
|
|
{
|
|
transaction,
|
|
}
|
|
);
|
|
|
|
|
|
return customer;
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
createCustomerDetails,
|
|
};
|