@tomei/sso 0.15.0 → 0.15.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,7 +20,7 @@ export class BuildingRepository
20
20
  return buildings;
21
21
  } catch (error) {
22
22
  throw new Error(
23
- `An Error occured when retriving product collection: ${error.message}`,
23
+ `An Error occured when retriving buildings: ${error.message}`,
24
24
  );
25
25
  }
26
26
  }
@@ -3,6 +3,8 @@ import { BuildingRepository } from './building.repository';
3
3
  import { LoginUser } from '../../..';
4
4
  import { ApplicationConfig } from '@tomei/config';
5
5
  import { Op } from 'sequelize';
6
+ import BuildingType from '../../models/building-type.entity';
7
+ import Country from '../../models/country.entity';
6
8
 
7
9
  export class Building {
8
10
  // implement all attributes from sso_buildings table
@@ -149,6 +151,7 @@ export class Building {
149
151
 
150
152
  let options: any = {
151
153
  where: whereObj,
154
+ include: [BuildingType, Country],
152
155
  order: [['created_at', 'DESC']],
153
156
  transaction: dbTransaction,
154
157
  };
@@ -7,4 +7,5 @@ export * from './user-group';
7
7
  export * from './user-user-group';
8
8
  export * from './building';
9
9
  export * from './building-type';
10
+ export * from './staff';
10
11
  //test ci
@@ -0,0 +1,3 @@
1
+ //export all files inside this folder
2
+ export * from './staff';
3
+ export * from './staff.repository';
@@ -0,0 +1,27 @@
1
+ import Staff from '../../models/staff.entity';
2
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
3
+
4
+ export class StaffRepository
5
+ extends RepositoryBase<Staff>
6
+ implements IRepositoryBase<Staff>
7
+ {
8
+ constructor() {
9
+ super(Staff);
10
+ }
11
+
12
+ async findAndCountAll(options?: any) {
13
+ try {
14
+ let staffs: any;
15
+ if (options) {
16
+ staffs = await Staff.findAndCountAll(options);
17
+ } else {
18
+ staffs = await Staff.findAndCountAll();
19
+ }
20
+ return staffs;
21
+ } catch (error) {
22
+ throw new Error(
23
+ `An Error occured when retriving staffs: ${error.message}`,
24
+ );
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,153 @@
1
+ import { IAddress, IPerson, ObjectBase } from '@tomei/general';
2
+ import { StaffRepository } from './staff.repository';
3
+ import { LoginUser } from '../../..';
4
+ import { ApplicationConfig } from '@tomei/config';
5
+ import { Op } from 'sequelize';
6
+ import StaffType from '../../models/staff-type.entity';
7
+ import Building from '../../models/building.entity';
8
+ import Department from '../../models/department.entity';
9
+ import BuildingType from '../../models/building-type.entity';
10
+
11
+ export class Staff extends ObjectBase implements IPerson {
12
+ ObjectId: string;
13
+ ObjectName: string;
14
+ TableName: 'sso_Staff';
15
+
16
+ FullName: string;
17
+ IDNo: string;
18
+ IDType: string;
19
+ Email: string;
20
+ ContactNo: string;
21
+ DefaultAddress: IAddress;
22
+
23
+ PreferredName: string;
24
+ StaffId: string;
25
+ StaffTypeId: number;
26
+ JobTitle: string;
27
+ CarPlate: string;
28
+ Mobile: string;
29
+ Floor: string;
30
+ Extension: string;
31
+ IsCharge: boolean;
32
+ Status: string;
33
+ CompanyId: number;
34
+ UserId: number;
35
+ BuildingId: number;
36
+ DepartmentId: number;
37
+ private _created_by_id;
38
+ private _updated_by_id;
39
+ private _created_at;
40
+ private _updated_at;
41
+ FullAddress: string;
42
+
43
+ private static _Repo = new StaffRepository();
44
+
45
+ getDetails():
46
+ | Promise<{
47
+ FullName: string;
48
+ IDNo: string;
49
+ IDType: string;
50
+ Email: string;
51
+ ContactNo: string;
52
+ }>
53
+ | {
54
+ FullName: string;
55
+ IDNo: string;
56
+ IDType: string;
57
+ Email: string;
58
+ ContactNo: string;
59
+ } {
60
+ throw new Error('Method not implemented.');
61
+ }
62
+
63
+ private constructor(staffInfo) {
64
+ super();
65
+ if (staffInfo) {
66
+ this.ObjectId = staffInfo.id;
67
+ this.UserId = staffInfo.user_id;
68
+ this.StaffId = staffInfo.staff_id;
69
+ this.FullName = staffInfo.full_name;
70
+ this.PreferredName = staffInfo.preferred_name;
71
+ this.IDNo = staffInfo.IdNo;
72
+ this.FullAddress = staffInfo.FullAddress;
73
+ this.StaffTypeId = staffInfo.staff_type_id;
74
+ this.Email = staffInfo.email;
75
+ this.CarPlate = staffInfo.car_plate;
76
+ this.Mobile = staffInfo.mobile;
77
+ this.Floor = staffInfo.floor;
78
+ this.Extension = staffInfo.extension;
79
+ this.IsCharge = staffInfo.is_charge;
80
+ this.BuildingId = staffInfo.building_id;
81
+ this.DepartmentId = staffInfo.department_id;
82
+ }
83
+ }
84
+
85
+ static async init(dbTransaction: any, staff_id?: string) {
86
+ if (staff_id) {
87
+ const staff = await Staff._Repo.findOne({
88
+ where: {
89
+ staff_id: staff_id,
90
+ },
91
+ });
92
+ if (!staff) {
93
+ throw Error('Building not found.');
94
+ }
95
+ return new Staff(staff);
96
+ }
97
+ }
98
+
99
+ static async findAll(
100
+ loginUser: LoginUser,
101
+ dbTransaction: any,
102
+ page?: number,
103
+ rows?: number,
104
+ search = {},
105
+ ) {
106
+ try {
107
+ const systemCode =
108
+ ApplicationConfig.getComponentConfigValue('system-code');
109
+
110
+ const isPrivileged = await loginUser.checkPrivileges(
111
+ systemCode,
112
+ 'Staff - View',
113
+ );
114
+ if (!isPrivileged) {
115
+ throw new Error('You do not have permission to view Building.');
116
+ }
117
+
118
+ const whereObj = {};
119
+
120
+ Object.keys(search).forEach((key) => {
121
+ if (search[key]) {
122
+ whereObj[key] = {
123
+ [Op.substring]: search[key],
124
+ };
125
+ }
126
+ });
127
+
128
+ let options: any = {
129
+ where: whereObj,
130
+ include: [
131
+ StaffType,
132
+ { model: Building, include: [BuildingType] },
133
+ Department,
134
+ ],
135
+ order: [['created_at', 'DESC']],
136
+ transaction: dbTransaction,
137
+ };
138
+
139
+ if (page && rows) {
140
+ const offset = rows * (page - 1);
141
+ options = {
142
+ ...options,
143
+ offset,
144
+ limit: rows,
145
+ };
146
+ }
147
+ const result = await Staff._Repo.findAndCountAll(options);
148
+ return result;
149
+ } catch (error) {
150
+ throw error;
151
+ }
152
+ }
153
+ }
@@ -47,20 +47,6 @@ export default class Country extends Model {
47
47
  })
48
48
  Phonecode: string;
49
49
 
50
- @Column({
51
- allowNull: true,
52
- type: DataType.INTEGER,
53
- field: 'created_by_id',
54
- })
55
- CreatedById: number;
56
-
57
- @Column({
58
- allowNull: true,
59
- type: DataType.INTEGER,
60
- field: 'updated_by_id',
61
- })
62
- UpdatedById: number;
63
-
64
50
  @CreatedAt
65
51
  CreatedAt: Date;
66
52