-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanagementService.ts
43 lines (38 loc) · 1.34 KB
/
managementService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { AuditAction, AuditTrailEvents } from '../entities/AuditTrail';
import { User } from '../entities/User';
import { getTraceId } from '../helpers/loggingHelpers';
import {
constructAuditTrailObject,
performAsyncOperationWithAuditTrail,
} from './auditTrailService';
import { UserParticipantRequest } from './participantsService';
import { findUserByEmail } from './usersService';
export const getAllUsersList = async () => {
const userList = await User.query().where('deleted', 0).orderBy('email');
return userList;
};
export const getUserById = async (userId: number) => {
const user = await User.query().where('id', userId).first();
return user;
};
export const updateUserLock = async (
req: UserParticipantRequest,
userId: number,
isLocked: boolean
) => {
const requestingUser = await findUserByEmail(req.auth?.payload.email as string);
const updatedUser = await User.query().where('id', userId).first();
const traceId = getTraceId(req);
const auditTrailInsertObject = constructAuditTrailObject(
requestingUser!,
AuditTrailEvents.ChangeUserLock,
{
action: AuditAction.Update,
email: updatedUser?.email,
locked: isLocked,
}
);
await performAsyncOperationWithAuditTrail(auditTrailInsertObject, traceId, async () => {
await User.query().where('id', userId).update({ locked: isLocked });
});
};