Add user profile retrieval function

This commit is contained in:
Isuru Bimsara
2026-08-21 11:44:00 +05:30
parent 6a4fe852e5
commit 2a35d86ebf
4 changed files with 156 additions and 109 deletions
@@ -0,0 +1,56 @@
// app/services/userProfile.service.js
const db = require("../../models");
const User = db.User;
const Customer = db.Customer;
const BusinessCustomer = db.BusinessCustomer;
const getUserProfile = async (userId) => {
const user = await User.findByPk(userId, {
attributes: {
exclude: ["password"],
},
});
if (!user) {
return null;
}
let accountDetails = null;
if (user.accountType === "customer") {
accountDetails = await Customer.findOne({
where: {
user_id: user.id,
},
});
}
else if (user.accountType === "business_customer") {
accountDetails =
await BusinessCustomer.findOne({
where: {
user_id: user.id,
},
});
}
return {
user,
accountDetails,
};
};
module.exports = {
getUserProfile,
};