@triproject/nestjs-core 1.0.43 → 1.0.44
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.
|
@@ -19,26 +19,28 @@ export declare class Repository<M extends Model<M, Partial<M>> & {
|
|
|
19
19
|
label: string;
|
|
20
20
|
value: string | number;
|
|
21
21
|
}>(params: PaginateRequest<M>, mapInto: (data: M) => P): Promise<P[]>;
|
|
22
|
-
protected
|
|
23
|
-
protected
|
|
24
|
-
protected
|
|
25
|
-
protected
|
|
26
|
-
protected
|
|
27
|
-
protected
|
|
28
|
-
protected
|
|
22
|
+
protected _paginate<P>(params: PaginateRequest<M>): Promise<PaginateResponse<M>>;
|
|
23
|
+
protected _paginate<P>(params: PaginateRequest<M>, mapInto: new (data: M) => P): Promise<PaginateResponse<P>>;
|
|
24
|
+
protected _paginateCursor(params: PaginateCursorRequest<M>): Promise<PaginateCursorResponse<M>>;
|
|
25
|
+
protected _paginateCursor<P>(params: PaginateCursorRequest<M>, mapInto: new (data: M) => P): Promise<PaginateCursorResponse<P>>;
|
|
26
|
+
protected _export(params: PaginateRequest<M>): Promise<M[]>;
|
|
27
|
+
protected _export(params: PaginateRequest<M>, mapInto: new (data: M) => string[]): Promise<string[][]>;
|
|
28
|
+
protected _updateOrCreate(values: CreationAttributes<M>, whereOptions: WhereOptions<M>, options?: CreateOptions<M> | UpdateOptions<M>): Promise<M>;
|
|
29
|
+
protected _findAll(options?: FindOptions<M>): Promise<M[]>;
|
|
30
|
+
protected _findAndCountAll(options: FindAndCountOptions<M>): Promise<{
|
|
29
31
|
rows: M[];
|
|
30
32
|
count: number;
|
|
31
33
|
}>;
|
|
32
|
-
protected
|
|
33
|
-
protected
|
|
34
|
-
protected
|
|
35
|
-
protected
|
|
36
|
-
protected
|
|
37
|
-
protected
|
|
38
|
-
protected
|
|
39
|
-
protected
|
|
40
|
-
protected
|
|
41
|
-
protected
|
|
42
|
-
protected
|
|
34
|
+
protected _findOne(options: FindOptions<M>): Promise<M | null>;
|
|
35
|
+
protected _create(values: CreationAttributes<M>, options?: CreateOptions<M>): Promise<M>;
|
|
36
|
+
protected _update(entity: M | string | number, values: Partial<M>, options?: Partial<UpdateOptions<M>>): Promise<M>;
|
|
37
|
+
protected _upsert(values: CreationAttributes<M>, options?: Partial<UpsertOptions<Attributes<M>>>): Promise<[M, boolean | null]>;
|
|
38
|
+
protected _bulkUpdate(values: Partial<M>, options: UpdateOptions<M>): Promise<[number]>;
|
|
39
|
+
protected _bulkCreate(values: ReadonlyArray<CreationAttributes<M>>, options?: BulkCreateOptions<M>): Promise<M[]>;
|
|
40
|
+
protected _destroy(options: DestroyOptions<M>): Promise<number>;
|
|
41
|
+
protected _sum(field: keyof Attributes<M>, options?: AggregateOptions<M>): Promise<number>;
|
|
42
|
+
protected _sumField(params: PaginateRequest<M>, field: keyof Attributes<M>): Promise<number>;
|
|
43
|
+
protected _sumCol(params: PaginateRequest<M>, fieldToSum: string, expectedField: string): Promise<number>;
|
|
44
|
+
protected _count(options: FindOptions<M>): Promise<number>;
|
|
43
45
|
protected filteredFindAll(params: PaginateRequest<M>): Promise<M[]>;
|
|
44
46
|
}
|
|
@@ -121,13 +121,13 @@ let Repository = class Repository {
|
|
|
121
121
|
}
|
|
122
122
|
async findForPublic(params, mapInto) {
|
|
123
123
|
let options = this._getOptions(params), limit = +(params?.perPage ?? 20);
|
|
124
|
-
return (await this.
|
|
124
|
+
return (await this._findAll({
|
|
125
125
|
...options,
|
|
126
126
|
limit
|
|
127
127
|
})).map((d)=>mapInto(d));
|
|
128
128
|
}
|
|
129
|
-
async
|
|
130
|
-
let options = this._getOptions(params), limit = +(params?.perPage ?? 20), page = +(params?.page ?? 1), data = await this.
|
|
129
|
+
async _paginate(params, mapInto) {
|
|
130
|
+
let options = this._getOptions(params), limit = +(params?.perPage ?? 20), page = +(params?.page ?? 1), data = await this._findAndCountAll({
|
|
131
131
|
limit,
|
|
132
132
|
offset: page > 1 ? limit * (page - 1) : 0,
|
|
133
133
|
...options,
|
|
@@ -136,7 +136,7 @@ let Repository = class Repository {
|
|
|
136
136
|
data.count = Array.isArray(data.count) ? data.count.length : data.count;
|
|
137
137
|
let totalPage = Math.ceil(data.count / limit);
|
|
138
138
|
return {
|
|
139
|
-
data: mapInto ? data.rows.map((d)=>mapInto(d)) : data.rows,
|
|
139
|
+
data: mapInto ? data.rows.map((d)=>new mapInto(d)) : data.rows,
|
|
140
140
|
timestamp: (0, _helpers.dateUtil)().utc().toISOString(),
|
|
141
141
|
meta: {
|
|
142
142
|
perPage: limit,
|
|
@@ -148,7 +148,7 @@ let Repository = class Repository {
|
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
-
async
|
|
151
|
+
async _paginateCursor(params, mapInto) {
|
|
152
152
|
if (!this.FIELDS?.includes('id')) throw new _common.UnprocessableEntityException('Entity must have id attribute for cursor pagination');
|
|
153
153
|
params.attributes = (0, _helpers.uniqueArray)([
|
|
154
154
|
...params.attributes || [],
|
|
@@ -161,12 +161,12 @@ let Repository = class Repository {
|
|
|
161
161
|
[_sequelize.Op.gt]: params.cursor
|
|
162
162
|
}, options.where = whereClause;
|
|
163
163
|
}
|
|
164
|
-
let data = await this.
|
|
164
|
+
let data = await this._findAll({
|
|
165
165
|
...options,
|
|
166
166
|
limit
|
|
167
167
|
}), lastId = data[data.length - 1]?.id, nextCursor = data.length > 0 && lastId ? String(lastId) : null;
|
|
168
168
|
return {
|
|
169
|
-
data: mapInto ? data.map((d)=>mapInto(d)) : data,
|
|
169
|
+
data: mapInto ? data.map((d)=>new mapInto(d)) : data,
|
|
170
170
|
timestamp: (0, _helpers.dateUtil)().utc().toISOString(),
|
|
171
171
|
meta: {
|
|
172
172
|
perPage: limit,
|
|
@@ -174,39 +174,39 @@ let Repository = class Repository {
|
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
async
|
|
178
|
-
let options = this._getOptions(params), data = await this.
|
|
179
|
-
return mapInto ? data.map((d)=>mapInto(d)) : data;
|
|
177
|
+
async _export(params, mapInto) {
|
|
178
|
+
let options = this._getOptions(params), data = await this._findAll(options);
|
|
179
|
+
return mapInto ? data.map((d)=>new mapInto(d)) : data;
|
|
180
180
|
}
|
|
181
|
-
async
|
|
182
|
-
let data = await this.
|
|
181
|
+
async _updateOrCreate(values, whereOptions, options) {
|
|
182
|
+
let data = await this._findOne({
|
|
183
183
|
where: whereOptions
|
|
184
184
|
});
|
|
185
|
-
return data ? (await this.
|
|
185
|
+
return data ? (await this._update(data, values, options), data) : await this._create(values, options);
|
|
186
186
|
}
|
|
187
|
-
async
|
|
187
|
+
async _findAll(options) {
|
|
188
188
|
return this.Model.findAll(options).catch((error)=>{
|
|
189
189
|
throw this._errorHandler(error);
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
|
-
async
|
|
192
|
+
async _findAndCountAll(options) {
|
|
193
193
|
return this.Model.findAndCountAll(options).catch((error)=>{
|
|
194
194
|
throw this._errorHandler(error);
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
async
|
|
197
|
+
async _findOne(options) {
|
|
198
198
|
return this.Model.findOne(options).catch((error)=>{
|
|
199
199
|
throw this._errorHandler(error);
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
|
-
async
|
|
202
|
+
async _create(values, options) {
|
|
203
203
|
return this.Model.create(values, options).catch((error)=>{
|
|
204
204
|
throw this._errorHandler(error);
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
|
-
async
|
|
207
|
+
async _update(entity, values, options) {
|
|
208
208
|
let model = entity;
|
|
209
|
-
if (('string' == typeof entity || 'number' == typeof entity) && (model = await this.
|
|
209
|
+
if (('string' == typeof entity || 'number' == typeof entity) && (model = await this._findOne({
|
|
210
210
|
where: {
|
|
211
211
|
id: entity
|
|
212
212
|
},
|
|
@@ -220,42 +220,42 @@ let Repository = class Repository {
|
|
|
220
220
|
throw this._errorHandler(error);
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
|
-
async
|
|
223
|
+
async _upsert(values, options) {
|
|
224
224
|
return this.Model.upsert(values, {
|
|
225
225
|
...options
|
|
226
226
|
}).catch((error)=>{
|
|
227
227
|
throw this._errorHandler(error);
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
async
|
|
230
|
+
async _bulkUpdate(values, options) {
|
|
231
231
|
return this.Model.update(values, {
|
|
232
232
|
...options
|
|
233
233
|
}).catch((error)=>{
|
|
234
234
|
throw this._errorHandler(error);
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
|
-
async
|
|
237
|
+
async _bulkCreate(values, options) {
|
|
238
238
|
return this.Model.bulkCreate(values, options).catch((error)=>{
|
|
239
239
|
throw this._errorHandler(error);
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
|
-
async
|
|
242
|
+
async _destroy(options) {
|
|
243
243
|
return this.Model.destroy(options).catch((error)=>{
|
|
244
244
|
throw this._errorHandler(error);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
async
|
|
247
|
+
async _sum(field, options) {
|
|
248
248
|
return this.Model.sum(field, options).catch((error)=>{
|
|
249
249
|
throw this._errorHandler(error);
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
async
|
|
252
|
+
async _sumField(params, field) {
|
|
253
253
|
let options = this._getOptions(params);
|
|
254
|
-
return this.
|
|
254
|
+
return this._sum(field, options).catch((error)=>{
|
|
255
255
|
throw this._errorHandler(error);
|
|
256
256
|
});
|
|
257
257
|
}
|
|
258
|
-
async
|
|
258
|
+
async _sumCol(params, fieldToSum, expectedField) {
|
|
259
259
|
let options = this._getOptions(params);
|
|
260
260
|
return options.attributes = [
|
|
261
261
|
[
|
|
@@ -266,7 +266,7 @@ let Repository = class Repository {
|
|
|
266
266
|
throw this._errorHandler(error);
|
|
267
267
|
})).reduce((total, row)=>total + parseFloat(String(row.get(expectedField)) || '0'), 0);
|
|
268
268
|
}
|
|
269
|
-
async
|
|
269
|
+
async _count(options) {
|
|
270
270
|
return this.Model.count(options).catch((error)=>{
|
|
271
271
|
throw this._errorHandler(error);
|
|
272
272
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triproject/nestjs-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
4
4
|
"author": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"description": "A collection of NestJS modules and utilities to speed up development.",
|
|
@@ -148,7 +148,8 @@
|
|
|
148
148
|
"sequelize": "^6.37.7",
|
|
149
149
|
"sequelize-typescript": "^2.1.6",
|
|
150
150
|
"speakeasy": "^2.0.0",
|
|
151
|
-
"ua-parser-js": "^2.0.8"
|
|
151
|
+
"ua-parser-js": "^2.0.8",
|
|
152
|
+
"class-transformer": "^0.5.1"
|
|
152
153
|
},
|
|
153
154
|
"peerDependenciesMeta": {
|
|
154
155
|
"amqplib": {
|
|
@@ -220,9 +221,6 @@
|
|
|
220
221
|
"exceljs": {
|
|
221
222
|
"optional": true
|
|
222
223
|
},
|
|
223
|
-
"rxjs": {
|
|
224
|
-
"optional": true
|
|
225
|
-
},
|
|
226
224
|
"@nest-lab/throttler-storage-redis": {
|
|
227
225
|
"optional": true
|
|
228
226
|
},
|
|
@@ -291,6 +289,7 @@
|
|
|
291
289
|
"ts-node": "^1.7.1",
|
|
292
290
|
"typescript": "^5.9.3",
|
|
293
291
|
"ua-parser-js": "^2.0.8",
|
|
294
|
-
"vitest": "^4.0.17"
|
|
292
|
+
"vitest": "^4.0.17",
|
|
293
|
+
"class-transformer": "^0.5.1"
|
|
295
294
|
}
|
|
296
295
|
}
|