@bmstravel/nvp-plop-templates 0.2.5 → 0.2.61

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- import { IBaseAction, IBaseAdapter, I{{pascalCase serviceName}}Service, UserAuthMeta } from "@src/types";
1
+ import { IBaseActionSchema, IBaseAdapter, I{{pascalCase serviceName}}Service, UserAuthMeta } from "@src/types";
2
2
  import { Context } from "moleculer";
3
3
  import { VISIBILITY, ERR_SYSTEM } from "@src/common";
4
4
  import { MoleculerRegularError } from "@src/errors";
@@ -7,71 +7,40 @@ export type {{pascalCase actionName}}Params = {
7
7
 
8
8
  }
9
9
 
10
+ async function handler(ctx: Context<{{pascalCase actionName}}Params, UserAuthMeta>) {
11
+ const $this: I{{pascalCase serviceName}}Service = this;
12
+ const $adapter: IBaseAdapter = $this.adapter;
13
+ const i18next = ctx.broker.i18next
14
+ try {
15
+ const params = ctx.params;
16
+ this.logger.info(`🎁 INFO $this:`, $this);
17
+ this.logger.info(`🎁 INFO $adapter:`, $adapter);
18
+ this.logger.info(`🎁 INFO params:`, params);
19
+
20
+ return {
21
+ code: 0,
22
+ data: {},
23
+ };
24
+ } catch(err) {
25
+ throw new MoleculerRegularError({
26
+ message: i18next.t('ERR_SYSTEM', ERR_SYSTEM.message),
27
+ code: ERR_SYSTEM.code,
28
+ type: ERR_SYSTEM.type,
29
+ data: {
30
+ error: err.message,
31
+ stack: err.stack,
32
+ },
33
+ error: err,
34
+ });
35
+ }
36
+ }
37
+
10
38
  /**
11
39
  * @description {{pascalCase actionName}} action
12
40
  * @example
13
41
  * rest: "POST {{pascalCase serviceName}}/{{pascalCase actionName}}",
14
- * cacher: {
15
- * keys: ["#token", "user"],
16
- * },
17
- * visibility: VISIBILITY.PUBLISHED,
18
- * timeout: 5000, // 5 secs
19
- * params: {
20
- * id: { type: "number", positive: true, integer: true },
21
- * name: "string|min:3|max:20", // empty:true,length:20,pattern:/^[a-z]$/,contains,numeric,enum,alpha,alphanum,alphadash,singleLine,hex,base64,trim,trimLeft,trimRight,lowercase:true,uppercase:true,convert:true
22
- * age: "number|optional|integer|positive|min:0|max:99", // convert:true, negative:true
23
- * thumb: "string|nullable|optional",
24
- * foo: "string[]",
25
- * recent: "boolean|default:true",
26
- * createdAt: {
27
- * type: "date",
28
- * default: (schema, field, parent, context) => new Date()
29
- * }
30
- * email: { type: "email" },
31
- * money: { type: "currency", currencySymbol: '$' },
32
- * dob: { type: "date" },
33
- * sex: { type: "enum", values: ["male", "female"] },
34
- * cache: [
35
- * { type: "string" },
36
- * { type: "boolean" }
37
- * ],
38
- * roles: [
39
- * { type: "array", unique: true },
40
- * // { type: "array", items: "string", default: ["user"] },
41
- * // { type: "array", items: "string", enum: [ "user", "admin" ] }
42
- * ],
43
- * status: { type: "multi", rules: [
44
- * { type: "boolean" },
45
- * { type: "number" }
46
- * ], default: true } // true,false,1,0
47
- * dot: {
48
- * $$type: "object",
49
- * x: "number", // object props here
50
- * y: "number", // object props here
51
- * },
52
- * circle: {
53
- * $$type: "object|optional",
54
- * o: {
55
- * $$type: "object",
56
- * x: "number",
57
- * y: "number",
58
- * },
59
- * r: "number"
60
- * },
61
- * list: { type: "array", min: 2, items: {
62
- * type: "number", positive: true, integer: true
63
- * } },
64
- * mac: { type: "mac" } // 01:C8:95:4B:65:FE, 01C8.954B.65FE, 01-C8-95-4B-65-FE,
65
- * url: { type: "url" },
66
- * uuid: { type: "uuid" },
67
- * _id: {
68
- * type: "objectID",
69
- * ObjectID // passing the ObjectID class example: const { ObjectID } = require("mongodb")
70
- * }
71
- * },
72
- * async handler(ctx: Context<any, any>) {}
73
42
  */
74
- const {{pascalCase actionName}}Action: IBaseAction = {
43
+ const {{pascalCase actionName}}Action: IBaseActionSchema<ReturnType<typeof handler>, {{pascalCase actionName}}Params, UserAuthMeta> = {
75
44
  {{#if actionPath}}
76
45
  rest: "{{method}} {{actionPath}}",
77
46
  {{/if}}
@@ -89,33 +58,7 @@ const {{pascalCase actionName}}Action: IBaseAction = {
89
58
  {{/eq}}
90
59
  params: {
91
60
  },
92
- async handler(ctx: Context<{{pascalCase actionName}}Params, UserAuthMeta>) {
93
- const $this: I{{pascalCase serviceName}}Service = this;
94
- const $adapter: IBaseAdapter = $this.adapter;
95
- const i18next = ctx.broker.i18next
96
- try {
97
- const params = ctx.params;
98
- this.logger.info(`🎁 INFO $this:`, $this);
99
- this.logger.info(`🎁 INFO $adapter:`, $adapter);
100
- this.logger.info(`🎁 INFO params:`, params);
101
-
102
- return {
103
- code: 0,
104
- data: {},
105
- };
106
- } catch(err) {
107
- throw new MoleculerRegularError({
108
- message: i18next.t('ERR_SYSTEM', ERR_SYSTEM.message),
109
- code: ERR_SYSTEM.code,
110
- type: ERR_SYSTEM.type,
111
- data: {
112
- error: err.message,
113
- stack: err.stack,
114
- },
115
- error: err,
116
- });
117
- }
118
- },
61
+ handler,
119
62
  };
120
63
 
121
64
  export default {{pascalCase actionName}}Action;
@@ -77,12 +77,16 @@ const {{pascalCase name}}Model: ISequelizeModel<I{{pascalCase name}}> = {
77
77
  createdAt: {
78
78
  type: DataTypes.BIGINT,
79
79
  allowNull: false,
80
- defaultValue: dayjs().valueOf(),
80
+ defaultValue: function () {
81
+ return dayjs().valueOf()
82
+ },
81
83
  },
82
84
  updatedAt: {
83
85
  type: DataTypes.BIGINT,
84
86
  allowNull: false,
85
- defaultValue: dayjs().valueOf(),
87
+ defaultValue: function () {
88
+ return dayjs().valueOf()
89
+ },
86
90
  },
87
91
  deletedAt: { type: DataTypes.BIGINT },
88
92
  {{/if}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bmstravel/nvp-plop-templates",
3
- "version": "0.2.5",
3
+ "version": "0.2.61",
4
4
  "description": "🏆 Using for plop templates",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -15,5 +15,5 @@
15
15
  "phongnv86 <phongnguyenvan86@gmail.com>",
16
16
  "phongnv86 <phongnv@media-one.vn>"
17
17
  ],
18
- "gitHead": "085c998c35b7c04fe33d302db01d1aacb0868f3a"
18
+ "gitHead": "6acafa3c6719a21132e6aaf8705830092afc7052"
19
19
  }