@tomei/sso 0.14.0 → 0.15.1
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.d.ts +1 -0
- package/dist/src/components/building/building.js +39 -2
- package/dist/src/components/building/building.js.map +1 -1
- package/dist/src/components/building/building.repository.d.ts +1 -0
- package/dist/src/components/building/building.repository.js +26 -0
- package/dist/src/components/building/building.repository.js.map +1 -1
- package/dist/src/models/country.entity.d.ts +0 -2
- package/dist/src/models/country.entity.js +0 -16
- package/dist/src/models/country.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/building/building.repository.ts +16 -0
- package/src/components/building/building.ts +56 -2
- package/src/models/country.entity.ts +0 -14
package/package.json
CHANGED
@@ -8,4 +8,20 @@ export class BuildingRepository
|
|
8
8
|
constructor() {
|
9
9
|
super(Building);
|
10
10
|
}
|
11
|
+
|
12
|
+
async findAndCountAll(options?: any) {
|
13
|
+
try {
|
14
|
+
let buildings: any;
|
15
|
+
if (options) {
|
16
|
+
buildings = await Building.findAndCountAll(options);
|
17
|
+
} else {
|
18
|
+
buildings = await Building.findAndCountAll();
|
19
|
+
}
|
20
|
+
return buildings;
|
21
|
+
} catch (error) {
|
22
|
+
throw new Error(
|
23
|
+
`An Error occured when retriving product collection: ${error.message}`,
|
24
|
+
);
|
25
|
+
}
|
26
|
+
}
|
11
27
|
}
|
@@ -2,6 +2,9 @@ import { BuildingTypeRepository } from '../building-type/building-type.repositor
|
|
2
2
|
import { BuildingRepository } from './building.repository';
|
3
3
|
import { LoginUser } from '../../..';
|
4
4
|
import { ApplicationConfig } from '@tomei/config';
|
5
|
+
import { Op } from 'sequelize';
|
6
|
+
import BuildingType from '../../models/building-type.entity';
|
7
|
+
import Country from '../../models/country.entity';
|
5
8
|
|
6
9
|
export class Building {
|
7
10
|
// implement all attributes from sso_buildings table
|
@@ -86,10 +89,10 @@ export class Building {
|
|
86
89
|
|
87
90
|
const isPrivileged = await loginUser.checkPrivileges(
|
88
91
|
systemCode,
|
89
|
-
'
|
92
|
+
'Building - View',
|
90
93
|
);
|
91
94
|
if (!isPrivileged) {
|
92
|
-
throw new Error('You do not have permission to view
|
95
|
+
throw new Error('You do not have permission to view Building.');
|
93
96
|
}
|
94
97
|
|
95
98
|
if (!this.building_type_id) {
|
@@ -116,4 +119,55 @@ export class Building {
|
|
116
119
|
BuildingType: this._BuildingType,
|
117
120
|
};
|
118
121
|
}
|
122
|
+
|
123
|
+
static async findAll(
|
124
|
+
loginUser: LoginUser,
|
125
|
+
dbTransaction: any,
|
126
|
+
page?: number,
|
127
|
+
rows?: number,
|
128
|
+
search = {},
|
129
|
+
) {
|
130
|
+
try {
|
131
|
+
const systemCode =
|
132
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
133
|
+
|
134
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
135
|
+
systemCode,
|
136
|
+
'Building - View',
|
137
|
+
);
|
138
|
+
if (!isPrivileged) {
|
139
|
+
throw new Error('You do not have permission to view Building.');
|
140
|
+
}
|
141
|
+
|
142
|
+
const whereObj = {};
|
143
|
+
|
144
|
+
Object.keys(search).forEach((key) => {
|
145
|
+
if (search[key]) {
|
146
|
+
whereObj[key] = {
|
147
|
+
[Op.substring]: search[key],
|
148
|
+
};
|
149
|
+
}
|
150
|
+
});
|
151
|
+
|
152
|
+
let options: any = {
|
153
|
+
where: whereObj,
|
154
|
+
include: [BuildingType, Country],
|
155
|
+
order: [['created_at', 'DESC']],
|
156
|
+
transaction: dbTransaction,
|
157
|
+
};
|
158
|
+
|
159
|
+
if (page && rows) {
|
160
|
+
const offset = rows * (page - 1);
|
161
|
+
options = {
|
162
|
+
...options,
|
163
|
+
offset,
|
164
|
+
limit: rows,
|
165
|
+
};
|
166
|
+
}
|
167
|
+
const result = await Building._Repo.findAndCountAll(options);
|
168
|
+
return result;
|
169
|
+
} catch (error) {
|
170
|
+
throw error;
|
171
|
+
}
|
172
|
+
}
|
119
173
|
}
|
@@ -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
|
|