2026-01-30 19:04:14 +00:00

49 lines
1.2 KiB
JavaScript

const db = require('../db/models');
class SellerService {
static async apply(userId, { shopName, shopDescription }) {
const user = await db.users.findByPk(userId);
if (!user) throw new Error('User not found');
await user.update({
shopName,
shopDescription,
sellerStatus: 'pending'
});
return { success: true, message: 'Application submitted successfully' };
}
static async getStatus(userId) {
const user = await db.users.findByPk(userId);
return { status: user.sellerStatus, shopName: user.shopName };
}
static async getPendingApplications() {
return await db.users.findAll({
where: { sellerStatus: 'pending' }
});
}
static async reviewApplication(userId, status) {
const user = await db.users.findByPk(userId);
if (!user) throw new Error('User not found');
const updateData = { sellerStatus: status };
if (status === 'approved') {
// Find Seller role
const sellerRole = await db.roles.findOne({ where: { name: 'Seller' } });
if (sellerRole) {
updateData.app_roleId = sellerRole.id;
}
}
await user.update(updateData);
return { success: true, status };
}
}
module.exports = SellerService;