@tomei/sso 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/__tests__/unit/components/login-history/login-history.repository.spec.ts +95 -0
- package/__tests__/unit/components/login-user/login-user.spec.ts +223 -0
- package/__tests__/unit/components/login-user/user.repository.spec.ts +81 -0
- package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +33 -0
- package/__tests__/unit/components/system/system.repository.spec.ts +88 -0
- package/__tests__/unit/components/system-access/system-access.repository.spec.ts +78 -0
- package/__tests__/unit/redis-client/redis.service.spec.ts +24 -0
- package/__tests__/unit/session/session.service.spec.ts +27 -0
- package/create-sso-user.sql +1 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +1 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +208 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.js +15 -0
- package/package.json +21 -3
- package/prisma/migrations/0_init/migration.sql +41 -42
- package/prisma/migrations/20230528161352_create_user_user_group_and_add_new_column/migration.sql +2 -2
- package/prisma/migrations/20230606091407_create_login_histories_table/migration.sql +17 -0
- package/prisma/schema.prisma +46 -33
- package/sampledotenv +8 -0
- package/src/components/index.ts +7 -0
- package/src/components/login-history/index.ts +1 -0
- package/src/components/login-history/login-history.repository.ts +33 -0
- package/src/components/login-user/index.ts +4 -0
- package/src/components/login-user/interfaces/index.ts +1 -0
- package/src/components/login-user/interfaces/user-info.interface.ts +9 -0
- package/src/components/login-user/login-user.ts +427 -0
- package/src/components/login-user/user.repository.ts +33 -0
- package/src/components/password-hash/index.ts +2 -0
- package/src/components/password-hash/interfaces/index.ts +1 -0
- package/src/components/password-hash/interfaces/password-hash-service.interface.ts +4 -0
- package/src/components/password-hash/password-hash.service.ts +14 -0
- package/src/components/system/index.ts +1 -0
- package/src/components/system/system.repository.ts +33 -0
- package/src/components/system-access/index.ts +1 -0
- package/src/components/system-access/system-access.repository.ts +33 -0
- package/src/components/user-group/index.ts +1 -0
- package/src/components/user-group/user-group.repository.ts +33 -0
- package/src/components/user-user-group/index.ts +1 -0
- package/src/components/user-user-group/user-user-group.repository.ts +33 -0
- package/src/index.ts +7 -0
- package/src/interfaces/index.ts +2 -0
- package/src/interfaces/system-login.interface.ts +6 -0
- package/src/interfaces/user-session.interface.ts +5 -0
- package/src/mail/index.ts +2 -0
- package/src/mail/interfaces/index.ts +2 -0
- package/src/mail/interfaces/send-mail.interface.ts +8 -0
- package/src/mail/interfaces/send-new-login-alert.interface.ts +6 -0
- package/src/mail/mail.service.ts +33 -0
- package/src/mail/mail.ts +40 -0
- package/src/prisma-client/__mocks__/prisma.ts +15 -0
- package/src/prisma-client/client.ts +3 -0
- package/src/prisma-client/index.ts +1 -0
- package/src/redis-client/__mocks__/jest-initial-setup.ts +2 -0
- package/src/redis-client/__mocks__/redis-mock.ts +28 -0
- package/src/redis-client/index.ts +1 -0
- package/src/redis-client/redis.service.ts +48 -0
- package/src/session/index.ts +2 -0
- package/src/session/interfaces/index.ts +1 -0
- package/src/session/interfaces/session-service.interface.ts +6 -0
- package/src/session/session.service.ts +45 -0
- package/tsconfig.json +7 -3
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -1
- package/dist/index.js.map +0 -1
@@ -0,0 +1,427 @@
|
|
1
|
+
import { ObjectBase, IPerson, IAddress } from '@tomei/general';
|
2
|
+
import { ISessionService } from '../../session/interfaces/session-service.interface';
|
3
|
+
import { IUserInfo } from './interfaces/user-info.interface';
|
4
|
+
import { IPasswordHashService } from '../password-hash/interfaces/password-hash-service.interface';
|
5
|
+
import { UserRepository } from './user.repository';
|
6
|
+
import { SystemRepository } from '../system/system.repository';
|
7
|
+
import { SystemAccessRepository } from '../system-access/system-access.repository';
|
8
|
+
import { LoginHistoryRepository } from '../login-history/login-history.repository';
|
9
|
+
import { MailService } from '../../mail/mail.service';
|
10
|
+
import { UserUserGroupRepository } from '../user-user-group/user-user-group.repository';
|
11
|
+
import { PasswordHashService } from '../password-hash/password-hash.service';
|
12
|
+
import { SessionService } from '../../session/session.service';
|
13
|
+
import { UserGroupRepository } from '../user-group/user-group.repository';
|
14
|
+
|
15
|
+
export class LoginUser extends ObjectBase implements IPerson {
|
16
|
+
FullName: string;
|
17
|
+
IDNo: string;
|
18
|
+
IDType: string;
|
19
|
+
Email: string;
|
20
|
+
ContactNo: string;
|
21
|
+
Password: string;
|
22
|
+
DefaultAddress: IAddress;
|
23
|
+
ObjectId: string;
|
24
|
+
ObjectName = 'User';
|
25
|
+
TableName = 'sso_users';
|
26
|
+
staffs: any;
|
27
|
+
|
28
|
+
private _OriginIP: string;
|
29
|
+
private _SessionService: ISessionService;
|
30
|
+
private _PasswordHashService = new PasswordHashService();
|
31
|
+
private _MailService = new MailService();
|
32
|
+
private static _Repository = new UserRepository();
|
33
|
+
private static _SystemRepository = new SystemRepository();
|
34
|
+
private static _SystemAccessRepository = new SystemAccessRepository();
|
35
|
+
private static _LoginHistoryRepository = new LoginHistoryRepository();
|
36
|
+
private static _UserUserGroupRepository = new UserUserGroupRepository();
|
37
|
+
private static _UserGroupRepository = new UserGroupRepository();
|
38
|
+
|
39
|
+
getDetails(): {
|
40
|
+
FullName: string;
|
41
|
+
IDNo: string;
|
42
|
+
IDType: string;
|
43
|
+
Email: string;
|
44
|
+
ContactNo: string;
|
45
|
+
} {
|
46
|
+
return {
|
47
|
+
FullName: this.FullName,
|
48
|
+
IDNo: this.IDNo,
|
49
|
+
IDType: this.IDType,
|
50
|
+
Email: this.Email,
|
51
|
+
ContactNo: this.ContactNo,
|
52
|
+
};
|
53
|
+
}
|
54
|
+
|
55
|
+
private constructor(
|
56
|
+
sessionService: ISessionService,
|
57
|
+
dbTransaction?: any,
|
58
|
+
userInfo?: IUserInfo,
|
59
|
+
) {
|
60
|
+
super();
|
61
|
+
this._SessionService = sessionService;
|
62
|
+
// this._PasswordHashService = new PasswordHashService();
|
63
|
+
// this._MailService = new MailService();
|
64
|
+
|
65
|
+
if (dbTransaction) {
|
66
|
+
LoginUser._Repository = new UserRepository(dbTransaction);
|
67
|
+
LoginUser._SystemRepository = new SystemRepository(dbTransaction);
|
68
|
+
LoginUser._SystemAccessRepository = new SystemAccessRepository(
|
69
|
+
dbTransaction,
|
70
|
+
);
|
71
|
+
LoginUser._LoginHistoryRepository = new LoginHistoryRepository(
|
72
|
+
dbTransaction,
|
73
|
+
);
|
74
|
+
LoginUser._UserUserGroupRepository = new UserUserGroupRepository(
|
75
|
+
dbTransaction,
|
76
|
+
);
|
77
|
+
LoginUser._UserGroupRepository = new UserGroupRepository(dbTransaction);
|
78
|
+
}
|
79
|
+
// set all the class properties
|
80
|
+
if (userInfo) {
|
81
|
+
this.ObjectId = userInfo.ObjectId;
|
82
|
+
this.FullName = userInfo.FullName;
|
83
|
+
this.IDNo = userInfo.IDNo;
|
84
|
+
this.Email = userInfo.Email;
|
85
|
+
this.ContactNo = userInfo.ContactNo;
|
86
|
+
this.Password = userInfo.Password;
|
87
|
+
this.staffs = userInfo.staffs;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
static async init(userId?: string, dbTransaction = null): Promise<LoginUser> {
|
92
|
+
const sessionService = await SessionService.init();
|
93
|
+
|
94
|
+
if (userId) {
|
95
|
+
if (dbTransaction) {
|
96
|
+
LoginUser._Repository = new UserRepository(dbTransaction);
|
97
|
+
}
|
98
|
+
const user = await LoginUser._Repository.findOne({
|
99
|
+
where: {
|
100
|
+
id: Number(userId),
|
101
|
+
},
|
102
|
+
include: {
|
103
|
+
staffs: true,
|
104
|
+
userSystemPrivileges: {
|
105
|
+
include: {
|
106
|
+
systemPrivilege: true,
|
107
|
+
},
|
108
|
+
},
|
109
|
+
},
|
110
|
+
});
|
111
|
+
|
112
|
+
if (user) {
|
113
|
+
const userInfo: IUserInfo = {
|
114
|
+
ObjectId: user.id,
|
115
|
+
FullName: user.staffs[0].name,
|
116
|
+
IDNo: user.staffs[0].idNo,
|
117
|
+
ContactNo: user.staffs[0].contactNo,
|
118
|
+
Email: user.staffs[0].email,
|
119
|
+
Password: user.password,
|
120
|
+
staffs: user.staffs[0],
|
121
|
+
};
|
122
|
+
|
123
|
+
return new LoginUser(sessionService, dbTransaction, userInfo);
|
124
|
+
} else {
|
125
|
+
throw new Error('User not found');
|
126
|
+
}
|
127
|
+
}
|
128
|
+
return new LoginUser(sessionService, dbTransaction);
|
129
|
+
}
|
130
|
+
|
131
|
+
async login(
|
132
|
+
systemCode: string,
|
133
|
+
email: string,
|
134
|
+
password: string,
|
135
|
+
ipAddress: string,
|
136
|
+
): Promise<string> {
|
137
|
+
//validate email
|
138
|
+
if (this.Email !== email) {
|
139
|
+
throw new Error('Invalid credentials.');
|
140
|
+
}
|
141
|
+
|
142
|
+
//validate password
|
143
|
+
const isPasswordValid = await this._PasswordHashService.verify(
|
144
|
+
password,
|
145
|
+
this.Password,
|
146
|
+
);
|
147
|
+
|
148
|
+
if (!isPasswordValid) {
|
149
|
+
throw new Error('Invalid credentials.');
|
150
|
+
}
|
151
|
+
|
152
|
+
//validate system code
|
153
|
+
const system = await LoginUser._SystemRepository.findOne({
|
154
|
+
where: {
|
155
|
+
code: systemCode,
|
156
|
+
},
|
157
|
+
});
|
158
|
+
|
159
|
+
if (!system) {
|
160
|
+
throw new Error('Invalid system code.');
|
161
|
+
}
|
162
|
+
|
163
|
+
//validate system access
|
164
|
+
await this.checkSystemAccess(this.ObjectId, system.id);
|
165
|
+
// alert user if new login
|
166
|
+
await this.alertNewLogin(this.ObjectId, system.id, ipAddress);
|
167
|
+
|
168
|
+
// fetch user session if exists
|
169
|
+
const userSession = await this._SessionService.retrieveUserSession(
|
170
|
+
this.ObjectId,
|
171
|
+
);
|
172
|
+
let systemLogin = userSession.systemLogins.find(
|
173
|
+
(system) => system.code === systemCode,
|
174
|
+
);
|
175
|
+
|
176
|
+
// generate new session id
|
177
|
+
const { randomUUID } = require('crypto');
|
178
|
+
const sessionId = randomUUID();
|
179
|
+
|
180
|
+
if (systemLogin) {
|
181
|
+
systemLogin = systemLogin.sessionId = sessionId;
|
182
|
+
userSession.systemLogins.map((system) =>
|
183
|
+
system.code === systemCode ? systemLogin : system,
|
184
|
+
);
|
185
|
+
} else {
|
186
|
+
// if not, add new system login into the userSession
|
187
|
+
const newLogin = {
|
188
|
+
id: system.id.toString(),
|
189
|
+
code: system.code,
|
190
|
+
sessionId: sessionId,
|
191
|
+
privileges: await this.getPrivileges(system.code),
|
192
|
+
};
|
193
|
+
userSession.systemLogins.push(newLogin);
|
194
|
+
}
|
195
|
+
// then update userSession inside the redis storage with 1 day duration of time-to-live
|
196
|
+
this._SessionService.setUserSession(this.ObjectId, userSession);
|
197
|
+
|
198
|
+
// record new login history
|
199
|
+
await LoginUser._LoginHistoryRepository.create({
|
200
|
+
data: {
|
201
|
+
userId: this.ObjectId,
|
202
|
+
systemId: system.id,
|
203
|
+
originIp: ipAddress,
|
204
|
+
createdAt: new Date(),
|
205
|
+
},
|
206
|
+
});
|
207
|
+
|
208
|
+
return sessionId;
|
209
|
+
}
|
210
|
+
|
211
|
+
private async checkSystemAccess(
|
212
|
+
userId: string,
|
213
|
+
systemId: number,
|
214
|
+
): Promise<void> {
|
215
|
+
const systemAccess = await LoginUser._SystemAccessRepository.findOne({
|
216
|
+
where: {
|
217
|
+
userId: userId,
|
218
|
+
systemId: systemId,
|
219
|
+
},
|
220
|
+
});
|
221
|
+
|
222
|
+
if (!systemAccess) {
|
223
|
+
throw new Error("User don't have access to the system.");
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
private async alertNewLogin(
|
228
|
+
userId: string,
|
229
|
+
systemId: string,
|
230
|
+
ipAddress: string,
|
231
|
+
) {
|
232
|
+
const userLogins = await LoginUser._LoginHistoryRepository.findAll({
|
233
|
+
where: {
|
234
|
+
userId: userId,
|
235
|
+
systemId: systemId,
|
236
|
+
},
|
237
|
+
});
|
238
|
+
|
239
|
+
const gotPreviousLogins = userLogins?.length !== 0;
|
240
|
+
let ipFound = null;
|
241
|
+
if (gotPreviousLogins) {
|
242
|
+
ipFound = userLogins.find((item) => item.ipAddress === ipAddress);
|
243
|
+
}
|
244
|
+
|
245
|
+
if (gotPreviousLogins && !ipFound) {
|
246
|
+
await this._MailService.sendNewLoginAlertEmail({
|
247
|
+
IpAddress: ipAddress,
|
248
|
+
Email: this.Email,
|
249
|
+
Name: this.FullName,
|
250
|
+
LoginDate: new Date(),
|
251
|
+
});
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
async getPrivileges(systemCode: string): Promise<string[]> {
|
256
|
+
try {
|
257
|
+
const system = await LoginUser._SystemRepository.findOne({
|
258
|
+
where: {
|
259
|
+
code: systemCode,
|
260
|
+
},
|
261
|
+
});
|
262
|
+
|
263
|
+
if (!system) {
|
264
|
+
throw new Error('Invalid system code.');
|
265
|
+
}
|
266
|
+
// retrive user userGroups with system privileges
|
267
|
+
const userUserGroups = await this.getUserUserGroupFromDB(system.id);
|
268
|
+
|
269
|
+
// get all userGroup data from user userGroups
|
270
|
+
const userGroupData = userUserGroups.map((u) => u.userGroup);
|
271
|
+
|
272
|
+
// get all privileges from userGroup data
|
273
|
+
let privileges: string[] = [];
|
274
|
+
for (const userGroup of userGroupData) {
|
275
|
+
const groupSystemPrivileges = userGroup.groupSystemPrivileges.map(
|
276
|
+
(g) => g.systemPrivilege.code,
|
277
|
+
);
|
278
|
+
const groupRolePrivileges = userGroup.groupRolePrivileges.map(
|
279
|
+
(g) => g.systemPrivilege.code,
|
280
|
+
);
|
281
|
+
|
282
|
+
// if userGroup is not root, get all parent tree privileges
|
283
|
+
if (userGroup.groupLevel !== 0) {
|
284
|
+
// get all parent tree privileges
|
285
|
+
const parentTreePrivileges = await this.getPrivilegesFromUserGroup(
|
286
|
+
userGroup.parentCode,
|
287
|
+
);
|
288
|
+
|
289
|
+
privileges = [...privileges, ...parentTreePrivileges];
|
290
|
+
}
|
291
|
+
|
292
|
+
privileges = [
|
293
|
+
...privileges,
|
294
|
+
...groupSystemPrivileges,
|
295
|
+
...groupRolePrivileges,
|
296
|
+
];
|
297
|
+
}
|
298
|
+
|
299
|
+
// retrive all user personal privileges
|
300
|
+
const userPrivileges = await this.getUserPersonalPrivileges(system.id);
|
301
|
+
|
302
|
+
privileges = [...privileges, ...userPrivileges];
|
303
|
+
privileges = [...new Set(privileges)];
|
304
|
+
return privileges;
|
305
|
+
} catch (error) {
|
306
|
+
throw error;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
private async getPrivilegesFromUserGroup(
|
311
|
+
groupCode: string,
|
312
|
+
): Promise<string[]> {
|
313
|
+
try {
|
314
|
+
// Retrieve userGroup from the database based on groupCode
|
315
|
+
const userGroup = await this.getUserGroupFromDB(groupCode);
|
316
|
+
let privileges: string[] = [];
|
317
|
+
|
318
|
+
// Add privileges from the userGroup to the privileges array
|
319
|
+
privileges = [
|
320
|
+
...privileges,
|
321
|
+
...userGroup.groupSystemPrivileges.map((g) => g.systemPrivilege.code),
|
322
|
+
...userGroup.groupRolePrivileges.map((g) => g.systemPrivilege.code),
|
323
|
+
];
|
324
|
+
|
325
|
+
// Recursive call if conditions are not met and ParentGroupCode exists
|
326
|
+
const isContinue =
|
327
|
+
userGroup.groupLevel !== 0 &&
|
328
|
+
userGroup.allowInheritFromParentYN === 'Y';
|
329
|
+
if (isContinue) {
|
330
|
+
const recursivePrivileges = await this.getPrivilegesFromUserGroup(
|
331
|
+
userGroup.parentGroupCode,
|
332
|
+
);
|
333
|
+
privileges = privileges.concat(recursivePrivileges);
|
334
|
+
}
|
335
|
+
|
336
|
+
// return privileges array
|
337
|
+
return privileges;
|
338
|
+
} catch (error) {
|
339
|
+
throw error;
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
private async getUserGroupFromDB(groupCode: string): Promise<any> {
|
344
|
+
try {
|
345
|
+
const userGroup = await LoginUser._UserGroupRepository.findOne({
|
346
|
+
where: {
|
347
|
+
groupCode: groupCode,
|
348
|
+
},
|
349
|
+
include: {
|
350
|
+
groupSystemPrivileges: {
|
351
|
+
include: {
|
352
|
+
systemPrivilege: true,
|
353
|
+
},
|
354
|
+
},
|
355
|
+
groupRolePrivileges: {
|
356
|
+
include: {
|
357
|
+
systemPrivilege: true,
|
358
|
+
},
|
359
|
+
},
|
360
|
+
},
|
361
|
+
});
|
362
|
+
return userGroup;
|
363
|
+
} catch (error) {
|
364
|
+
throw error;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
private async getUserUserGroupFromDB(systemCode: number) {
|
369
|
+
try {
|
370
|
+
return await LoginUser._UserUserGroupRepository.findAll({
|
371
|
+
where: {
|
372
|
+
userId: this.ObjectId,
|
373
|
+
systemId: systemCode,
|
374
|
+
},
|
375
|
+
include: {
|
376
|
+
userGroup: {
|
377
|
+
include: {
|
378
|
+
groupSystemPrivileges: {
|
379
|
+
include: {
|
380
|
+
systemPrivilege: true,
|
381
|
+
},
|
382
|
+
},
|
383
|
+
groupRolePrivileges: {
|
384
|
+
include: {
|
385
|
+
systemPrivilege: true,
|
386
|
+
},
|
387
|
+
},
|
388
|
+
},
|
389
|
+
},
|
390
|
+
},
|
391
|
+
});
|
392
|
+
} catch (error) {
|
393
|
+
throw error;
|
394
|
+
}
|
395
|
+
}
|
396
|
+
|
397
|
+
private async getUserPersonalPrivileges(systemId: number): Promise<string[]> {
|
398
|
+
try {
|
399
|
+
const userRole = await LoginUser._Repository.findOne({
|
400
|
+
where: {
|
401
|
+
id: this.ObjectId,
|
402
|
+
},
|
403
|
+
include: {
|
404
|
+
userSystemPrivileges: {
|
405
|
+
include: {
|
406
|
+
systemPrivilege: true,
|
407
|
+
},
|
408
|
+
},
|
409
|
+
},
|
410
|
+
});
|
411
|
+
|
412
|
+
//retrive all user systemPrevileges data from user roles
|
413
|
+
let userSystemPrivileges = userRole.userSystemPrivileges.map(
|
414
|
+
(u) => u.systemPrivilege,
|
415
|
+
);
|
416
|
+
|
417
|
+
userSystemPrivileges = userRole.userSystemPrivileges.filter(
|
418
|
+
(u) => u.systemPrivilege.systemId === systemId,
|
419
|
+
);
|
420
|
+
|
421
|
+
const userPrivileges: string[] = userSystemPrivileges.map((u) => u.code);
|
422
|
+
return userPrivileges;
|
423
|
+
} catch (error) {
|
424
|
+
throw error;
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import prisma from '../../prisma-client/client';
|
2
|
+
|
3
|
+
export class UserRepository {
|
4
|
+
private _prisma: any;
|
5
|
+
|
6
|
+
constructor(client?: any) {
|
7
|
+
if (client) {
|
8
|
+
this._prisma = client;
|
9
|
+
} else {
|
10
|
+
this._prisma = prisma;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
public async create(data: any): Promise<any> {
|
15
|
+
return await this._prisma.user.create(data);
|
16
|
+
}
|
17
|
+
|
18
|
+
public async findAll(options: any): Promise<any[]> {
|
19
|
+
return await this._prisma.user.findMany(options);
|
20
|
+
}
|
21
|
+
|
22
|
+
public async findOne(options: any): Promise<any> {
|
23
|
+
return await this._prisma.user.findFirst(options);
|
24
|
+
}
|
25
|
+
|
26
|
+
public async update(where: any, data: any): Promise<any> {
|
27
|
+
return await this._prisma.user.update(where, data);
|
28
|
+
}
|
29
|
+
|
30
|
+
public async delete(where: any): Promise<any> {
|
31
|
+
return await this._prisma.user.delete(where);
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './password-hash-service.interface';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import * as argon2 from 'argon2';
|
2
|
+
import { IPasswordHashService } from './interfaces/password-hash-service.interface';
|
3
|
+
|
4
|
+
export class PasswordHashService implements IPasswordHashService {
|
5
|
+
constructor() {}
|
6
|
+
|
7
|
+
async hashPassword(password: string): Promise<string> {
|
8
|
+
return await argon2.hash(password);
|
9
|
+
}
|
10
|
+
|
11
|
+
async verify(password: string, hash: string): Promise<boolean> {
|
12
|
+
return await argon2.verify(hash, password);
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './system.repository';
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import prisma from '../../prisma-client/client';
|
2
|
+
|
3
|
+
export class SystemRepository {
|
4
|
+
private _prisma: any;
|
5
|
+
|
6
|
+
constructor(client?: any) {
|
7
|
+
if (client) {
|
8
|
+
this._prisma = client;
|
9
|
+
} else {
|
10
|
+
this._prisma = prisma;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
public async create(data: any): Promise<any> {
|
15
|
+
return await this._prisma.system.create(data);
|
16
|
+
}
|
17
|
+
|
18
|
+
public async findAll(options: any): Promise<any[]> {
|
19
|
+
return await this._prisma.system.findMany(options);
|
20
|
+
}
|
21
|
+
|
22
|
+
public async findOne(options: any): Promise<any> {
|
23
|
+
return await this._prisma.system.findFirst(options);
|
24
|
+
}
|
25
|
+
|
26
|
+
public async update(where: any, data: any): Promise<any> {
|
27
|
+
return await this._prisma.system.update(where, data);
|
28
|
+
}
|
29
|
+
|
30
|
+
public async delete(where: any): Promise<any> {
|
31
|
+
return await this._prisma.system.delete(where);
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './system-access.repository';
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import prisma from '../../prisma-client/client';
|
2
|
+
|
3
|
+
export class SystemAccessRepository {
|
4
|
+
private _prisma: any;
|
5
|
+
|
6
|
+
constructor(client?: any) {
|
7
|
+
if (client) {
|
8
|
+
this._prisma = client;
|
9
|
+
} else {
|
10
|
+
this._prisma = prisma;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
public async create(data: any): Promise<any> {
|
15
|
+
return await this._prisma.systemAccess.create(data);
|
16
|
+
}
|
17
|
+
|
18
|
+
public async findAll(options: any): Promise<any[]> {
|
19
|
+
return await this._prisma.systemAccess.findMany(options);
|
20
|
+
}
|
21
|
+
|
22
|
+
public async findOne(options: any): Promise<any> {
|
23
|
+
return await this._prisma.systemAccess.findFirst(options);
|
24
|
+
}
|
25
|
+
|
26
|
+
public async update(where: any, data: any): Promise<any> {
|
27
|
+
return await this._prisma.systemAccess.update(where, data);
|
28
|
+
}
|
29
|
+
|
30
|
+
public async delete(where: any): Promise<any> {
|
31
|
+
return await this._prisma.systemAccess.delete(where);
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './user-group.repository';
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import prisma from '../../prisma-client/client';
|
2
|
+
|
3
|
+
export class UserGroupRepository {
|
4
|
+
private _prisma: any;
|
5
|
+
|
6
|
+
constructor(client?: any) {
|
7
|
+
if (client) {
|
8
|
+
this._prisma = client;
|
9
|
+
} else {
|
10
|
+
this._prisma = prisma;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
public async create(data: any): Promise<any> {
|
15
|
+
return await this._prisma.userGroup.create(data);
|
16
|
+
}
|
17
|
+
|
18
|
+
public async findAll(options: any): Promise<any[]> {
|
19
|
+
return await this._prisma.userGroup.findMany(options);
|
20
|
+
}
|
21
|
+
|
22
|
+
public async findOne(options: any): Promise<any> {
|
23
|
+
return await this._prisma.userGroup.findFirst(options);
|
24
|
+
}
|
25
|
+
|
26
|
+
public async update(where: any, data: any): Promise<any> {
|
27
|
+
return await this._prisma.userGroup.update(where, data);
|
28
|
+
}
|
29
|
+
|
30
|
+
public async delete(where: any): Promise<any> {
|
31
|
+
return await this._prisma.userGroups.delete(where);
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './user-user-group.repository';
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import prisma from '../../prisma-client/client';
|
2
|
+
|
3
|
+
export class UserUserGroupRepository {
|
4
|
+
private _prisma: any;
|
5
|
+
|
6
|
+
constructor(client?: any) {
|
7
|
+
if (client) {
|
8
|
+
this._prisma = client;
|
9
|
+
} else {
|
10
|
+
this._prisma = prisma;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
public async create(data: any): Promise<any> {
|
15
|
+
return await this._prisma.userUserGroup.create(data);
|
16
|
+
}
|
17
|
+
|
18
|
+
public async findAll(options: any): Promise<any[]> {
|
19
|
+
return await this._prisma.userUserGroup.findMany(options);
|
20
|
+
}
|
21
|
+
|
22
|
+
public async findOne(options: any): Promise<any> {
|
23
|
+
return await this._prisma.userUserGroup.findFirst(options);
|
24
|
+
}
|
25
|
+
|
26
|
+
public async update(where: any, data: any): Promise<any> {
|
27
|
+
return await this._prisma.userUserGroup.update(where, data);
|
28
|
+
}
|
29
|
+
|
30
|
+
public async delete(where: any): Promise<any> {
|
31
|
+
return await this._prisma.userUserGroup.delete(where);
|
32
|
+
}
|
33
|
+
}
|
package/src/index.ts
CHANGED