spice-js 2.6.38 → 2.6.40

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.
@@ -1,41 +1,44 @@
1
- import flatten from "flat";
2
1
  import _ from "lodash";
3
2
  const fs = require("fs");
4
3
  const path = require("path");
5
4
 
6
5
  const { parse } = require("json2csv");
7
6
  export default class RestHelper {
8
- constructor() { }
9
- static async clear_pagination(ctx, next) {
10
- delete ctx.query.limit;
11
- delete ctx.query.offset;
12
- await next();
13
- }
7
+ constructor() {}
8
+ static async clear_pagination(ctx, next) {
9
+ delete ctx.query.limit;
10
+ delete ctx.query.offset;
11
+ await next();
12
+ }
14
13
 
15
- static async send_response(ctx, next) {
16
- try {
17
- let response;
18
- if (_.isArray(ctx.data)) {
19
- response = RestHelper.prepare_collection(RestHelper.SUCCESS, {
20
- data: ctx.data,
21
- total: ctx.total
22
- });
23
- } else {
24
- response = RestHelper.prepare_response(RestHelper.SUCCESS, ctx.data, ctx.errors, ctx.token);
25
- }
26
- ctx.status = 200;
27
- ctx.body = response;
28
- } catch (e) {
29
- console.log("Error at response: ", e, e.stack);
30
- }
14
+ static async send_response(ctx, next) {
15
+ try {
16
+ let response;
17
+ if (_.isArray(ctx.data)) {
18
+ response = RestHelper.prepare_collection(RestHelper.SUCCESS, {
19
+ data: ctx.data,
20
+ total: ctx.total,
21
+ });
22
+ } else {
23
+ response = RestHelper.prepare_response(
24
+ RestHelper.SUCCESS,
25
+ ctx.data,
26
+ ctx.errors,
27
+ ctx.token
28
+ );
29
+ }
30
+ ctx.status = 200;
31
+ ctx.body = response;
32
+ } catch (e) {
33
+ console.log("Error at response: ", e, e.stack);
31
34
  }
32
-
35
+ }
33
36
 
34
- static async clear_pagination(ctx, next) {
35
- delete ctx.query.limit;
36
- delete ctx.query.offset;
37
- await next();
38
- }
37
+ static async clear_pagination(ctx, next) {
38
+ delete ctx.query.limit;
39
+ delete ctx.query.offset;
40
+ await next();
41
+ }
39
42
 
40
43
  static async send_download(ctx, next) {
41
44
  function makeDirectory(dir) {
@@ -47,6 +50,7 @@ export default class RestHelper {
47
50
  let download_type = ctx.request.query.format || "csv";
48
51
  let content;
49
52
  if (download_type == "csv") {
53
+ const { flatten } = await import("flat");
50
54
  let items = _.map(ctx.data, (item) => {
51
55
  return flatten(item);
52
56
  });