@things-factory/operato-hub 4.3.218 → 4.3.219
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/config.development.js +108 -75
- package/dist-server/routers/internal/index.js +6 -0
- package/dist-server/routers/internal/index.js.map +1 -0
- package/dist-server/routers/internal/middlewares/index.js +20 -0
- package/dist-server/routers/internal/middlewares/index.js.map +1 -0
- package/dist-server/routers/internal/middlewares/logging-middleware.js +23 -0
- package/dist-server/routers/internal/middlewares/logging-middleware.js.map +1 -0
- package/dist-server/routers/internal/middlewares/validation-middleware.js +110 -0
- package/dist-server/routers/internal/middlewares/validation-middleware.js.map +1 -0
- package/dist-server/routers/internal/powrup-router.js +183 -0
- package/dist-server/routers/internal/powrup-router.js.map +1 -0
- package/dist-server/routers/internal/utils/error-util.js +71 -0
- package/dist-server/routers/internal/utils/error-util.js.map +1 -0
- package/dist-server/routers/internal/utils/params.js +31 -0
- package/dist-server/routers/internal/utils/params.js.map +1 -0
- package/dist-server/routes.js +2 -1
- package/dist-server/routes.js.map +1 -1
- package/package.json +13 -13
- package/server/routers/internal/index.ts +3 -0
- package/server/routers/internal/middlewares/index.ts +4 -0
- package/server/routers/internal/middlewares/logging-middleware.ts +24 -0
- package/server/routers/internal/middlewares/validation-middleware.ts +107 -0
- package/server/routers/internal/powrup-router.ts +208 -0
- package/server/routers/internal/utils/error-util.ts +70 -0
- package/server/routers/internal/utils/params.ts +28 -0
- package/server/routes.ts +7 -1
package/config.development.js
CHANGED
|
@@ -1,106 +1,146 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
domainType: 'company',
|
|
3
3
|
domainExtType: 'company',
|
|
4
|
+
useVirtualHostBasedDomain: false,
|
|
5
|
+
fallbackRoute: '/',
|
|
4
6
|
subdomainOffset: 2,
|
|
7
|
+
port: 3000,
|
|
8
|
+
inspect: '9260',
|
|
9
|
+
// ormconfig: {
|
|
10
|
+
// name: 'default',
|
|
11
|
+
// type: 'postgres',
|
|
12
|
+
// database: 'dev',
|
|
13
|
+
// username: 'postgres',
|
|
14
|
+
// password: 'abcd1234',
|
|
15
|
+
// host: 'operatov3.cluster-cijhm4n1hbst.ap-southeast-1.rds.amazonaws.com',
|
|
16
|
+
// port: 55432,
|
|
17
|
+
// synchronize: false,
|
|
18
|
+
// logging: true
|
|
19
|
+
// },
|
|
20
|
+
// ormconfig: {
|
|
21
|
+
// name: 'default',
|
|
22
|
+
// type: 'postgres',
|
|
23
|
+
// database: 'v3-hub1',
|
|
24
|
+
// username: 'postgres',
|
|
25
|
+
// password: 'hatio',
|
|
26
|
+
// host: 'localhost',
|
|
27
|
+
// port: 15432,
|
|
28
|
+
// synchronize: true,
|
|
29
|
+
// logging: true
|
|
30
|
+
// },
|
|
5
31
|
ormconfig: {
|
|
6
32
|
name: 'default',
|
|
7
33
|
type: 'postgres',
|
|
8
|
-
database: '
|
|
34
|
+
database: 'dev2',
|
|
9
35
|
username: 'postgres',
|
|
10
36
|
password: 'hatio',
|
|
11
|
-
host: '192.168.0.
|
|
37
|
+
host: '192.168.0.161',
|
|
12
38
|
port: 15432,
|
|
13
|
-
synchronize:
|
|
14
|
-
logging:
|
|
39
|
+
synchronize: true,
|
|
40
|
+
logging: true
|
|
15
41
|
},
|
|
16
42
|
// ormconfig: {
|
|
17
43
|
// name: 'default',
|
|
18
44
|
// type: 'postgres',
|
|
19
|
-
// database: '
|
|
45
|
+
// database: 'dev',
|
|
20
46
|
// username: 'postgres',
|
|
21
|
-
// password: '
|
|
22
|
-
// host: '
|
|
23
|
-
// port:
|
|
24
|
-
// synchronize:
|
|
25
|
-
// logging:
|
|
47
|
+
// password: 'hatio',
|
|
48
|
+
// host: 'localhost',
|
|
49
|
+
// port: 15432,
|
|
50
|
+
// synchronize: true,
|
|
51
|
+
// logging: true
|
|
26
52
|
// },
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
messagingSenderId: 79537064975,
|
|
39
|
-
appId: '1:79537064975:web:32f53119e9c8c6ee2a277a'
|
|
40
|
-
},
|
|
41
|
-
serverKey:
|
|
42
|
-
'AAAAEoTHTA8:APA91bGwt-4HT82Dfwf_VwbQaKT0_qHd0Y3tuW41udjWz5Lz0Ko0mEMD6WbHHSILvQpa6yuoGGKCMsrU7VW2qWRrUm3CYpyG9oSwshNm1tIhljAnOuUfwHCoawbVLwf9qlWpHt4dwCoc'
|
|
43
|
-
},
|
|
44
|
-
vapidKey: {
|
|
45
|
-
subject: 'mailto:heartyoh@hatiolab.com',
|
|
46
|
-
publicKey: 'BAkVkITsCXBIsYL1yeaBmx5_dn57we-ZXMjirPPHzC2dan82cdEnAio_53PQ-1_w3ykWCBPrrFAWQ_d9N4cFF0o',
|
|
47
|
-
privateKey: '4pmlt3Wk019u7nqU3Q_oGZE6LbUDjjf8DpmAcn9-iss'
|
|
48
|
-
}
|
|
53
|
+
password: {
|
|
54
|
+
lowerCase: true,
|
|
55
|
+
upperCase: false,
|
|
56
|
+
digit: false,
|
|
57
|
+
specialCharacter: false,
|
|
58
|
+
allowRepeat: true,
|
|
59
|
+
useTightPattern: false,
|
|
60
|
+
useLoosePattern: true,
|
|
61
|
+
tightCharacterLength: 4,
|
|
62
|
+
looseCharacterLength: 4,
|
|
63
|
+
history: 2
|
|
49
64
|
},
|
|
50
|
-
|
|
65
|
+
sftpFileStorage: {
|
|
66
|
+
type: 's3',
|
|
67
|
+
accessKeyId: 'AKIAUQEOPWEJKL43OMZA',
|
|
68
|
+
secretAccessKey: 'OG2qS0Usg4wyjPWbfv1ahPZzP80/w8z4i8MYHl+e',
|
|
69
|
+
bucketName: 'operato-sftp'
|
|
70
|
+
},
|
|
71
|
+
// storage: {
|
|
72
|
+
// type: 's3',
|
|
73
|
+
// accessKeyId: 'AKIAUQEOPWEJCDH6AR5H',
|
|
74
|
+
// secretAccessKey: 'AuDAgmODf9EJNB24OveRhTSLV/OJy6IFFoRxe8k2',
|
|
75
|
+
// bucketName: 'opa-one',
|
|
76
|
+
// region: 'ap-southeast-1'
|
|
77
|
+
// },
|
|
78
|
+
uploads: 'uploads',
|
|
79
|
+
attachmentsPath: 'attachments',
|
|
51
80
|
SECRET: '0xD58F835B69D207A76CC5F84a70a1D0d4C79dfC95',
|
|
52
|
-
|
|
81
|
+
logger: {
|
|
82
|
+
file: {
|
|
83
|
+
filename: 'logs/application-%DATE%.log',
|
|
84
|
+
datePattern: 'YYYY-MM-DD-HH',
|
|
85
|
+
zippedArchive: true,
|
|
86
|
+
maxSize: '200m',
|
|
87
|
+
maxFiles: '1m',
|
|
88
|
+
level: 'info'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
53
91
|
email: {
|
|
54
92
|
host: 'smtp.office365.com',
|
|
55
93
|
port: 587,
|
|
56
94
|
secure: false, // true for 465, false for other ports
|
|
57
95
|
auth: {
|
|
58
|
-
user: '
|
|
96
|
+
user: 'noreply@hatiolab.com', // generated ethereal user
|
|
59
97
|
pass: 'h@ti0LAB1008' // generated ethereal password
|
|
60
98
|
},
|
|
61
99
|
secureConnection: false,
|
|
62
100
|
tls: {
|
|
63
101
|
ciphers: 'SSLv3'
|
|
64
|
-
}
|
|
65
|
-
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
sender: 'noreply@hatiolab.com',
|
|
105
|
+
notification: {
|
|
106
|
+
// fcm: {
|
|
107
|
+
// serviceAccount: {
|
|
108
|
+
// project_id: 'operato',
|
|
109
|
+
// private_key:
|
|
110
|
+
// '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDYNOfyNjPMSeG9\nzU1qs0cpVK5cVfadcUaw5g+hkQZMOMlAA7uqW2eX4vkayj7MzbYUayH+sei8044Q\nJIyl6f26dNX1VT3UgTmSmCS0v48EBEZHCgusrUGFjduLRN6OS6uvrXW1xKA18k9q\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LeLu+VpFjZMzQrjyl6RIWbyTExEc84rVWfpQYAu3qIGOQKBgAFr\nXatEk7TdAtRNSPflTfu/rTAaSeKROjQBkvBiU8x4US1YpOBDBxUUyAtG8wKh5FHC\nfnsaGq+fM3KXJVv2R6J62mXQOfg4xyDLpWlwcBK4aSBBMoiBcsjouqSlZQlqMpdf\nZBgixqHe6U8BsFJg/6ZxC0y+e3AIss4Bo4/lb+1lAoGAFOexvaBh21K6W3inmRW4\nLlkVYJaBJ20OwokXg5aXjBiHxqmk7VLAuFbkpb5LOKH2xPILRQ0OEkn51yVymS3T\n9lLpHOFTQXt5tF2/F7NW7kaQJNlLr/h5jPi3O9XHeFmuaN2z150ZB6zzgjeGKzr8\ni+1fgTsRfDtNw8xkSH9qL1Y=\n-----END PRIVATE KEY-----\n',
|
|
111
|
+
// client_email: 'firebase-adminsdk-xmm2e@operato.iam.gserviceaccount.com'
|
|
112
|
+
// },
|
|
113
|
+
// appConfig: {
|
|
114
|
+
// apiKey: 'AIzaSyDdTM2BTLHSt2LNS0G5QB8G0i4KBXFiG7U',
|
|
115
|
+
// projectId: 'operato',
|
|
116
|
+
// messagingSenderId: 79537064975,
|
|
117
|
+
// appId: '1:79537064975:web:32f53119e9c8c6ee2a277a'
|
|
118
|
+
// },
|
|
119
|
+
// serverKey:
|
|
120
|
+
// 'AAAAEoTHTA8:APA91bGwt-4HT82Dfwf_VwbQaKT0_qHd0Y3tuW41udjWz5Lz0Ko0mEMD6WbHHSILvQpa6yuoGGKCMsrU7VW2qWRrUm3CYpyG9oSwshNm1tIhljAnOuUfwHCoawbVLwf9qlWpHt4dwCoc'
|
|
121
|
+
// },
|
|
122
|
+
// vapidKey: {
|
|
123
|
+
// subject: 'mailto:heartyoh@hatiolab.com',
|
|
124
|
+
// publicKey: 'BAkVkITsCXBIsYL1yeaBmx5_dn57we-ZXMjirPPHzC2dan82cdEnAio_53PQ-1_w3ykWCBPrrFAWQ_d9N4cFF0o',
|
|
125
|
+
// privateKey: '4pmlt3Wk019u7nqU3Q_oGZE6LbUDjjf8DpmAcn9-iss'
|
|
126
|
+
// }
|
|
66
127
|
},
|
|
67
|
-
awsSesEmail: 'support@hatio.asia',
|
|
68
|
-
attachmentsPath: 'attachment',
|
|
69
128
|
fulfillmentIntegrationOperato: {
|
|
70
|
-
host: 'operato.com:3000',
|
|
129
|
+
host: 'operato-h.com:3000',
|
|
71
130
|
protocol: 'http',
|
|
72
131
|
platform: 'operato',
|
|
73
132
|
application: 'Operato MMS',
|
|
74
133
|
appKey: 'a9bf751e622bf146662b240d58971051',
|
|
75
134
|
appSecret: '1c385935dc131c4b902b9bbf6a4798af',
|
|
76
|
-
|
|
77
|
-
callback: 'http://operato.com:9000/callback-operato'
|
|
78
|
-
},
|
|
79
|
-
fulfillmentIntegrationOperatoSftp: {
|
|
80
|
-
host: 'operato.com:3000',
|
|
81
|
-
protocol: 'http',
|
|
82
|
-
platform: 'operato',
|
|
83
|
-
application: 'Operato SFTP',
|
|
84
|
-
appKey: 'd3ebaf18121947931b5902d78adc9a98',
|
|
85
|
-
appSecret: '41e5591dd6597a75ae5d54603494525b',
|
|
86
|
-
type: 'SFTP',
|
|
87
|
-
callback: 'http://operato.com:9000/callback-operato'
|
|
135
|
+
callback: 'http://operato-retail.com:5000/callback-operato'
|
|
88
136
|
},
|
|
89
137
|
marketplaceIntegrationShopee: {
|
|
90
138
|
platform: 'shopee',
|
|
91
139
|
isUAT: false,
|
|
92
140
|
application: 'Operato MMS',
|
|
93
141
|
partnerId: 846025,
|
|
94
|
-
partnerKey: 'd34cfd85a603f196a0d74ebe08043280c1a27788bb36bdffd61e7e0bb1c90b64'
|
|
95
|
-
v2: true
|
|
142
|
+
partnerKey: 'd34cfd85a603f196a0d74ebe08043280c1a27788bb36bdffd61e7e0bb1c90b64'
|
|
96
143
|
},
|
|
97
|
-
// marketplaceIntegrationShopee: {
|
|
98
|
-
// platform: 'shopee',
|
|
99
|
-
// isUAT: false,
|
|
100
|
-
// application: 'Staging MMS',
|
|
101
|
-
// partnerId: 845525,
|
|
102
|
-
// partnerKey: '4a3f4214fd0f0bda970b342a99b6f8705fc7bacad2743cffa7ed67b79840665e'
|
|
103
|
-
// },
|
|
104
144
|
marketplaceIntegrationLazada: {
|
|
105
145
|
platform: 'lazada',
|
|
106
146
|
application: 'operato-mms',
|
|
@@ -108,19 +148,12 @@ module.exports = {
|
|
|
108
148
|
appSecret: 'HB3RTNEXHlVSlBr9SmWF8AjbSUT7a825',
|
|
109
149
|
callback: 'https://maybank.operato-m.com/lazada-callback'
|
|
110
150
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
apiKey: 'Et0KqtLvA6e92bDvOywy9eCCud4hpAal8akpqI90'
|
|
119
|
-
},
|
|
120
|
-
sftpFileStorage: {
|
|
121
|
-
type: 's3',
|
|
122
|
-
accessKeyId: 'AKIAUQEOPWEJKL43OMZA',
|
|
123
|
-
secretAccessKey: 'OG2qS0Usg4wyjPWbfv1ahPZzP80/w8z4i8MYHl+e',
|
|
124
|
-
bucketName: 'operato-sftp'
|
|
151
|
+
accountingIntegrationXero: {
|
|
152
|
+
platform: 'xero',
|
|
153
|
+
application: 'Operato WMS',
|
|
154
|
+
apiKey: '6B12D1AAC05347DC92159C2AEC812859',
|
|
155
|
+
apiSecret: 'T139_ItMjObC82mmy7iwnNflhd2iV0kUvDBj0P_201EmA7Sj',
|
|
156
|
+
callback: 'http://operato-h.com:3000/callback-xero',
|
|
157
|
+
hostname: 'http://operato-h.com:3000/'
|
|
125
158
|
}
|
|
126
159
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/routers/internal/index.ts"],"names":[],"mappings":";;AAAA,2BAAwB;AACxB,yBAAsB;AACtB,mBAAgB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const debug = require('debug')('things-factory:operato-hub:index');
|
|
18
|
+
__exportStar(require("./validation-middleware"), exports);
|
|
19
|
+
__exportStar(require("./logging-middleware"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/routers/internal/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,kCAAkC,CAAC,CAAA;AAElE,0DAAuC;AACvC,uDAAoC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loggingMiddleware = void 0;
|
|
4
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
5
|
+
// inserts payload log after successful endpoint request
|
|
6
|
+
async function loggingMiddleware(context, next) {
|
|
7
|
+
// wait for endpoint logic to complete
|
|
8
|
+
await next();
|
|
9
|
+
// name of requester's domain
|
|
10
|
+
const name = context.state.domain.name;
|
|
11
|
+
// endpoint that was queried
|
|
12
|
+
const endpoint = context.req._parsedUrl.pathname;
|
|
13
|
+
// request body and query
|
|
14
|
+
const request = {
|
|
15
|
+
query: context.query,
|
|
16
|
+
requestBody: context.request.body
|
|
17
|
+
};
|
|
18
|
+
// response
|
|
19
|
+
const response = context.body;
|
|
20
|
+
await (0, integration_base_1.createPayloadLog)(name, endpoint, request, response, context, integration_base_1.PayloadType.INGESTION);
|
|
21
|
+
}
|
|
22
|
+
exports.loggingMiddleware = loggingMiddleware;
|
|
23
|
+
//# sourceMappingURL=logging-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging-middleware.js","sourceRoot":"","sources":["../../../../server/routers/internal/middlewares/logging-middleware.ts"],"names":[],"mappings":";;;AAAA,uEAAgF;AAEhF,wDAAwD;AACjD,KAAK,UAAU,iBAAiB,CAAC,OAAO,EAAE,IAAI;IACnD,sCAAsC;IACtC,MAAM,IAAI,EAAE,CAAA;IAEZ,6BAA6B;IAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAA;IAEtC,4BAA4B;IAC5B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAA;IAEhD,yBAAyB;IACzB,MAAM,OAAO,GAAG;QACd,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;KAClC,CAAA;IAED,WAAW;IACX,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAA;IAE7B,MAAM,IAAA,mCAAgB,EAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,8BAAW,CAAC,SAAS,CAAC,CAAA;AAC3F,CAAC;AApBD,8CAoBC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validationMiddleware = void 0;
|
|
4
|
+
const error_util_1 = require("../utils/error-util");
|
|
5
|
+
const params_1 = require("../utils/params");
|
|
6
|
+
const debug = require('debug')('things-factory:operato-hub:validation-middleware');
|
|
7
|
+
let req;
|
|
8
|
+
async function validationMiddleware(context, next) {
|
|
9
|
+
var _a, _b, _c, _d, _e;
|
|
10
|
+
let path = context.req._parsedUrl.pathname;
|
|
11
|
+
let endpoint = path.substring(path.lastIndexOf('/') + 1);
|
|
12
|
+
let q = (_a = context === null || context === void 0 ? void 0 : context.request) === null || _a === void 0 ? void 0 : _a.query;
|
|
13
|
+
req = params_1.reqParams[endpoint];
|
|
14
|
+
// validate data key
|
|
15
|
+
try {
|
|
16
|
+
if (!((_c = (_b = context === null || context === void 0 ? void 0 : context.request) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.apiKey)) {
|
|
17
|
+
throw new error_util_1.ApiError('E03', 'apiKey');
|
|
18
|
+
}
|
|
19
|
+
if (context.method == 'POST' && !((_e = (_d = context === null || context === void 0 ? void 0 : context.request) === null || _d === void 0 ? void 0 : _d.body) === null || _e === void 0 ? void 0 : _e.data)) {
|
|
20
|
+
throw new error_util_1.ApiError('E03', 'data');
|
|
21
|
+
}
|
|
22
|
+
validateExpected(endpoint, context);
|
|
23
|
+
validateRequired(endpoint, context);
|
|
24
|
+
await next();
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
if (e instanceof error_util_1.ApiError)
|
|
28
|
+
(0, error_util_1.ApiErrorHandler)(context, e);
|
|
29
|
+
else
|
|
30
|
+
(0, error_util_1.throwInternalServerError)(context, e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.validationMiddleware = validationMiddleware;
|
|
34
|
+
function validateExpected(endpoint, context) {
|
|
35
|
+
let data = context.method == 'POST' ? context.request.body.data : context.request.query;
|
|
36
|
+
let expected = params_1.params[endpoint];
|
|
37
|
+
let result = context.method == 'POST' ? Object.keys(flatten(data)) : Object.keys(data);
|
|
38
|
+
for (let r of result) {
|
|
39
|
+
if (!expected.includes(r))
|
|
40
|
+
throw new error_util_1.ApiError('E02', r.toString());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function validateRequired(endpoint, context) {
|
|
44
|
+
let data;
|
|
45
|
+
if (context.method == 'GET') {
|
|
46
|
+
data = context.request.query;
|
|
47
|
+
let required = params_1.reqParams[endpoint];
|
|
48
|
+
let result = Object.keys(data);
|
|
49
|
+
if (required) {
|
|
50
|
+
for (let r of required) {
|
|
51
|
+
if (!result.includes(r))
|
|
52
|
+
throw new error_util_1.ApiError('E03', r.toString());
|
|
53
|
+
}
|
|
54
|
+
for (let r of result) {
|
|
55
|
+
if (data[r] == null || data[r] === '')
|
|
56
|
+
throw new error_util_1.ApiError('E01', r.toString());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
data = context.request.body.data;
|
|
62
|
+
if (data instanceof Array) {
|
|
63
|
+
for (let d of data) {
|
|
64
|
+
validateReq(d);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
validateReq(data);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function flatten(obj, path = '') {
|
|
73
|
+
if (!(obj instanceof Object))
|
|
74
|
+
return { [path.replace(/\.$/g, '')]: obj };
|
|
75
|
+
return Object.keys(obj).reduce((output, key) => {
|
|
76
|
+
return obj instanceof Array
|
|
77
|
+
? Object.assign(Object.assign({}, output), flatten(obj[key], path)) : Object.assign(Object.assign({}, output), flatten(obj[key], path + key + '.'));
|
|
78
|
+
}, {});
|
|
79
|
+
}
|
|
80
|
+
function validateReq(obj, path = []) {
|
|
81
|
+
let keys = Object.keys(obj);
|
|
82
|
+
let reqTemp = req;
|
|
83
|
+
let pathTemp = path.slice();
|
|
84
|
+
while (pathTemp.length > 0) {
|
|
85
|
+
reqTemp = reqTemp.find(e => e.name == pathTemp[0]).data;
|
|
86
|
+
pathTemp.shift();
|
|
87
|
+
}
|
|
88
|
+
for (let rule of reqTemp) {
|
|
89
|
+
if (rule.type == 'field') {
|
|
90
|
+
if (rule.required && !keys.includes(rule.name)) {
|
|
91
|
+
throw new error_util_1.ApiError('E03', rule.name);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
if (!obj.hasOwnProperty(rule.name) && rule.required) {
|
|
96
|
+
throw new error_util_1.ApiError('E03', rule.name);
|
|
97
|
+
}
|
|
98
|
+
if (obj[rule.name]) {
|
|
99
|
+
let arr = rule.type == 'array' ? obj[rule.name] : [obj[rule.name]];
|
|
100
|
+
for (let arrObj of arr) {
|
|
101
|
+
validateReq(arrObj, [...path, rule.name]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (rule.required && (obj[rule.name] == null || obj[rule.name] == undefined || obj[rule.name] === '')) {
|
|
106
|
+
throw new error_util_1.ApiError('E01', `${rule.name}: null`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=validation-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-middleware.js","sourceRoot":"","sources":["../../../../server/routers/internal/middlewares/validation-middleware.ts"],"names":[],"mappings":";;;AAAA,oDAAyF;AACzF,4CAAmD;AAEnD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,kDAAkD,CAAC,CAAA;AAElF,IAAI,GAAG,CAAA;AAEA,KAAK,UAAU,oBAAoB,CAAC,OAAO,EAAE,IAAI;;IACtD,IAAI,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAA;IAC1C,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACx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};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.powrupRouter = void 0;
|
|
7
|
+
const koa_router_1 = __importDefault(require("koa-router"));
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
10
|
+
const biz_base_1 = require("@things-factory/biz-base");
|
|
11
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
12
|
+
const shell_1 = require("@things-factory/shell");
|
|
13
|
+
const utils_1 = require("@things-factory/utils");
|
|
14
|
+
const generate_bizplace_domain_1 = require("../../controllers/bizplace-initializer/generate-bizplace-domain");
|
|
15
|
+
const validation_middleware_1 = require("./middlewares/validation-middleware");
|
|
16
|
+
const error_util_1 = require("./utils/error-util");
|
|
17
|
+
const debug = require('debug')('things-factory:integration-accounting:xilnex-router');
|
|
18
|
+
exports.powrupRouter = new koa_router_1.default();
|
|
19
|
+
exports.powrupRouter.post('/internal/account/create-user', validation_middleware_1.validationMiddleware, async (context, next) => {
|
|
20
|
+
try {
|
|
21
|
+
await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
|
22
|
+
const { body } = context.request;
|
|
23
|
+
await getIntegration(context, tx);
|
|
24
|
+
let user = (body === null || body === void 0 ? void 0 : body.data) || {};
|
|
25
|
+
const { email } = user;
|
|
26
|
+
user.email = email.trim();
|
|
27
|
+
const oldUser = await tx.getRepository(auth_base_1.User).findOne({ where: { email: user.email } });
|
|
28
|
+
if (oldUser) {
|
|
29
|
+
throw new error_util_1.ApiError('E04', context.t('error.x already exists in y', { x: context.t('field.user'), y: 'operato' }));
|
|
30
|
+
}
|
|
31
|
+
const salt = auth_base_1.User.generateSalt();
|
|
32
|
+
let createdUser = await tx.getRepository(auth_base_1.User).save(Object.assign(Object.assign({}, user), { userType: (user === null || user === void 0 ? void 0 : user.userType) || 'user', status: (user === null || user === void 0 ? void 0 : user.status) || 'inactive', salt, passwordUpdatedAt: new Date(), password: auth_base_1.User.encode(user.password, salt) }));
|
|
33
|
+
context.body = {
|
|
34
|
+
data: createdUser
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
if (e instanceof error_util_1.ApiError)
|
|
40
|
+
(0, error_util_1.ApiErrorHandler)(context, e);
|
|
41
|
+
else
|
|
42
|
+
(0, error_util_1.throwInternalServerError)(context, e);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
exports.powrupRouter.post('/internal/account/create-company', validation_middleware_1.validationMiddleware, async (context, next) => {
|
|
46
|
+
try {
|
|
47
|
+
await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
|
48
|
+
const { body } = context.request;
|
|
49
|
+
await getIntegration(context, tx);
|
|
50
|
+
const { name, description, brn, address, postalCode, type, status } = body.data;
|
|
51
|
+
const subdomain = (0, utils_1.slugger)(name);
|
|
52
|
+
//check for existing company
|
|
53
|
+
const oldCompany = await tx.getRepository(biz_base_1.Company).findOne({
|
|
54
|
+
where: {
|
|
55
|
+
name
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (oldCompany) {
|
|
59
|
+
throw new error_util_1.ApiError('E04', `${name} is duplicated`);
|
|
60
|
+
}
|
|
61
|
+
const oldDomain = await tx.getRepository(shell_1.Domain).findOne({
|
|
62
|
+
where: {
|
|
63
|
+
subdomain
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (oldDomain) {
|
|
67
|
+
throw new error_util_1.ApiError('E04', `${subdomain} is duplicated`);
|
|
68
|
+
}
|
|
69
|
+
// create company
|
|
70
|
+
const domain = await tx.getRepository(shell_1.Domain).save({
|
|
71
|
+
subdomain,
|
|
72
|
+
name,
|
|
73
|
+
extType: 'company'
|
|
74
|
+
});
|
|
75
|
+
const company = await tx.getRepository(biz_base_1.Company).save({
|
|
76
|
+
name,
|
|
77
|
+
description,
|
|
78
|
+
brn,
|
|
79
|
+
address,
|
|
80
|
+
postalCode,
|
|
81
|
+
type,
|
|
82
|
+
status,
|
|
83
|
+
domain
|
|
84
|
+
});
|
|
85
|
+
context.body = {
|
|
86
|
+
data: company
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
if (e instanceof error_util_1.ApiError)
|
|
92
|
+
(0, error_util_1.ApiErrorHandler)(context, e);
|
|
93
|
+
else
|
|
94
|
+
(0, error_util_1.throwInternalServerError)(context, e);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
exports.powrupRouter.post('/internal/account/create-bizplace', validation_middleware_1.validationMiddleware, async (context, next) => {
|
|
98
|
+
try {
|
|
99
|
+
await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
|
100
|
+
const { body } = context.request;
|
|
101
|
+
await getIntegration(context, tx);
|
|
102
|
+
const { data: bizplace } = body;
|
|
103
|
+
const company = await tx.getRepository(biz_base_1.Company).findOne({ where: { id: bizplace.companyOriginId } });
|
|
104
|
+
const oldBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
|
|
105
|
+
where: {
|
|
106
|
+
name: (0, typeorm_1.Raw)(alias => `LOWER(${alias}) LIKE '${bizplace.name.toLowerCase()}'`)
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
if (oldBizplace) {
|
|
110
|
+
throw new error_util_1.ApiError('E04', `${bizplace.name} is duplicated`);
|
|
111
|
+
}
|
|
112
|
+
let createdBizplace = await tx.getRepository(biz_base_1.Bizplace).save({
|
|
113
|
+
name: bizplace.name,
|
|
114
|
+
description: bizplace.description,
|
|
115
|
+
address: bizplace.address,
|
|
116
|
+
postalCode: bizplace.postalCode,
|
|
117
|
+
latlng: bizplace.latlng,
|
|
118
|
+
status: bizplace.status,
|
|
119
|
+
company,
|
|
120
|
+
updater: context.state.user,
|
|
121
|
+
creator: context.state.user
|
|
122
|
+
});
|
|
123
|
+
await (0, generate_bizplace_domain_1.generateBizplaceDomain)(bizplace.id, null, tx);
|
|
124
|
+
context.body = {
|
|
125
|
+
data: createdBizplace
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
if (e instanceof error_util_1.ApiError)
|
|
131
|
+
(0, error_util_1.ApiErrorHandler)(context, e);
|
|
132
|
+
else
|
|
133
|
+
(0, error_util_1.throwInternalServerError)(context, e);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
exports.powrupRouter.post('/internal/account/create-partner', validation_middleware_1.validationMiddleware, async (context, next) => {
|
|
137
|
+
// try {
|
|
138
|
+
// await getConnection().transaction(async (tx: EntityManager) => {
|
|
139
|
+
// const { body } = context.request
|
|
140
|
+
// await getIntegration(context, tx)
|
|
141
|
+
// const { data: partner } = body
|
|
142
|
+
// const company: Company = await tx.getRepository(Company).findOne({ where: { id: bizplace.companyOriginId } })
|
|
143
|
+
// const oldBizplace = await tx.getRepository(Bizplace).findOne({
|
|
144
|
+
// where: {
|
|
145
|
+
// name: Raw(alias => `LOWER(${alias}) LIKE '${bizplace.name.toLowerCase()}'`)
|
|
146
|
+
// }
|
|
147
|
+
// })
|
|
148
|
+
// if (oldBizplace) {
|
|
149
|
+
// throw new ApiError('E04', `${bizplace.name} is duplicated`)
|
|
150
|
+
// }
|
|
151
|
+
// let createdBizplace: Bizplace = await tx.getRepository(Bizplace).save({
|
|
152
|
+
// name: bizplace.name,
|
|
153
|
+
// description: bizplace.description,
|
|
154
|
+
// address: bizplace.address,
|
|
155
|
+
// postalCode: bizplace.postalCode,
|
|
156
|
+
// latlng: bizplace.latlng,
|
|
157
|
+
// status: bizplace.status,
|
|
158
|
+
// company,
|
|
159
|
+
// updater: context.state.user,
|
|
160
|
+
// creator: context.state.user
|
|
161
|
+
// })
|
|
162
|
+
// await generateBizplaceDomain(bizplace.id, null, tx)
|
|
163
|
+
// context.body = {
|
|
164
|
+
// data: createdBizplace
|
|
165
|
+
// }
|
|
166
|
+
// })
|
|
167
|
+
// } catch (e) {
|
|
168
|
+
// if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
169
|
+
// else throwInternalServerError(context, e)
|
|
170
|
+
// }
|
|
171
|
+
});
|
|
172
|
+
async function getIntegration(context, tx) {
|
|
173
|
+
const integration = await tx.getRepository(integration_base_1.Integration).findOne({
|
|
174
|
+
where: { name: context.request.body.apiKey }
|
|
175
|
+
});
|
|
176
|
+
if (integration) {
|
|
177
|
+
context.state.integration = integration;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
throw new error_util_1.ApiError('E04', 'apiKey');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=powrup-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"powrup-router.js","sourceRoot":"","sources":["../../../server/routers/internal/powrup-router.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA+B;AAC/B,qCAA2D;AAE3D,yDAAyD;AACzD,uDAA4D;AAC5D,uEAA8D;AAC9D,iDAA8C;AAC9C,iDAA+C;AAE/C,8GAAwG;AACxG,+EAA0E;AAC1E,mDAAwF;AAExF,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,qDAAqD,CAAC,CAAA;AAExE,QAAA,YAAY,GAAG,IAAI,oBAAM,EAAE,CAAA;AAExC,oBAAY,CAAC,IAAI,CAAC,+BAA+B,EAAE,4CAAoB,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IAC/F,IAAI;QACF,MAAM,IAAA,uBAAa,GAAE,CAAC,WAAW,CAAC,KAAK,EAAE,EAAiB,EAAE,EAAE;YAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAA;YAEhC,MAAM,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;YAEjC,IAAI,IAAI,GAAY,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,KAAI,EAAE,CAAA;YACpC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAA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9E,6BAA6B;IAC7B,2CAA2C;IAC3C,mCAAmC;IACnC,yCAAyC;IACzC,iCAAiC;IACjC,iCAAiC;IACjC,iBAAiB;IACjB,qCAAqC;IACrC,oCAAoC;IACpC,SAAS;IACT,0DAA0D;IAC1D,uBAAuB;IACvB,8BAA8B;IAC9B,QAAQ;IACR,OAAO;IACP,gBAAgB;IAChB,2DAA2D;IAC3D,8CAA8C;IAC9C,IAAI;AACN,CAAC,CAAC,CAAA;AAEF,KAAK,UAAU,cAAc,CAAC,OAAO,EAAE,EAAE;IACvC,MAAM,WAAW,GAAgB,MAAM,EAAE,CAAC,aAAa,CAAC,8BAAW,CAAC,CAAC,OAAO,CAAC;QAC3E,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;KAC7C,CAAC,CAAA;IAEF,IAAI,WAAW,EAAE;QACf,OAAO,CAAC,KAAK,CAAC,WAAW,GAAG,WAAW,CAAA;KACxC;SAAM;QACL,MAAM,IAAI,qBAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;KACpC;AACH,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwInternalServerError = exports.ApiErrorHandler = exports.ApiError = void 0;
|
|
4
|
+
// custom error class used when throwing errors for API V1
|
|
5
|
+
class ApiError extends Error {
|
|
6
|
+
constructor(responseCode, message, ...params) {
|
|
7
|
+
super(...params);
|
|
8
|
+
this.responseCode = responseCode;
|
|
9
|
+
this.name = 'ApiError';
|
|
10
|
+
switch (responseCode) {
|
|
11
|
+
case 'E01':
|
|
12
|
+
this.status = 400;
|
|
13
|
+
this.message = 'Invalid parameter values';
|
|
14
|
+
this.details = message;
|
|
15
|
+
break;
|
|
16
|
+
case 'E02':
|
|
17
|
+
this.status = 400;
|
|
18
|
+
this.message = 'Unexpected parameters';
|
|
19
|
+
this.details = message;
|
|
20
|
+
break;
|
|
21
|
+
case 'E03':
|
|
22
|
+
this.status = 400;
|
|
23
|
+
this.message = 'Missing parameters';
|
|
24
|
+
this.details = message;
|
|
25
|
+
break;
|
|
26
|
+
case 'E04':
|
|
27
|
+
this.status = 404;
|
|
28
|
+
this.message = 'Resource not found';
|
|
29
|
+
this.details = message;
|
|
30
|
+
break;
|
|
31
|
+
case 'E05':
|
|
32
|
+
this.status = 409;
|
|
33
|
+
this.message = 'Duplicate entry';
|
|
34
|
+
this.details = message;
|
|
35
|
+
break;
|
|
36
|
+
case 'E06':
|
|
37
|
+
this.status = 500;
|
|
38
|
+
this.message = 'Internal server error';
|
|
39
|
+
this.details = message;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ApiError = ApiError;
|
|
45
|
+
// used in catch block to give an error response
|
|
46
|
+
function ApiErrorHandler(context, e) {
|
|
47
|
+
context.type = 'application/json';
|
|
48
|
+
context.status = e.status;
|
|
49
|
+
context.body = {
|
|
50
|
+
error: {
|
|
51
|
+
responseCode: e.responseCode,
|
|
52
|
+
message: e.message,
|
|
53
|
+
details: e.details
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.ApiErrorHandler = ApiErrorHandler;
|
|
58
|
+
// used in catch block for all errors that are not ApiError
|
|
59
|
+
function throwInternalServerError(context, e) {
|
|
60
|
+
context.type = 'application/json';
|
|
61
|
+
context.status = 500;
|
|
62
|
+
context.body = {
|
|
63
|
+
error: {
|
|
64
|
+
responseCode: 'E06',
|
|
65
|
+
message: 'Internal Server Error',
|
|
66
|
+
details: e.message
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.throwInternalServerError = throwInternalServerError;
|
|
71
|
+
//# sourceMappingURL=error-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-util.js","sourceRoot":"","sources":["../../../../server/routers/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CAAA;gBACtB,MAAK;SACR;IACH,CAAC;CACF;AA1CD,4BA0CC;AAED,gDAAgD;AAChD,SAAgB,eAAe,CAAC,OAAO,EAAE,CAAC;IACxC,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAA;IACjC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IACzB,OAAO,CAAC,IAAI,GAAG;QACb,KAAK,EAAE;YACL,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB;KACF,CAAA;AACH,CAAC;AAVD,0CAUC;AAED,2DAA2D;AAC3D,SAAgB,wBAAwB,CAAC,OAAO,EAAE,CAAC;IACjD,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAA;IACjC,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;IACpB,OAAO,CAAC,IAAI,GAAG;QACb,KAAK,EAAE;YACL,YAAY,EAAE,KAAK;YACnB,OAAO,EAAE,uBAAuB;YAChC,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB;KACF,CAAA;AACH,CAAC;AAVD,4DAUC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reqParams = exports.params = void 0;
|
|
4
|
+
exports.params = {
|
|
5
|
+
'create-user': ['userOriginId', 'name', 'description', 'email', 'password', 'status']
|
|
6
|
+
};
|
|
7
|
+
exports.reqParams = {
|
|
8
|
+
'create-user': [
|
|
9
|
+
{
|
|
10
|
+
name: 'userOriginId',
|
|
11
|
+
required: true,
|
|
12
|
+
type: 'field'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'name',
|
|
16
|
+
required: true,
|
|
17
|
+
type: 'field'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'email',
|
|
21
|
+
required: true,
|
|
22
|
+
type: 'field'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'password',
|
|
26
|
+
required: true,
|
|
27
|
+
type: 'field'
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../../../server/routers/internal/utils/params.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG;IACpB,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC;CACtF,CAAA;AAEY,QAAA,SAAS,GAAG;IACvB,aAAa,EAAE;QACb;YACE,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,OAAO;SACd;KACF;CACF,CAAA"}
|
package/dist-server/routes.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const business_middleware_1 = require("./middlewares/business-middleware");
|
|
4
4
|
const business_1 = require("./routers/business");
|
|
5
|
+
const powrup_router_1 = require("./routers/internal/powrup-router");
|
|
5
6
|
const xilnex_router_1 = require("./routers/xilnex-router");
|
|
6
7
|
const debug = require('debug')('things-factory:operato-hub:routes');
|
|
7
8
|
process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
|
|
8
|
-
globalPublicRouter.use(xilnex_router_1.xilnexRouter.routes(), xilnex_router_1.xilnexRouter.allowedMethods());
|
|
9
|
+
globalPublicRouter.use(xilnex_router_1.xilnexRouter.routes(), xilnex_router_1.xilnexRouter.allowedMethods(), powrup_router_1.powrupRouter.routes(), powrup_router_1.powrupRouter.allowedMethods());
|
|
9
10
|
});
|
|
10
11
|
process.on('bootstrap-module-global-private-route', (app, globalPrivateRouter) => {
|
|
11
12
|
globalPrivateRouter.use('/business-register', business_1.businessRegisterRouter.routes(), business_1.businessRegisterRouter.allowedMethods());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,2EAAsE;AACtE,iDAAmF;AACnF,2DAAsD;AAEtD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mCAAmC,CAAC,CAAA;AAEnE,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF,kBAAkB,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,2EAAsE;AACtE,iDAAmF;AACnF,oEAA+D;AAC/D,2DAAsD;AAEtD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mCAAmC,CAAC,CAAA;AAEnE,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF,kBAAkB,CAAC,GAAG,CACpB,4BAAY,CAAC,MAAM,EAAE,EACrB,4BAAY,CAAC,cAAc,EAAE,EAC7B,4BAAY,CAAC,MAAM,EAAE,EACrB,4BAAY,CAAC,cAAc,EAAE,CAC9B,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF,mBAAmB,CAAC,GAAG,CACrB,oBAAoB,EACpB,iCAAsB,CAAC,MAAM,EAAE,EAC/B,iCAAsB,CAAC,cAAc,EAAE,CACxC,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF,mGAAmG;IACnG,kBAAkB,CAAC,GAAG,CAAC,wCAAkB,CAAC,CAAA;AAC5C,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF,mBAAmB,CAAC,GAAG,CAAC,wCAAkB,CAAC,CAAA;IAE3C,8CAA8C;IAC9C,mBAAmB,CAAC,GAAG,CACrB,oBAAoB,EACpB,iCAAsB,CAAC,MAAM,EAAE,EAC/B,iCAAsB,CAAC,cAAc,EAAE,CACxC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/operato-hub",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.219",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -77,21 +77,21 @@
|
|
|
77
77
|
"@things-factory/i18n-base": "^4.3.179",
|
|
78
78
|
"@things-factory/import-ui": "^4.3.179",
|
|
79
79
|
"@things-factory/import-ui-excel": "^4.3.179",
|
|
80
|
-
"@things-factory/integration-accounting": "^4.3.
|
|
81
|
-
"@things-factory/integration-fulfillment": "^4.3.
|
|
82
|
-
"@things-factory/integration-lmd": "^4.3.
|
|
83
|
-
"@things-factory/integration-marketplace": "^4.3.
|
|
84
|
-
"@things-factory/integration-pos": "^4.3.
|
|
85
|
-
"@things-factory/integration-sellercraft": "^4.3.
|
|
86
|
-
"@things-factory/integration-sftp": "^4.3.
|
|
80
|
+
"@things-factory/integration-accounting": "^4.3.219",
|
|
81
|
+
"@things-factory/integration-fulfillment": "^4.3.219",
|
|
82
|
+
"@things-factory/integration-lmd": "^4.3.219",
|
|
83
|
+
"@things-factory/integration-marketplace": "^4.3.219",
|
|
84
|
+
"@things-factory/integration-pos": "^4.3.219",
|
|
85
|
+
"@things-factory/integration-sellercraft": "^4.3.219",
|
|
86
|
+
"@things-factory/integration-sftp": "^4.3.219",
|
|
87
87
|
"@things-factory/lite-menu": "^4.3.186",
|
|
88
|
-
"@things-factory/marketplace-base": "^4.3.
|
|
88
|
+
"@things-factory/marketplace-base": "^4.3.219",
|
|
89
89
|
"@things-factory/more-ui": "^4.3.179",
|
|
90
90
|
"@things-factory/notification": "^4.3.186",
|
|
91
91
|
"@things-factory/pdf": "^4.3.159",
|
|
92
92
|
"@things-factory/product-ui": "^4.3.204",
|
|
93
93
|
"@things-factory/resource-ui": "^4.3.179",
|
|
94
|
-
"@things-factory/sales-base": "^4.3.
|
|
94
|
+
"@things-factory/sales-base": "^4.3.219",
|
|
95
95
|
"@things-factory/scene-data-transform": "^4.3.159",
|
|
96
96
|
"@things-factory/scene-excel": "^4.3.159",
|
|
97
97
|
"@things-factory/scene-firebase": "^4.3.159",
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
"@things-factory/setting-ui": "^4.3.186",
|
|
107
107
|
"@things-factory/shell": "^4.3.179",
|
|
108
108
|
"@things-factory/system-ui": "^4.3.179",
|
|
109
|
-
"@things-factory/warehouse-base": "^4.3.
|
|
110
|
-
"@things-factory/worksheet-base": "^4.3.
|
|
109
|
+
"@things-factory/warehouse-base": "^4.3.219",
|
|
110
|
+
"@things-factory/worksheet-base": "^4.3.219",
|
|
111
111
|
"cron-parser": "^4.7.0",
|
|
112
112
|
"koa2-swagger-ui": "^5.0.2",
|
|
113
113
|
"swagger-jsdoc": "^5.0.0",
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"resolutions": {
|
|
120
120
|
"core-js": "^3.16.0"
|
|
121
121
|
},
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "b6b100adf5b9d8066b0b063b5e4bd804d4782880"
|
|
123
123
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createPayloadLog, PayloadType } from '@things-factory/integration-base'
|
|
2
|
+
|
|
3
|
+
// inserts payload log after successful endpoint request
|
|
4
|
+
export async function loggingMiddleware(context, next) {
|
|
5
|
+
// wait for endpoint logic to complete
|
|
6
|
+
await next()
|
|
7
|
+
|
|
8
|
+
// name of requester's domain
|
|
9
|
+
const name = context.state.domain.name
|
|
10
|
+
|
|
11
|
+
// endpoint that was queried
|
|
12
|
+
const endpoint = context.req._parsedUrl.pathname
|
|
13
|
+
|
|
14
|
+
// request body and query
|
|
15
|
+
const request = {
|
|
16
|
+
query: context.query,
|
|
17
|
+
requestBody: context.request.body
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// response
|
|
21
|
+
const response = context.body
|
|
22
|
+
|
|
23
|
+
await createPayloadLog(name, endpoint, request, response, context, PayloadType.INGESTION)
|
|
24
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ApiError, ApiErrorHandler, throwInternalServerError } from '../utils/error-util'
|
|
2
|
+
import { params, reqParams } from '../utils/params'
|
|
3
|
+
|
|
4
|
+
const debug = require('debug')('things-factory:operato-hub:validation-middleware')
|
|
5
|
+
|
|
6
|
+
let req
|
|
7
|
+
|
|
8
|
+
export async function validationMiddleware(context, next) {
|
|
9
|
+
let path = context.req._parsedUrl.pathname
|
|
10
|
+
let endpoint = path.substring(path.lastIndexOf('/') + 1)
|
|
11
|
+
let q = context?.request?.query
|
|
12
|
+
req = reqParams[endpoint]
|
|
13
|
+
|
|
14
|
+
// validate data key
|
|
15
|
+
try {
|
|
16
|
+
if (!context?.request?.body?.apiKey) {
|
|
17
|
+
throw new ApiError('E03', 'apiKey')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (context.method == 'POST' && !context?.request?.body?.data) {
|
|
21
|
+
throw new ApiError('E03', 'data')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
validateExpected(endpoint, context)
|
|
25
|
+
validateRequired(endpoint, context)
|
|
26
|
+
|
|
27
|
+
await next()
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
30
|
+
else throwInternalServerError(context, e)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function validateExpected(endpoint, context) {
|
|
35
|
+
let data = context.method == 'POST' ? context.request.body.data : context.request.query
|
|
36
|
+
let expected = params[endpoint]
|
|
37
|
+
let result = context.method == 'POST' ? Object.keys(flatten(data)) : Object.keys(data)
|
|
38
|
+
for (let r of result) {
|
|
39
|
+
if (!expected.includes(r)) throw new ApiError('E02', r.toString())
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function validateRequired(endpoint, context) {
|
|
44
|
+
let data
|
|
45
|
+
if (context.method == 'GET') {
|
|
46
|
+
data = context.request.query
|
|
47
|
+
let required = reqParams[endpoint]
|
|
48
|
+
let result = Object.keys(data)
|
|
49
|
+
if (required) {
|
|
50
|
+
for (let r of required) {
|
|
51
|
+
if (!result.includes(r)) throw new ApiError('E03', r.toString())
|
|
52
|
+
}
|
|
53
|
+
for (let r of result) {
|
|
54
|
+
if (data[r] == null || data[r] === '') throw new ApiError('E01', r.toString())
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
data = context.request.body.data
|
|
59
|
+
if (data instanceof Array) {
|
|
60
|
+
for (let d of data) {
|
|
61
|
+
validateReq(d)
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
validateReq(data)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function flatten(obj, path = '') {
|
|
70
|
+
if (!(obj instanceof Object)) return { [path.replace(/\.$/g, '')]: obj }
|
|
71
|
+
|
|
72
|
+
return Object.keys(obj).reduce((output, key) => {
|
|
73
|
+
return obj instanceof Array
|
|
74
|
+
? { ...output, ...flatten(obj[key], path) }
|
|
75
|
+
: { ...output, ...flatten(obj[key], path + key + '.') }
|
|
76
|
+
}, {})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function validateReq(obj, path = []) {
|
|
80
|
+
let keys = Object.keys(obj)
|
|
81
|
+
let reqTemp = req
|
|
82
|
+
let pathTemp = path.slice()
|
|
83
|
+
while (pathTemp.length > 0) {
|
|
84
|
+
reqTemp = reqTemp.find(e => e.name == pathTemp[0]).data
|
|
85
|
+
pathTemp.shift()
|
|
86
|
+
}
|
|
87
|
+
for (let rule of reqTemp) {
|
|
88
|
+
if (rule.type == 'field') {
|
|
89
|
+
if (rule.required && !keys.includes(rule.name)) {
|
|
90
|
+
throw new ApiError('E03', rule.name)
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (!obj.hasOwnProperty(rule.name) && rule.required) {
|
|
94
|
+
throw new ApiError('E03', rule.name)
|
|
95
|
+
}
|
|
96
|
+
if (obj[rule.name]) {
|
|
97
|
+
let arr = rule.type == 'array' ? obj[rule.name] : [obj[rule.name]]
|
|
98
|
+
for (let arrObj of arr) {
|
|
99
|
+
validateReq(arrObj, [...path, rule.name])
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (rule.required && (obj[rule.name] == null || obj[rule.name] == undefined || obj[rule.name] === '')) {
|
|
104
|
+
throw new ApiError('E01', `${rule.name}: null`)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import Router from 'koa-router'
|
|
2
|
+
import { EntityManager, getConnection, Raw } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { NewUser, User } from '@things-factory/auth-base'
|
|
5
|
+
import { Bizplace, Company } from '@things-factory/biz-base'
|
|
6
|
+
import { Integration } from '@things-factory/integration-base'
|
|
7
|
+
import { Domain } from '@things-factory/shell'
|
|
8
|
+
import { slugger } from '@things-factory/utils'
|
|
9
|
+
|
|
10
|
+
import { generateBizplaceDomain } from '../../controllers/bizplace-initializer/generate-bizplace-domain'
|
|
11
|
+
import { validationMiddleware } from './middlewares/validation-middleware'
|
|
12
|
+
import { ApiError, ApiErrorHandler, throwInternalServerError } from './utils/error-util'
|
|
13
|
+
|
|
14
|
+
const debug = require('debug')('things-factory:integration-accounting:xilnex-router')
|
|
15
|
+
|
|
16
|
+
export const powrupRouter = new Router()
|
|
17
|
+
|
|
18
|
+
powrupRouter.post('/internal/account/create-user', validationMiddleware, async (context, next) => {
|
|
19
|
+
try {
|
|
20
|
+
await getConnection().transaction(async (tx: EntityManager) => {
|
|
21
|
+
const { body } = context.request
|
|
22
|
+
|
|
23
|
+
await getIntegration(context, tx)
|
|
24
|
+
|
|
25
|
+
let user: NewUser = body?.data || {}
|
|
26
|
+
const { email } = user
|
|
27
|
+
user.email = email.trim()
|
|
28
|
+
|
|
29
|
+
const oldUser: User = await tx.getRepository(User).findOne({ where: { email: user.email } })
|
|
30
|
+
if (oldUser) {
|
|
31
|
+
throw new ApiError(
|
|
32
|
+
'E04',
|
|
33
|
+
context.t('error.x already exists in y', { x: context.t('field.user'), y: 'operato' })
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const salt = User.generateSalt()
|
|
38
|
+
|
|
39
|
+
let createdUser: User = await tx.getRepository(User).save({
|
|
40
|
+
...user,
|
|
41
|
+
userType: user?.userType || 'user',
|
|
42
|
+
status: user?.status || 'inactive',
|
|
43
|
+
salt,
|
|
44
|
+
passwordUpdatedAt: new Date(),
|
|
45
|
+
password: User.encode(user.password, salt)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
context.body = {
|
|
49
|
+
data: createdUser
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
54
|
+
else throwInternalServerError(context, e)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
powrupRouter.post('/internal/account/create-company', validationMiddleware, async (context, next) => {
|
|
59
|
+
try {
|
|
60
|
+
await getConnection().transaction(async (tx: EntityManager) => {
|
|
61
|
+
const { body } = context.request
|
|
62
|
+
|
|
63
|
+
await getIntegration(context, tx)
|
|
64
|
+
|
|
65
|
+
const { name, description, brn, address, postalCode, type, status } = body.data
|
|
66
|
+
|
|
67
|
+
const subdomain = slugger(name)
|
|
68
|
+
|
|
69
|
+
//check for existing company
|
|
70
|
+
const oldCompany = await tx.getRepository(Company).findOne({
|
|
71
|
+
where: {
|
|
72
|
+
name
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
if (oldCompany) {
|
|
77
|
+
throw new ApiError('E04', `${name} is duplicated`)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const oldDomain = await tx.getRepository(Domain).findOne({
|
|
81
|
+
where: {
|
|
82
|
+
subdomain
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
if (oldDomain) {
|
|
87
|
+
throw new ApiError('E04', `${subdomain} is duplicated`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// create company
|
|
91
|
+
const domain: Domain = await tx.getRepository(Domain).save({
|
|
92
|
+
subdomain,
|
|
93
|
+
name,
|
|
94
|
+
extType: 'company'
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const company: Company = await tx.getRepository(Company).save({
|
|
98
|
+
name,
|
|
99
|
+
description,
|
|
100
|
+
brn,
|
|
101
|
+
address,
|
|
102
|
+
postalCode,
|
|
103
|
+
type,
|
|
104
|
+
status,
|
|
105
|
+
domain
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
context.body = {
|
|
109
|
+
data: company
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
114
|
+
else throwInternalServerError(context, e)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
powrupRouter.post('/internal/account/create-bizplace', validationMiddleware, async (context, next) => {
|
|
119
|
+
try {
|
|
120
|
+
await getConnection().transaction(async (tx: EntityManager) => {
|
|
121
|
+
const { body } = context.request
|
|
122
|
+
|
|
123
|
+
await getIntegration(context, tx)
|
|
124
|
+
|
|
125
|
+
const { data: bizplace } = body
|
|
126
|
+
const company: Company = await tx.getRepository(Company).findOne({ where: { id: bizplace.companyOriginId } })
|
|
127
|
+
|
|
128
|
+
const oldBizplace = await tx.getRepository(Bizplace).findOne({
|
|
129
|
+
where: {
|
|
130
|
+
name: Raw(alias => `LOWER(${alias}) LIKE '${bizplace.name.toLowerCase()}'`)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
if (oldBizplace) {
|
|
134
|
+
throw new ApiError('E04', `${bizplace.name} is duplicated`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let createdBizplace: Bizplace = await tx.getRepository(Bizplace).save({
|
|
138
|
+
name: bizplace.name,
|
|
139
|
+
description: bizplace.description,
|
|
140
|
+
address: bizplace.address,
|
|
141
|
+
postalCode: bizplace.postalCode,
|
|
142
|
+
latlng: bizplace.latlng,
|
|
143
|
+
status: bizplace.status,
|
|
144
|
+
company,
|
|
145
|
+
updater: context.state.user,
|
|
146
|
+
creator: context.state.user
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
await generateBizplaceDomain(bizplace.id, null, tx)
|
|
150
|
+
|
|
151
|
+
context.body = {
|
|
152
|
+
data: createdBizplace
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
} catch (e) {
|
|
156
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
157
|
+
else throwInternalServerError(context, e)
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
powrupRouter.post('/internal/account/create-partner', validationMiddleware, async (context, next) => {
|
|
162
|
+
// try {
|
|
163
|
+
// await getConnection().transaction(async (tx: EntityManager) => {
|
|
164
|
+
// const { body } = context.request
|
|
165
|
+
// await getIntegration(context, tx)
|
|
166
|
+
// const { data: partner } = body
|
|
167
|
+
// const company: Company = await tx.getRepository(Company).findOne({ where: { id: bizplace.companyOriginId } })
|
|
168
|
+
// const oldBizplace = await tx.getRepository(Bizplace).findOne({
|
|
169
|
+
// where: {
|
|
170
|
+
// name: Raw(alias => `LOWER(${alias}) LIKE '${bizplace.name.toLowerCase()}'`)
|
|
171
|
+
// }
|
|
172
|
+
// })
|
|
173
|
+
// if (oldBizplace) {
|
|
174
|
+
// throw new ApiError('E04', `${bizplace.name} is duplicated`)
|
|
175
|
+
// }
|
|
176
|
+
// let createdBizplace: Bizplace = await tx.getRepository(Bizplace).save({
|
|
177
|
+
// name: bizplace.name,
|
|
178
|
+
// description: bizplace.description,
|
|
179
|
+
// address: bizplace.address,
|
|
180
|
+
// postalCode: bizplace.postalCode,
|
|
181
|
+
// latlng: bizplace.latlng,
|
|
182
|
+
// status: bizplace.status,
|
|
183
|
+
// company,
|
|
184
|
+
// updater: context.state.user,
|
|
185
|
+
// creator: context.state.user
|
|
186
|
+
// })
|
|
187
|
+
// await generateBizplaceDomain(bizplace.id, null, tx)
|
|
188
|
+
// context.body = {
|
|
189
|
+
// data: createdBizplace
|
|
190
|
+
// }
|
|
191
|
+
// })
|
|
192
|
+
// } catch (e) {
|
|
193
|
+
// if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
194
|
+
// else throwInternalServerError(context, e)
|
|
195
|
+
// }
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
async function getIntegration(context, tx) {
|
|
199
|
+
const integration: Integration = await tx.getRepository(Integration).findOne({
|
|
200
|
+
where: { name: context.request.body.apiKey }
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
if (integration) {
|
|
204
|
+
context.state.integration = integration
|
|
205
|
+
} else {
|
|
206
|
+
throw new ApiError('E04', 'apiKey')
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// custom error class used when throwing errors for API V1
|
|
2
|
+
export class ApiError extends Error {
|
|
3
|
+
responseCode: string
|
|
4
|
+
status: number
|
|
5
|
+
message: string
|
|
6
|
+
details: string
|
|
7
|
+
constructor(responseCode: string, message: string, ...params) {
|
|
8
|
+
super(...params)
|
|
9
|
+
this.responseCode = responseCode
|
|
10
|
+
this.name = 'ApiError'
|
|
11
|
+
switch (responseCode) {
|
|
12
|
+
case 'E01':
|
|
13
|
+
this.status = 400
|
|
14
|
+
this.message = 'Invalid parameter values'
|
|
15
|
+
this.details = message
|
|
16
|
+
break
|
|
17
|
+
case 'E02':
|
|
18
|
+
this.status = 400
|
|
19
|
+
this.message = 'Unexpected parameters'
|
|
20
|
+
this.details = message
|
|
21
|
+
break
|
|
22
|
+
case 'E03':
|
|
23
|
+
this.status = 400
|
|
24
|
+
this.message = 'Missing parameters'
|
|
25
|
+
this.details = message
|
|
26
|
+
break
|
|
27
|
+
case 'E04':
|
|
28
|
+
this.status = 404
|
|
29
|
+
this.message = 'Resource not found'
|
|
30
|
+
this.details = message
|
|
31
|
+
break
|
|
32
|
+
case 'E05':
|
|
33
|
+
this.status = 409
|
|
34
|
+
this.message = 'Duplicate entry'
|
|
35
|
+
this.details = message
|
|
36
|
+
break
|
|
37
|
+
case 'E06':
|
|
38
|
+
this.status = 500
|
|
39
|
+
this.message = 'Internal server error'
|
|
40
|
+
this.details = message
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// used in catch block to give an error response
|
|
47
|
+
export function ApiErrorHandler(context, e) {
|
|
48
|
+
context.type = 'application/json'
|
|
49
|
+
context.status = e.status
|
|
50
|
+
context.body = {
|
|
51
|
+
error: {
|
|
52
|
+
responseCode: e.responseCode,
|
|
53
|
+
message: e.message,
|
|
54
|
+
details: e.details
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// used in catch block for all errors that are not ApiError
|
|
60
|
+
export function throwInternalServerError(context, e) {
|
|
61
|
+
context.type = 'application/json'
|
|
62
|
+
context.status = 500
|
|
63
|
+
context.body = {
|
|
64
|
+
error: {
|
|
65
|
+
responseCode: 'E06',
|
|
66
|
+
message: 'Internal Server Error',
|
|
67
|
+
details: e.message
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const params = {
|
|
2
|
+
'create-user': ['userOriginId', 'name', 'description', 'email', 'password', 'status']
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const reqParams = {
|
|
6
|
+
'create-user': [
|
|
7
|
+
{
|
|
8
|
+
name: 'userOriginId',
|
|
9
|
+
required: true,
|
|
10
|
+
type: 'field'
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'name',
|
|
14
|
+
required: true,
|
|
15
|
+
type: 'field'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'email',
|
|
19
|
+
required: true,
|
|
20
|
+
type: 'field'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'password',
|
|
24
|
+
required: true,
|
|
25
|
+
type: 'field'
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
package/server/routes.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { businessMiddleware } from './middlewares/business-middleware'
|
|
2
2
|
import { bizplaceRegisterRouter, businessRegisterRouter } from './routers/business'
|
|
3
|
+
import { powrupRouter } from './routers/internal/powrup-router'
|
|
3
4
|
import { xilnexRouter } from './routers/xilnex-router'
|
|
4
5
|
|
|
5
6
|
const debug = require('debug')('things-factory:operato-hub:routes')
|
|
6
7
|
|
|
7
8
|
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
8
|
-
globalPublicRouter.use(
|
|
9
|
+
globalPublicRouter.use(
|
|
10
|
+
xilnexRouter.routes(),
|
|
11
|
+
xilnexRouter.allowedMethods(),
|
|
12
|
+
powrupRouter.routes(),
|
|
13
|
+
powrupRouter.allowedMethods()
|
|
14
|
+
)
|
|
9
15
|
})
|
|
10
16
|
|
|
11
17
|
process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
|