@tomei/sso 0.15.1 → 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/dist/src/components/building/building.repository.js +1 -1
- package/dist/src/components/building/building.repository.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/staff/index.d.ts +2 -0
- package/dist/src/components/staff/index.js +19 -0
- package/dist/src/components/staff/index.js.map +1 -0
- package/dist/src/components/staff/staff.d.ts +49 -0
- package/dist/src/components/staff/staff.js +102 -0
- package/dist/src/components/staff/staff.js.map +1 -0
- package/dist/src/components/staff/staff.repository.d.ts +6 -0
- package/dist/src/components/staff/staff.repository.js +38 -0
- package/dist/src/components/staff/staff.repository.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/building/building.repository.ts +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/staff/index.ts +3 -0
- package/src/components/staff/staff.repository.ts +27 -0
- package/src/components/staff/staff.ts +153 -0
package/package.json
CHANGED
package/src/components/index.ts
CHANGED
@@ -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
|
+
}
|