add create user and login user parts

This commit is contained in:
Isuru Bimsara
2026-08-21 02:20:57 +05:30
parent 621d348eb1
commit b2c5e198a1
15 changed files with 842 additions and 336 deletions
@@ -0,0 +1,86 @@
// 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,
};
@@ -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,
};