@digione/node-custom-api 0.2.0-alpha6 → 0.2.0-alpha7

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": "@digione/node-custom-api",
3
- "version": "0.2.0-alpha6",
3
+ "version": "0.2.0-alpha7",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
package/utils/file.d.ts CHANGED
@@ -89,6 +89,12 @@ export declare class FileUtil {
89
89
  tags?: TagFile;
90
90
  group?: any;
91
91
  }): Promise<any[]>;
92
+ countFileByFolder(slug: string, { where, parent_folder, tags, group }?: {
93
+ where?: {};
94
+ parent_folder?: string;
95
+ tags?: any[];
96
+ group?: any;
97
+ }): Promise<number>;
92
98
  findAndCountAllFileByFolder(slug: string, { where, file_link, parent_folder, limit, offset, tag, tags, group }?: {
93
99
  where?: {};
94
100
  file_link?: boolean;
package/utils/file.js CHANGED
@@ -373,6 +373,33 @@ class FileUtil {
373
373
  }
374
374
  });
375
375
  }
376
+ countFileByFolder(slug, { where = {}, parent_folder = "", tags = [], group = null } = {}) {
377
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
378
+ let include_folder = [];
379
+ if (parent_folder) {
380
+ where['$`f->p`.slug$'] = parent_folder;
381
+ include_folder.push({
382
+ required: true, attributes: [],
383
+ model: folder_1.FolderModel.schema(this.ref, "_"),
384
+ association: new sequelize_1.BelongsTo(folder_1.FolderModel, folder_1.FolderModel, { as: "p", foreignKey: "parent_id", constraints: false })
385
+ });
386
+ }
387
+ where['$f.slug$'] = slug;
388
+ where['is_hidden'] = where['is_hidden'] || "no";
389
+ let option = this.beforeFindFile(where, { tags, group, verify: true });
390
+ return yield file_1.FileModel.schema(this.ref, "_").count({
391
+ where: option.where,
392
+ include: [
393
+ {
394
+ required: true, attributes: [],
395
+ model: folder_1.FolderModel.schema(this.ref, "_"),
396
+ association: new sequelize_1.BelongsTo(file_1.FileModel, folder_1.FolderModel, { as: "f", foreignKey: "folder_id", constraints: false }),
397
+ include: include_folder
398
+ }
399
+ ]
400
+ });
401
+ });
402
+ }
376
403
  findAndCountAllFileByFolder(slug, { where = {}, file_link = false, parent_folder = "", limit = undefined, offset = undefined, tag = {}, tags = [], group = null } = {}) {
377
404
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
378
405
  let where_folder = {};
package/utils/stream.d.ts CHANGED
@@ -76,13 +76,14 @@ export declare class StreamUtil {
76
76
  include?: any;
77
77
  include_only?: boolean;
78
78
  }): any;
79
- buildStream(slug: string, namespace: string, { query, builder, fetch, label, attribute, attributes, field_exclude, include, include_all }?: {
79
+ buildStream(slug: string, namespace: string, { query, builder, fetch, label, attribute, attributes, field_option, field_exclude, include, include_all }?: {
80
80
  query?: boolean;
81
81
  builder?: boolean;
82
82
  fetch?: boolean;
83
83
  label?: boolean;
84
84
  attribute?: boolean;
85
85
  attributes?: any;
86
+ field_option?: {};
86
87
  field_exclude?: any[];
87
88
  include?: {};
88
89
  include_all?: boolean;
@@ -92,10 +93,11 @@ export declare class StreamUtil {
92
93
  fetchFn: any;
93
94
  attributes: any;
94
95
  }>;
95
- getBuilder(slug: string, namespace: string, { query, index, builder, field_exclude }?: {
96
+ getBuilder(slug: string, namespace: string, { query, index, builder, field_option, field_exclude }?: {
96
97
  query?: boolean;
97
98
  index?: string;
98
99
  builder?: boolean;
100
+ field_option?: {};
99
101
  field_exclude?: any[];
100
102
  }): Promise<any>;
101
103
  getValue(slug: string, namespace: string, value: any, { query, transform, spread, spread_all, raw, lang_code }?: {
@@ -305,7 +307,7 @@ export declare class StreamUtil {
305
307
  stripUnknown?: boolean;
306
308
  builder?: boolean;
307
309
  }): Promise<Joi.ObjectSchema<any>>;
308
- validate(slug: string, namespace: string, input: any, { req, isNew, default_value, lang, stripUnknown, inputLang, inputLangSeparate, prefixMessage, builder, field_exclude }?: {
310
+ validate(slug: string, namespace: string, input: any, { req, isNew, default_value, lang, stripUnknown, inputLang, inputLangSeparate, prefixMessage, builder, field_option, field_exclude }?: {
309
311
  req?: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
310
312
  isNew?: boolean;
311
313
  default_value?: {};
@@ -315,6 +317,7 @@ export declare class StreamUtil {
315
317
  inputLangSeparate?: boolean;
316
318
  prefixMessage?: string;
317
319
  builder?: boolean;
320
+ field_option?: {};
318
321
  field_exclude?: any[];
319
322
  }): Promise<any>;
320
323
  validateByField(streams: Array<any>, input: any, { req, isNew, default_value, lang, stripUnknown, inputLang, inputLangSeparate, prefixMessage }?: {
package/utils/stream.js CHANGED
@@ -235,13 +235,13 @@ class StreamUtil {
235
235
  }
236
236
  return data;
237
237
  }
238
- buildStream(slug, namespace, { query = true, builder = true, fetch = false, label = false, attribute = false, attributes = null, field_exclude = [], include = {}, include_all = false } = {}) {
238
+ buildStream(slug, namespace, { query = true, builder = true, fetch = false, label = false, attribute = false, attributes = null, field_option = {}, field_exclude = [], include = {}, include_all = false } = {}) {
239
239
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
240
240
  let build = this.builder[slug + "_" + namespace] || { stream: null, fields: null, fetchFn: [], attributes: null };
241
241
  if (!build['fields']) {
242
242
  let data = {};
243
243
  if (query)
244
- data = yield this.findField(slug, namespace, { field_only: false, convert_option: true, field_exclude });
244
+ data = yield this.findField(slug, namespace, { field_only: false, convert_option: true, field_option, field_exclude });
245
245
  build['fields'] = data['fields'] || [];
246
246
  build['stream'] = _.omit(data, ['fields']);
247
247
  }
@@ -312,9 +312,9 @@ class StreamUtil {
312
312
  return build;
313
313
  });
314
314
  }
315
- getBuilder(slug, namespace, { query = true, index = "", builder = true, field_exclude = [] } = {}) {
315
+ getBuilder(slug, namespace, { query = true, index = "", builder = true, field_option = {}, field_exclude = [] } = {}) {
316
316
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
317
- let result = yield this.buildStream(slug, namespace, { query, builder, field_exclude });
317
+ let result = yield this.buildStream(slug, namespace, { query, builder, field_option, field_exclude });
318
318
  return index ? result[index] : result;
319
319
  });
320
320
  }
@@ -2056,9 +2056,9 @@ class StreamUtil {
2056
2056
  return yield this.getValidator(streams, { req, isNew, required, lang, stripUnknown });
2057
2057
  });
2058
2058
  }
2059
- validate(slug, namespace, input, { req = {}, isNew = false, default_value = {}, lang = [], stripUnknown = false, inputLang = false, inputLangSeparate = true, prefixMessage = "", builder = true, field_exclude = [] } = {}) {
2059
+ validate(slug, namespace, input, { req = {}, isNew = false, default_value = {}, lang = [], stripUnknown = false, inputLang = false, inputLangSeparate = true, prefixMessage = "", builder = true, field_option = {}, field_exclude = [] } = {}) {
2060
2060
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
2061
- let streams = yield this.getBuilder(slug, namespace, { index: "fields", builder, field_exclude });
2061
+ let streams = yield this.getBuilder(slug, namespace, { index: "fields", builder, field_option, field_exclude });
2062
2062
  return this.validateByField(streams, input, { req, isNew, default_value, lang, stripUnknown, inputLang, inputLangSeparate, prefixMessage });
2063
2063
  });
2064
2064
  }