add create user and login user parts
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
//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,
|
||||
};
|
||||
Reference in New Issue
Block a user