flamerest 1.0.92 → 1.0.94

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.
Files changed (3) hide show
  1. package/REST.d.ts +15 -1
  2. package/REST.js +17 -9
  3. package/package.json +1 -1
package/REST.d.ts CHANGED
@@ -69,7 +69,21 @@ interface IREST {
69
69
  * @param {object} params
70
70
  * @returns
71
71
  */
72
- all<T>(table: string, params?: { where?: object, extfields?: object | Array<string>, fields?: object | Array<string>, sort?: Array<string>, page?: number, perPage?: number, tree?: number }): Promise<Rows<T>>,
72
+ all<T>(table: string, params?: {
73
+ where?: object,
74
+ extfields?: object | Array<string>,
75
+ fields?: object | Array<string>,
76
+ sort?: Array<string>,
77
+ page?: number,
78
+ perPage?: number,
79
+ tree?: number,
80
+ params?: any,
81
+ export?: {
82
+ format?: 'xlsx' | 'csv',
83
+ titles?: Array<string>,
84
+ filename?: string,
85
+ }
86
+ }): Promise<Rows<T>>,
73
87
 
74
88
  /**
75
89
  * Получить одну запись по ID или по условию выборки [первая запись]
package/REST.js CHANGED
@@ -319,9 +319,11 @@ class FLAMEREST {
319
319
  * @param format
320
320
  * @param titles Это чтобы мы могли контроллить какие названия полей мы будет загружать при экспорте, чтобы они были как в таблице
321
321
  * @param tree дерево
322
+ * @param params Доп параметры для кастомизации запроса на беке
323
+ * @param exportData имя файла для экспорта
322
324
  * @return Promise<>
323
325
  */
324
- get(table, where, extfields, fields, sortfields, page, perPage, RemoveDuplicates, format, titles, tree) {
326
+ get(table, where, extfields, fields, sortfields, page, perPage, RemoveDuplicates, format, titles, tree, params, exportData) {
325
327
 
326
328
  // Нормализуем имена таблиц
327
329
  table = table.replace(/_/g, "");
@@ -344,25 +346,31 @@ class FLAMEREST {
344
346
  if (fields !== undefined && fields !== null)
345
347
  json.fields = fields;
346
348
 
347
- if (titles !== undefined && titles !== null)
348
- json.titles = titles;
349
-
350
349
  if (sortfields !== undefined && sortfields !== null)
351
350
  json.sort = sortfields;
352
351
 
353
352
  if (extfields !== undefined && extfields !== null)
354
353
  json.extfields = extfields;
355
354
 
355
+ if (params !== undefined && params !== null)
356
+ json.params = params;
357
+
356
358
  if (RemoveDuplicates !== undefined && RemoveDuplicates !== null)
357
359
  json.RemoveDuplicates = true;
358
360
 
359
- if (format !== undefined && format !== null) {
360
- json.format = format;
361
+ if (titles !== undefined && titles !== null)
362
+ json.titles = titles;
363
+
364
+ // экспорт
365
+ if (exportData !== undefined && exportData !== null) {
366
+ json.export = {
367
+ format: exportData.format ?? 'xlsx',
368
+ titles: exportData.titles ?? [],
369
+ filename: exportData.filename ?? 'export_' + new Date().toUTCString + ".xlsx",
370
+ };
361
371
  responseType = "blob";
362
372
  }
363
373
 
364
-
365
-
366
374
  // Страницы
367
375
  json['per-page'] = perPage === undefined ? this.perPageDefault : perPage;
368
376
  json['page'] = page === undefined ? 1 : page;
@@ -378,7 +386,7 @@ class FLAMEREST {
378
386
  * @returns {object}
379
387
  */
380
388
  all(table, params) {
381
- return this.get(table, params?.where, params?.extfields, params?.fields, params?.sort, params?.page, params?.perPage, null, null, null, params?.tree);
389
+ return this.get(table, params?.where, params?.extfields, params?.fields, params?.sort, params?.page, params?.perPage, null, null, null, params?.tree, params?.params, params?.export);
382
390
  }
383
391
 
384
392
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flamerest",
3
- "version": "1.0.92",
3
+ "version": "1.0.94",
4
4
  "description": "",
5
5
  "main": "REST.js",
6
6
  "typings": "./REST.d.ts",