@bmstravel/nvp-plop-templates 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
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:
|
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
|
-
|
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;
|
@@ -24,6 +24,7 @@ export const {{pascalCase mixinName}}Mixin = () => {
|
|
24
24
|
/* MOL_METHOD_MIXIN */
|
25
25
|
async {{camelCase mixinMethod}}({ }: {{pascalCase mixinMethod}}Params) {
|
26
26
|
const $this: IBaseService<any, any> = this
|
27
|
+
$this.logger.info("{{camelCase mixinMethod}} parameters", ctx.params)
|
27
28
|
const $cacher = $this.broker.cacher as RedisCacher
|
28
29
|
return {}
|
29
30
|
},
|
@@ -35,10 +36,11 @@ export const {{pascalCase mixinName}}Mixin = () => {
|
|
35
36
|
{{camelCase mixinAction}}: {
|
36
37
|
async handler(ctx: Context<{{pascalCase mixinAction}}Params, any>) {
|
37
38
|
const $this: IBaseService<any, any> = this
|
39
|
+
$this.logger.info("{{camelCase mixinAction}} parameters", ctx.params)
|
38
40
|
return {
|
39
41
|
code: 0,
|
40
42
|
data: {},
|
41
|
-
}
|
43
|
+
}
|
42
44
|
},
|
43
45
|
}
|
44
46
|
}
|
@@ -50,7 +52,7 @@ export const {{pascalCase mixinName}}Mixin = () => {
|
|
50
52
|
params: {},
|
51
53
|
handler(ctx: Context<{{pascalCase mixinEvent}}Params, any>) {
|
52
54
|
const $this: IBaseService<any, any> = this
|
53
|
-
$this.logger.info("
|
55
|
+
$this.logger.info("{{camelCase mixinEvent}} event received, parameters OK!", ctx.params);
|
54
56
|
},
|
55
57
|
}
|
56
58
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bmstravel/nvp-plop-templates",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.6",
|
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": "
|
18
|
+
"gitHead": "8e2aefd89cbc161e10838a2a479f7182e4bc41b1"
|
19
19
|
}
|