refactor: Update deactivateAccount to accept user ID directly instead of a JWT token.
This commit is contained in:
parent
8960e90dbd
commit
bca2cc944e
1 changed files with 2 additions and 6 deletions
|
|
@ -104,15 +104,11 @@ export class UserManagementService {
|
|||
}
|
||||
}
|
||||
|
||||
async deactivateAccount(token: string): Promise<DeactivateAccountResponse> {
|
||||
async deactivateAccount(id: number): Promise<DeactivateAccountResponse> {
|
||||
try {
|
||||
// Decode JWT token to get user ID
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decoded.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id } });
|
||||
if (!user) throw new UnauthorizedError('User not found');
|
||||
|
||||
// Check if account is already deactivated
|
||||
if (user.is_deactivated) {
|
||||
logger.warn('Deactivate attempt with deactivated account', { userId: user.id });
|
||||
throw new ForbiddenError('This account has already been deactivated');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue