@tomei/sso 0.14.0 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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,7 @@ 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';
5
6
 
6
7
  export class Building {
7
8
  // implement all attributes from sso_buildings table
@@ -86,10 +87,10 @@ export class Building {
86
87
 
87
88
  const isPrivileged = await loginUser.checkPrivileges(
88
89
  systemCode,
89
- 'Store - View',
90
+ 'Building - View',
90
91
  );
91
92
  if (!isPrivileged) {
92
- throw new Error('You do not have permission to view store.');
93
+ throw new Error('You do not have permission to view Building.');
93
94
  }
94
95
 
95
96
  if (!this.building_type_id) {
@@ -116,4 +117,54 @@ export class Building {
116
117
  BuildingType: this._BuildingType,
117
118
  };
118
119
  }
120
+
121
+ static async findAll(
122
+ loginUser: LoginUser,
123
+ dbTransaction: any,
124
+ page?: number,
125
+ rows?: number,
126
+ search = {},
127
+ ) {
128
+ try {
129
+ const systemCode =
130
+ ApplicationConfig.getComponentConfigValue('system-code');
131
+
132
+ const isPrivileged = await loginUser.checkPrivileges(
133
+ systemCode,
134
+ 'Building - View',
135
+ );
136
+ if (!isPrivileged) {
137
+ throw new Error('You do not have permission to view Building.');
138
+ }
139
+
140
+ const whereObj = {};
141
+
142
+ Object.keys(search).forEach((key) => {
143
+ if (search[key]) {
144
+ whereObj[key] = {
145
+ [Op.substring]: search[key],
146
+ };
147
+ }
148
+ });
149
+
150
+ let options: any = {
151
+ where: whereObj,
152
+ order: [['created_at', 'DESC']],
153
+ transaction: dbTransaction,
154
+ };
155
+
156
+ if (page && rows) {
157
+ const offset = rows * (page - 1);
158
+ options = {
159
+ ...options,
160
+ offset,
161
+ limit: rows,
162
+ };
163
+ }
164
+ const result = await Building._Repo.findAndCountAll(options);
165
+ return result;
166
+ } catch (error) {
167
+ throw error;
168
+ }
169
+ }
119
170
  }