@tomei/sso 0.60.4-dev.1 → 0.60.4-dev.2

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.
Files changed (25) hide show
  1. package/dist/src/components/login-history/index.d.ts +1 -0
  2. package/dist/src/components/login-history/index.js +1 -0
  3. package/dist/src/components/login-history/index.js.map +1 -1
  4. package/dist/src/components/login-history/login-history.d.ts +22 -0
  5. package/dist/src/components/login-history/login-history.js +75 -0
  6. package/dist/src/components/login-history/login-history.js.map +1 -0
  7. package/dist/src/components/login-history/login-history.repository.d.ts +2 -2
  8. package/dist/src/components/login-history/login-history.repository.js.map +1 -1
  9. package/dist/src/interfaces/login-history-search-attr.interface.d.ts +8 -0
  10. package/dist/src/interfaces/login-history-search-attr.interface.js +3 -0
  11. package/dist/src/interfaces/login-history-search-attr.interface.js.map +1 -0
  12. package/dist/src/interfaces/login-history.interface.d.ts +8 -0
  13. package/dist/src/interfaces/login-history.interface.js +3 -0
  14. package/dist/src/interfaces/login-history.interface.js.map +1 -0
  15. package/dist/src/models/login-history.entity.d.ts +2 -2
  16. package/dist/src/models/login-history.entity.js +13 -13
  17. package/dist/src/models/login-history.entity.js.map +1 -1
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/package.json +1 -1
  20. package/src/components/login-history/index.ts +1 -0
  21. package/src/components/login-history/login-history.repository.ts +4 -4
  22. package/src/components/login-history/login-history.ts +109 -0
  23. package/src/interfaces/login-history-search-attr.interface.ts +8 -0
  24. package/src/interfaces/login-history.interface.ts +8 -0
  25. package/src/models/login-history.entity.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.60.4-dev.1",
3
+ "version": "0.60.4-dev.2",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1 +1,2 @@
1
1
  export * from './login-history.repository';
2
+ export * from './login-history';
@@ -1,11 +1,11 @@
1
- import LoginHistory from '../../models/login-history.entity';
1
+ import LoginHistoryModel from '../../models/login-history.entity';
2
2
  import { RepositoryBase, IRepositoryBase } from '@tomei/general';
3
3
 
4
4
  export class LoginHistoryRepository
5
- extends RepositoryBase<LoginHistory>
6
- implements IRepositoryBase<LoginHistory>
5
+ extends RepositoryBase<LoginHistoryModel>
6
+ implements IRepositoryBase<LoginHistoryModel>
7
7
  {
8
8
  constructor() {
9
- super(LoginHistory);
9
+ super(LoginHistoryModel);
10
10
  }
11
11
  }
@@ -0,0 +1,109 @@
1
+ import { ClassError, ObjectBase } from '@tomei/general';
2
+ import { LoginHistoryRepository } from './login-history.repository';
3
+ import { ILoginHistoryAttr } from '../../interfaces/login-history.interface';
4
+ import { LoginUser } from '../login-user/login-user';
5
+ import { ApplicationConfig } from '@tomei/config';
6
+ import { ILoginHistorySearchAttr } from '../../interfaces/login-history-search-attr.interface';
7
+ import { Op } from 'sequelize';
8
+
9
+ export class LoginHistory extends ObjectBase {
10
+ ObjectId: string;
11
+ ObjectName: string;
12
+ TableName = 'sso_LoginHistory';
13
+ ObjectType = 'Login History';
14
+
15
+ HistoryId: number;
16
+ UserId: number;
17
+ OriginIP: string;
18
+ SystemCode: string;
19
+ LoginStatus: string;
20
+ private _CreatedAt: Date;
21
+ private static _Repo = new LoginHistoryRepository();
22
+
23
+ get CreatedAt(): Date {
24
+ return this._CreatedAt;
25
+ }
26
+
27
+ private constructor(loginHistoryAttr?: ILoginHistoryAttr) {
28
+ super();
29
+ if (loginHistoryAttr) {
30
+ this.HistoryId = loginHistoryAttr.HistoryId;
31
+ this.UserId = loginHistoryAttr.UserId;
32
+ this.OriginIP = loginHistoryAttr?.OriginIp;
33
+ this.SystemCode = loginHistoryAttr?.SystemCode;
34
+ this.LoginStatus = loginHistoryAttr?.LoginStatus;
35
+ this._CreatedAt = loginHistoryAttr.CreatedAt;
36
+ }
37
+ }
38
+
39
+ public static async findAll(
40
+ dbTransaction: any,
41
+ loginUser: LoginUser,
42
+ page?: number,
43
+ rows?: number,
44
+ search?: ILoginHistorySearchAttr,
45
+ ): Promise<{ count: number; loginHistory: LoginHistory[] }> {
46
+ try {
47
+ // Part 1: Make sure loginUser got "LOGIN_HISTORY_REPORT" privilege.
48
+ const sc = ApplicationConfig.getComponentConfigValue('system-code');
49
+ const isPrivileged = await loginUser.checkPrivileges(
50
+ sc,
51
+ 'LOGIN_HISTORY_REPORT',
52
+ );
53
+
54
+ if (!isPrivileged) {
55
+ throw new ClassError(
56
+ 'System',
57
+ 'SystemErrMsg06',
58
+ 'You do not have permission to list login histories.',
59
+ );
60
+ }
61
+
62
+ //Part 2: Transform page and row into sequelize limit and offset & If search object exists, transform search object to Sequelize where object.
63
+ const queryObj: any = {};
64
+ const whereObj: any = {};
65
+
66
+ if (search) {
67
+ Object.entries(search).forEach(([key, value]) => {
68
+ if (value !== undefined && value !== null) {
69
+ if (key === 'DateFrom' || key === 'DateTo') {
70
+ // We'll handle DateFrom and DateTo after this loop
71
+ return;
72
+ }
73
+
74
+ queryObj[key] = {
75
+ [Op.substring]: value,
76
+ };
77
+ }
78
+ });
79
+ }
80
+
81
+ if (page && rows) {
82
+ whereObj.offset = (page - 1) * rows;
83
+ whereObj.limit = rows;
84
+ }
85
+
86
+ if (search?.DateFrom || search?.DateTo) {
87
+ queryObj.createdAt = {
88
+ ...(search?.DateFrom && { [Op.gte]: search.DateFrom }),
89
+ ...(search?.DateTo && { [Op.lte]: search.DateTo }),
90
+ };
91
+ }
92
+
93
+ //Part 3: Call the class' repo class findAndCountAll() method queryObj and whereObj
94
+ const result = await LoginHistory._Repo.findAllWithPagination({
95
+ distinct: true,
96
+ where: queryObj,
97
+ ...whereObj,
98
+ order: [['CreatedAt', 'DESC']],
99
+ transaction: dbTransaction,
100
+ });
101
+
102
+ //Part 4: Return the Count and LoginHistories.
103
+ const loginHistory = result.rows.map((data) => new LoginHistory(data));
104
+ return { count: result.count, loginHistory };
105
+ } catch (error) {
106
+ throw error;
107
+ }
108
+ }
109
+ }
@@ -0,0 +1,8 @@
1
+ export interface ILoginHistorySearchAttr {
2
+ UserId?: number;
3
+ SystemCode?: string;
4
+ LoginStatus?: string;
5
+ OriginIP?: string;
6
+ DateFrom?: Date;
7
+ DateTo?: Date;
8
+ }
@@ -0,0 +1,8 @@
1
+ export interface ILoginHistoryAttr {
2
+ HistoryId: number;
3
+ UserId: number;
4
+ OriginIp: string;
5
+ SystemCode: string;
6
+ LoginStatus: string;
7
+ CreatedAt: Date;
8
+ }
@@ -17,7 +17,7 @@ import { LoginStatusEnum } from '../enum/login-status.enum';
17
17
  createdAt: 'CreatedAt',
18
18
  updatedAt: false,
19
19
  })
20
- export default class LoginHistory extends Model {
20
+ export default class LoginHistoryModel extends Model {
21
21
  @Column({
22
22
  primaryKey: true,
23
23
  allowNull: false,
@@ -38,7 +38,7 @@ export default class LoginHistory extends Model {
38
38
  allowNull: true,
39
39
  type: DataType.STRING(10),
40
40
  })
41
- SystemCode: number;
41
+ SystemCode: string;
42
42
 
43
43
  @Column({
44
44
  allowNull: true,