feat: Filter user listings by deactivation status, include a total count in the response, and simplify account activation to use user ID directly.
This commit is contained in:
parent
000de75dd1
commit
8960e90dbd
2 changed files with 9 additions and 6 deletions
|
|
@ -18,15 +18,20 @@ export class UserManagementService {
|
|||
async listUsers(): Promise<ListUsersResponse> {
|
||||
try {
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
is_deactivated: false
|
||||
},
|
||||
include: {
|
||||
profile: true,
|
||||
role: true
|
||||
role: true,
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Users fetched successfully',
|
||||
total: users.length,
|
||||
data: users.map(user => this.formatUserResponse(user))
|
||||
};
|
||||
} catch (error) {
|
||||
|
|
@ -138,12 +143,9 @@ export class UserManagementService {
|
|||
}
|
||||
}
|
||||
|
||||
async activateAccount(token: string): Promise<ActivateAccountResponse> {
|
||||
async activateAccount(id: number): Promise<ActivateAccountResponse> {
|
||||
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 activated
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { ProfileUpdate, UserResponse } from "./user.types";
|
|||
export interface ListUsersResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
total: number;
|
||||
data: UserResponse[] | null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue