Files
Zumri-Backend/app/utils/users/userProfileDetails.util.js
2026-08-21 11:44:00 +05:30

56 lines
826 B
JavaScript

// 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,
};