@things-factory/operato-hub 4.3.228 → 4.3.230
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 +5 -1
- package/dist-server/routers/api/restful-apis/v1/marketplace/get-marketplace-order-shipping-list.js +1 -0
- package/dist-server/routers/api/restful-apis/v1/marketplace/get-marketplace-order-shipping-list.js.map +1 -1
- package/dist-server/routers/internal/apis/create-bizplace.js +40 -0
- package/dist-server/routers/internal/apis/create-bizplace.js.map +1 -0
- package/dist-server/routers/internal/apis/create-company.js +74 -0
- package/dist-server/routers/internal/apis/create-company.js.map +1 -0
- package/dist-server/routers/internal/apis/create-partner.js +41 -0
- package/dist-server/routers/internal/apis/create-partner.js.map +1 -0
- package/dist-server/routers/internal/apis/create-user.js +23 -0
- package/dist-server/routers/internal/apis/create-user.js.map +1 -0
- package/dist-server/routers/internal/apis/index.js +37 -0
- package/dist-server/routers/internal/apis/index.js.map +1 -0
- package/dist-server/routers/internal/apis/invite-user.js +32 -0
- package/dist-server/routers/internal/apis/invite-user.js.map +1 -0
- package/dist-server/routers/internal/apis/terminate-partner.js +38 -0
- package/dist-server/routers/internal/apis/terminate-partner.js.map +1 -0
- package/dist-server/routers/internal/apis/terminate-user.js +37 -0
- package/dist-server/routers/internal/apis/terminate-user.js.map +1 -0
- package/dist-server/routers/internal/apis/update-bizplace.js +52 -0
- package/dist-server/routers/internal/apis/update-bizplace.js.map +1 -0
- package/dist-server/routers/internal/apis/update-company.js +62 -0
- package/dist-server/routers/internal/apis/update-company.js.map +1 -0
- package/dist-server/routers/internal/apis/update-user.js +33 -0
- package/dist-server/routers/internal/apis/update-user.js.map +1 -0
- package/dist-server/routers/internal/index.js +1 -0
- package/dist-server/routers/internal/index.js.map +1 -1
- package/dist-server/routers/internal/powrup-router.js +38 -372
- package/dist-server/routers/internal/powrup-router.js.map +1 -1
- package/dist-server/routers/internal/utils/params.js +2 -2
- package/dist-server/routers/internal/utils/params.js.map +1 -1
- package/openapi/v1/marketplace.yaml +4 -0
- package/package.json +5 -5
- package/server/routers/api/restful-apis/v1/marketplace/get-marketplace-order-shipping-list.ts +1 -0
- package/server/routers/internal/apis/create-bizplace.ts +43 -0
- package/server/routers/internal/apis/create-company.ts +84 -0
- package/server/routers/internal/apis/create-partner.ts +50 -0
- package/server/routers/internal/apis/create-user.ts +33 -0
- package/server/routers/internal/apis/index.ts +21 -0
- package/server/routers/internal/apis/invite-user.ts +38 -0
- package/server/routers/internal/apis/terminate-partner.ts +45 -0
- package/server/routers/internal/apis/terminate-user.ts +45 -0
- package/server/routers/internal/apis/update-bizplace.ts +66 -0
- package/server/routers/internal/apis/update-company.ts +79 -0
- package/server/routers/internal/apis/update-user.ts +39 -0
- package/server/routers/internal/index.ts +1 -0
- package/server/routers/internal/powrup-router.ts +15 -483
- package/server/routers/internal/utils/params.ts +2 -2
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import { EntityManager, getConnection } from 'typeorm'
|
|
3
3
|
|
|
4
|
-
import { NewUser, Partner, Role, terminateGrantedRoles, User } from '@things-factory/auth-base'
|
|
5
|
-
import { Bizplace, Company } from '@things-factory/biz-base'
|
|
6
4
|
import { Integration } from '@things-factory/integration-base'
|
|
7
|
-
import { Domain } from '@things-factory/shell'
|
|
8
|
-
import { slugger } from '@things-factory/utils'
|
|
9
5
|
|
|
10
|
-
import
|
|
11
|
-
import { generateBusinessRoles } from '../../controllers/company-initializer'
|
|
6
|
+
import * as API from './apis'
|
|
12
7
|
import { validationMiddleware } from './middlewares/validation-middleware'
|
|
13
8
|
import { ApiError, ApiErrorHandler, throwInternalServerError } from './utils/error-util'
|
|
14
9
|
|
|
@@ -23,39 +18,7 @@ powrupRouter.post('/internal/account/create-user', validationMiddleware, async (
|
|
|
23
18
|
|
|
24
19
|
await getIntegration(context, tx)
|
|
25
20
|
|
|
26
|
-
let
|
|
27
|
-
const { email } = user
|
|
28
|
-
user.email = email.trim()
|
|
29
|
-
|
|
30
|
-
const oldUser: User = await tx.getRepository(User).findOne({ where: { refUserId: user.refUserId } })
|
|
31
|
-
if (oldUser) {
|
|
32
|
-
throw new ApiError(
|
|
33
|
-
'E04',
|
|
34
|
-
context.t('error.x already exists in y', { x: context.t('field.user'), y: 'operato' })
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const salt = User.generateSalt()
|
|
39
|
-
|
|
40
|
-
let createdUser: User = await tx.getRepository(User).save({
|
|
41
|
-
...user,
|
|
42
|
-
refUserId: user?.refUserId,
|
|
43
|
-
userType: user?.userType || 'user',
|
|
44
|
-
status: user?.status || 'inactive',
|
|
45
|
-
salt,
|
|
46
|
-
passwordUpdatedAt: new Date(),
|
|
47
|
-
password: User.encode(user.password, salt)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
let data = {
|
|
51
|
-
id: createdUser.id,
|
|
52
|
-
name: createdUser.name,
|
|
53
|
-
description: createdUser.description,
|
|
54
|
-
email: createdUser.email,
|
|
55
|
-
userType: createdUser.userType,
|
|
56
|
-
status: createdUser.status,
|
|
57
|
-
refUserId: createdUser.refUserId
|
|
58
|
-
}
|
|
21
|
+
let data = await API.createUser(body, context, tx)
|
|
59
22
|
|
|
60
23
|
context.body = {
|
|
61
24
|
result: { data }
|
|
@@ -74,41 +37,7 @@ powrupRouter.post('/internal/account/update-user', validationMiddleware, async (
|
|
|
74
37
|
|
|
75
38
|
await getIntegration(context, tx)
|
|
76
39
|
|
|
77
|
-
let
|
|
78
|
-
|
|
79
|
-
const existingUser: User = await tx.getRepository(User).findOne({ where: { id: user.id } })
|
|
80
|
-
if (!existingUser) {
|
|
81
|
-
throw new ApiError(
|
|
82
|
-
'E04',
|
|
83
|
-
context.t('error.x does not exists in y', { x: context.t('field.user'), y: 'operato' })
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const salt = User.generateSalt()
|
|
88
|
-
|
|
89
|
-
await tx.getRepository(User).update(
|
|
90
|
-
{ id: existingUser.id },
|
|
91
|
-
{
|
|
92
|
-
name: user?.name || existingUser.name,
|
|
93
|
-
status: user?.status || existingUser.status,
|
|
94
|
-
userType: user?.userType || existingUser.userType,
|
|
95
|
-
salt: user?.password ? salt : existingUser.salt,
|
|
96
|
-
password: user?.password ? User.encode(user.password, salt) : existingUser.password,
|
|
97
|
-
passwordUpdatedAt: user?.password ? new Date() : existingUser.passwordUpdatedAt
|
|
98
|
-
}
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
let updatedUser: User = await tx.getRepository(User).findOne(existingUser.id)
|
|
102
|
-
|
|
103
|
-
let data = {
|
|
104
|
-
id: updatedUser.id,
|
|
105
|
-
name: updatedUser.name,
|
|
106
|
-
description: updatedUser.description,
|
|
107
|
-
email: updatedUser.email,
|
|
108
|
-
userType: updatedUser.userType,
|
|
109
|
-
status: updatedUser.status,
|
|
110
|
-
refUserId: updatedUser.refUserId
|
|
111
|
-
}
|
|
40
|
+
let data = await API.updateUser(body, context, tx)
|
|
112
41
|
|
|
113
42
|
context.body = {
|
|
114
43
|
result: { data }
|
|
@@ -127,88 +56,7 @@ powrupRouter.post('/internal/account/create-company', validationMiddleware, asyn
|
|
|
127
56
|
|
|
128
57
|
await getIntegration(context, tx)
|
|
129
58
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
let foundUser: User = await tx
|
|
133
|
-
.getRepository(User)
|
|
134
|
-
.findOne({ where: { id: userId }, relations: ['domains', 'roles'] })
|
|
135
|
-
|
|
136
|
-
const subdomain = slugger(name)
|
|
137
|
-
|
|
138
|
-
//check for existing company
|
|
139
|
-
const oldCompany = await tx.getRepository(Company).findOne({
|
|
140
|
-
where: {
|
|
141
|
-
refCompanyId
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
if (oldCompany) {
|
|
146
|
-
throw new ApiError('E04', `${name} is duplicated`)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const oldDomain = await tx.getRepository(Domain).findOne({
|
|
150
|
-
where: {
|
|
151
|
-
subdomain
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
if (oldDomain) {
|
|
156
|
-
throw new ApiError('E04', `${subdomain} is duplicated`)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// create company
|
|
160
|
-
const domain: Domain = await tx.getRepository(Domain).save({
|
|
161
|
-
subdomain,
|
|
162
|
-
name,
|
|
163
|
-
extType: 'company',
|
|
164
|
-
creator: foundUser,
|
|
165
|
-
updater: foundUser
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
const company: Company = await tx.getRepository(Company).save({
|
|
169
|
-
name,
|
|
170
|
-
description,
|
|
171
|
-
brn,
|
|
172
|
-
address,
|
|
173
|
-
postalCode,
|
|
174
|
-
countryCode: countryCode || 'my',
|
|
175
|
-
type,
|
|
176
|
-
status,
|
|
177
|
-
domain,
|
|
178
|
-
refCompanyId: refCompanyId || null,
|
|
179
|
-
creator: foundUser,
|
|
180
|
-
updater: foundUser
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
const userHavingRoles: Role[] = foundUser.roles
|
|
184
|
-
const domainRoles: Role[] = await generateBusinessRoles(domain, tx)
|
|
185
|
-
|
|
186
|
-
foundUser.domains = [...foundUser.domains, domain]
|
|
187
|
-
foundUser.roles = [...userHavingRoles, domainRoles.find(r => r.name === 'BUSINESS-OWNER')]
|
|
188
|
-
|
|
189
|
-
await tx.getRepository(User).save(foundUser)
|
|
190
|
-
await tx.getRepository(Bizplace).save({
|
|
191
|
-
name: company.name,
|
|
192
|
-
description: company.description,
|
|
193
|
-
address: company.address,
|
|
194
|
-
postalCode: company.postalCode || '',
|
|
195
|
-
latlng: '',
|
|
196
|
-
domain,
|
|
197
|
-
company
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
let data = {
|
|
201
|
-
id: company.id,
|
|
202
|
-
name: company.name,
|
|
203
|
-
description: company.description,
|
|
204
|
-
address: company.address,
|
|
205
|
-
brn: company.brn,
|
|
206
|
-
postalCode: company.postalCode,
|
|
207
|
-
countryCode: company.countryCode,
|
|
208
|
-
type: company.type,
|
|
209
|
-
status: company.status,
|
|
210
|
-
refCompanyId: company.refCompanyId
|
|
211
|
-
}
|
|
59
|
+
let data = await API.createCompany(body, context, tx)
|
|
212
60
|
|
|
213
61
|
context.body = {
|
|
214
62
|
result: { data }
|
|
@@ -224,84 +72,8 @@ powrupRouter.post('/internal/account/update-company', validationMiddleware, asyn
|
|
|
224
72
|
try {
|
|
225
73
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
226
74
|
const { body } = context.request
|
|
227
|
-
const { id, name, description, brn, address, postalCode, countryCode, type, status, userId } = body.data
|
|
228
|
-
|
|
229
|
-
let foundUser: User = await tx
|
|
230
|
-
.getRepository(User)
|
|
231
|
-
.findOne({ where: { id: userId }, relations: ['domains', 'roles'] })
|
|
232
|
-
|
|
233
|
-
const subdomain = slugger(name)
|
|
234
|
-
|
|
235
|
-
//check for existing company
|
|
236
|
-
const existingCompany: Company = await tx.getRepository(Company).findOne({
|
|
237
|
-
where: { id }
|
|
238
|
-
})
|
|
239
75
|
|
|
240
|
-
|
|
241
|
-
throw new ApiError('E04', `${name} does not exist`)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const existingDomain: Domain = await tx.getRepository(Domain).findOne({
|
|
245
|
-
where: {
|
|
246
|
-
subdomain
|
|
247
|
-
},
|
|
248
|
-
relations: ['bizplace']
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
if (!existingDomain) {
|
|
252
|
-
throw new ApiError('E04', `${subdomain} does not exist`)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// update company
|
|
256
|
-
await tx.getRepository(Domain).update(
|
|
257
|
-
{ id: existingDomain.id },
|
|
258
|
-
{
|
|
259
|
-
subdomain: name ? subdomain : existingDomain.subdomain,
|
|
260
|
-
name: name ? name : existingDomain.name,
|
|
261
|
-
updater: foundUser
|
|
262
|
-
}
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
await tx.getRepository(Company).update(
|
|
266
|
-
{ id: existingCompany.id },
|
|
267
|
-
{
|
|
268
|
-
name: name || existingCompany.name,
|
|
269
|
-
description: description || existingCompany.description,
|
|
270
|
-
brn: brn || existingCompany.brn,
|
|
271
|
-
address: address || existingCompany.address,
|
|
272
|
-
countryCode: countryCode || existingCompany.countryCode,
|
|
273
|
-
postalCode: postalCode || existingCompany.postalCode || '',
|
|
274
|
-
updater: foundUser
|
|
275
|
-
}
|
|
276
|
-
)
|
|
277
|
-
await tx.getRepository(Bizplace).update(
|
|
278
|
-
{ id: existingDomain.bizplace.id },
|
|
279
|
-
{
|
|
280
|
-
name: name || existingDomain.bizplace.name,
|
|
281
|
-
description: description || existingDomain.bizplace.description,
|
|
282
|
-
address: address || existingDomain.bizplace.address,
|
|
283
|
-
postalCode: postalCode || existingDomain.bizplace.postalCode || '',
|
|
284
|
-
latlng: '',
|
|
285
|
-
updater: foundUser
|
|
286
|
-
}
|
|
287
|
-
)
|
|
288
|
-
|
|
289
|
-
const updatedCompany: Company = await tx.getRepository(Company).findOne({
|
|
290
|
-
where: { id }
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
let data = {
|
|
294
|
-
id: updatedCompany.id,
|
|
295
|
-
name: updatedCompany.name,
|
|
296
|
-
description: updatedCompany.description,
|
|
297
|
-
address: updatedCompany.address,
|
|
298
|
-
brn: updatedCompany.brn,
|
|
299
|
-
postalCode: updatedCompany.postalCode,
|
|
300
|
-
countryCode: updatedCompany.countryCode,
|
|
301
|
-
type: updatedCompany.type,
|
|
302
|
-
status: updatedCompany.status,
|
|
303
|
-
refCompanyId: updatedCompany.refCompanyId
|
|
304
|
-
}
|
|
76
|
+
let data = await API.updateCompany(body, context, tx)
|
|
305
77
|
|
|
306
78
|
context.body = {
|
|
307
79
|
result: { data }
|
|
@@ -320,45 +92,7 @@ powrupRouter.post('/internal/account/create-bizplace', validationMiddleware, asy
|
|
|
320
92
|
|
|
321
93
|
await getIntegration(context, tx)
|
|
322
94
|
|
|
323
|
-
|
|
324
|
-
const company: Company = await tx.getRepository(Company).findOne({ where: { id: bizplace.companyId } })
|
|
325
|
-
|
|
326
|
-
const oldBizplace = await tx.getRepository(Bizplace).findOne({
|
|
327
|
-
where: {
|
|
328
|
-
refBizplaceId: bizplace.refBizplaceId
|
|
329
|
-
}
|
|
330
|
-
})
|
|
331
|
-
if (oldBizplace) {
|
|
332
|
-
throw new ApiError('E04', `${bizplace.name} is duplicated`)
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
let foundUser: User = await tx.getRepository(User).findOne({ where: { id: bizplace.userId } })
|
|
336
|
-
|
|
337
|
-
let createdBizplace: Bizplace = await tx.getRepository(Bizplace).save({
|
|
338
|
-
name: bizplace.name,
|
|
339
|
-
description: bizplace?.description || null,
|
|
340
|
-
address: bizplace?.address || '',
|
|
341
|
-
postalCode: bizplace?.postalCode || '',
|
|
342
|
-
latlng: bizplace?.latlng || '',
|
|
343
|
-
status: bizplace?.status || null,
|
|
344
|
-
refBizplaceId: bizplace?.refBizplaceId || null,
|
|
345
|
-
company,
|
|
346
|
-
updater: foundUser,
|
|
347
|
-
creator: foundUser
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
await generateBizplaceDomain(createdBizplace.id, foundUser, tx)
|
|
351
|
-
|
|
352
|
-
let data = {
|
|
353
|
-
id: createdBizplace.id,
|
|
354
|
-
name: createdBizplace.name,
|
|
355
|
-
description: createdBizplace.description,
|
|
356
|
-
address: createdBizplace.address,
|
|
357
|
-
postalCode: createdBizplace.postalCode,
|
|
358
|
-
latlng: createdBizplace.latlng,
|
|
359
|
-
status: createdBizplace.status,
|
|
360
|
-
company: createdBizplace.company
|
|
361
|
-
}
|
|
95
|
+
let data = await API.createBizplace(body, context, tx)
|
|
362
96
|
|
|
363
97
|
context.body = {
|
|
364
98
|
result: { data }
|
|
@@ -377,68 +111,7 @@ powrupRouter.post('/internal/account/update-bizplace', validationMiddleware, asy
|
|
|
377
111
|
|
|
378
112
|
await getIntegration(context, tx)
|
|
379
113
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const existingBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
|
|
383
|
-
where: {
|
|
384
|
-
id: bizplace.id
|
|
385
|
-
},
|
|
386
|
-
relations: ['company', 'domain']
|
|
387
|
-
})
|
|
388
|
-
if (!existingBizplace) {
|
|
389
|
-
throw new ApiError('E04', `${bizplace.id} does not exist`)
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
const company: Company = existingBizplace.company
|
|
393
|
-
const domain: Domain = existingBizplace.domain
|
|
394
|
-
|
|
395
|
-
await tx.getRepository(Bizplace).update(
|
|
396
|
-
{ id: existingBizplace.id },
|
|
397
|
-
{
|
|
398
|
-
name: bizplace?.name || existingBizplace.name,
|
|
399
|
-
description: bizplace?.description || existingBizplace.description,
|
|
400
|
-
address: bizplace?.address || existingBizplace.address,
|
|
401
|
-
postalCode: bizplace?.postalCode || existingBizplace.postalCode,
|
|
402
|
-
latlng: bizplace?.latlng || existingBizplace.latlng,
|
|
403
|
-
status: bizplace?.status || existingBizplace.status,
|
|
404
|
-
updatedAt: new Date()
|
|
405
|
-
}
|
|
406
|
-
)
|
|
407
|
-
|
|
408
|
-
if (existingBizplace.domain.extType == 'company') {
|
|
409
|
-
await tx.getRepository(Company).update(
|
|
410
|
-
{ id: company.id },
|
|
411
|
-
{
|
|
412
|
-
name: bizplace?.name || company.name,
|
|
413
|
-
description: bizplace?.description || company.description,
|
|
414
|
-
address: bizplace?.address || company.address,
|
|
415
|
-
postalCode: bizplace?.postalCode || company.postalCode || '',
|
|
416
|
-
updatedAt: new Date()
|
|
417
|
-
}
|
|
418
|
-
)
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
await tx.getRepository(Domain).update(
|
|
422
|
-
{ id: domain.id },
|
|
423
|
-
{
|
|
424
|
-
name: bizplace?.name ? bizplace.name : domain.name,
|
|
425
|
-
subdomain: bizplace?.name ? slugger(bizplace.name) : domain.subdomain,
|
|
426
|
-
updatedAt: new Date()
|
|
427
|
-
}
|
|
428
|
-
)
|
|
429
|
-
|
|
430
|
-
let updatedBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({ where: { id: existingBizplace.id } })
|
|
431
|
-
|
|
432
|
-
let data = {
|
|
433
|
-
id: updatedBizplace.id,
|
|
434
|
-
name: updatedBizplace.name,
|
|
435
|
-
description: updatedBizplace.description,
|
|
436
|
-
address: updatedBizplace.address,
|
|
437
|
-
postalCode: updatedBizplace.postalCode,
|
|
438
|
-
latlng: updatedBizplace.latlng,
|
|
439
|
-
status: updatedBizplace.status,
|
|
440
|
-
company: updatedBizplace.company
|
|
441
|
-
}
|
|
114
|
+
let data = await API.updateBizplace(body, context, tx)
|
|
442
115
|
|
|
443
116
|
context.body = {
|
|
444
117
|
result: { data }
|
|
@@ -456,50 +129,10 @@ powrupRouter.post('/internal/account/create-partner', validationMiddleware, asyn
|
|
|
456
129
|
const { body } = context.request
|
|
457
130
|
await getIntegration(context, tx)
|
|
458
131
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const bizplace: Bizplace = await tx
|
|
462
|
-
.getRepository(Bizplace)
|
|
463
|
-
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
464
|
-
|
|
465
|
-
if (!bizplace) {
|
|
466
|
-
throw new ApiError('E04', `${bizplaceId} does not exist`)
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
const partnerBizplace: Bizplace = await tx
|
|
470
|
-
.getRepository(Bizplace)
|
|
471
|
-
.findOne({ where: { id: partnerBizplaceId }, relations: ['domain'] })
|
|
472
|
-
|
|
473
|
-
if (!partnerBizplace) {
|
|
474
|
-
throw new ApiError('E04', `${partnerBizplaceId} does not exist`)
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
const isExistingCustomer: boolean = Boolean(
|
|
478
|
-
await tx.getRepository(Partner).count({
|
|
479
|
-
where: { domain: bizplace.domain, partnerDomain: partnerBizplace.domain }
|
|
480
|
-
})
|
|
481
|
-
)
|
|
482
|
-
|
|
483
|
-
if (isExistingCustomer) {
|
|
484
|
-
throw new ApiError('E04', `${partnerBizplaceId} already registered as partner`)
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
let user: User = await tx.getRepository(User).findOne({ where: { id: requesterId } })
|
|
488
|
-
|
|
489
|
-
await tx.getRepository(Partner).save({
|
|
490
|
-
domain: bizplace.domain,
|
|
491
|
-
partnerDomain: partnerBizplace.domain,
|
|
492
|
-
requester: user || null,
|
|
493
|
-
approver: user || null
|
|
494
|
-
})
|
|
132
|
+
let data = await API.createPartner(body, context, tx)
|
|
495
133
|
|
|
496
134
|
context.body = {
|
|
497
|
-
result: {
|
|
498
|
-
data: {
|
|
499
|
-
bizplace,
|
|
500
|
-
partnerBizplaceId
|
|
501
|
-
}
|
|
502
|
-
}
|
|
135
|
+
result: { data }
|
|
503
136
|
}
|
|
504
137
|
})
|
|
505
138
|
} catch (e) {
|
|
@@ -514,45 +147,10 @@ powrupRouter.post('/internal/account/terminate-partner', validationMiddleware, a
|
|
|
514
147
|
const { body } = context.request
|
|
515
148
|
await getIntegration(context, tx)
|
|
516
149
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const bizplace: Bizplace = await tx
|
|
520
|
-
.getRepository(Bizplace)
|
|
521
|
-
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
522
|
-
|
|
523
|
-
if (!bizplace) {
|
|
524
|
-
throw new ApiError('E04', `${bizplaceId} does not exist`)
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
const partnerBizplace: Bizplace = await tx
|
|
528
|
-
.getRepository(Bizplace)
|
|
529
|
-
.findOne({ where: { id: partnerBizplaceId }, relations: ['domain'] })
|
|
530
|
-
|
|
531
|
-
if (!partnerBizplace) {
|
|
532
|
-
throw new ApiError('E04', `${partnerBizplaceId} does not exist`)
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
const partner: Partner = await tx.getRepository(Partner).findOne({
|
|
536
|
-
where: { domain: bizplace.domain, partnerDomain: partnerBizplace.domain }
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
if (!partner) {
|
|
540
|
-
throw new ApiError('E04', `partner does not exist`)
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// Remove partner
|
|
544
|
-
await tx.getRepository(Partner).delete(partner.id)
|
|
545
|
-
|
|
546
|
-
// Remove granted roles
|
|
547
|
-
await terminateGrantedRoles(bizplace.domain, partnerBizplace.domain, tx)
|
|
150
|
+
let data = await API.terminatePartner(body, context, tx)
|
|
548
151
|
|
|
549
152
|
context.body = {
|
|
550
|
-
result: {
|
|
551
|
-
data: {
|
|
552
|
-
bizplace,
|
|
553
|
-
partnerBizplaceId
|
|
554
|
-
}
|
|
555
|
-
}
|
|
153
|
+
result: { data }
|
|
556
154
|
}
|
|
557
155
|
})
|
|
558
156
|
} catch (e) {
|
|
@@ -567,39 +165,10 @@ powrupRouter.post('/internal/account/invite-user', validationMiddleware, async (
|
|
|
567
165
|
const { body } = context.request
|
|
568
166
|
await getIntegration(context, tx)
|
|
569
167
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const user: User = await tx.getRepository(User).findOne({ where: { id: userId }, relations: ['domains'] })
|
|
573
|
-
|
|
574
|
-
if (!user) {
|
|
575
|
-
throw new ApiError('E04', `${userId} does not exist`)
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const bizplace: Bizplace = await tx
|
|
579
|
-
.getRepository(Bizplace)
|
|
580
|
-
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
581
|
-
|
|
582
|
-
if (!bizplace) {
|
|
583
|
-
throw new ApiError('E04', `${bizplaceId} does not exist`)
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
const existingDomains: Domain[] = user.domains
|
|
587
|
-
if (existingDomains.find((d: Domain) => d.id === bizplace.domain.id)) {
|
|
588
|
-
throw new ApiError('E04', `user already exists in ${bizplace.name}`)
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
user.domains = [...existingDomains, bizplace.domain]
|
|
592
|
-
let updatedUser: User = await tx.getRepository(User).save(user)
|
|
168
|
+
let data = await API.inviteUser(body, context, tx)
|
|
593
169
|
|
|
594
170
|
context.body = {
|
|
595
|
-
result: {
|
|
596
|
-
data: {
|
|
597
|
-
id: updatedUser.id,
|
|
598
|
-
name: updatedUser.name,
|
|
599
|
-
email: updatedUser.email,
|
|
600
|
-
domains: updatedUser.domains
|
|
601
|
-
}
|
|
602
|
-
}
|
|
171
|
+
result: { data }
|
|
603
172
|
}
|
|
604
173
|
})
|
|
605
174
|
} catch (e) {
|
|
@@ -614,47 +183,10 @@ powrupRouter.post('/internal/account/terminate-user', validationMiddleware, asyn
|
|
|
614
183
|
const { body } = context.request
|
|
615
184
|
await getIntegration(context, tx)
|
|
616
185
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const user: User = await tx
|
|
620
|
-
.getRepository(User)
|
|
621
|
-
.findOne({ where: { id: userId }, relations: ['domains', 'roles', 'roles.domain'] })
|
|
622
|
-
|
|
623
|
-
if (!user) {
|
|
624
|
-
throw new ApiError('E04', `${userId} does not exist`)
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
const bizplace: Bizplace = await tx
|
|
628
|
-
.getRepository(Bizplace)
|
|
629
|
-
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
630
|
-
|
|
631
|
-
if (!bizplace) {
|
|
632
|
-
throw new ApiError('E04', `${bizplaceId} does not exist`)
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
const targetDomainIdx: number = user.domains.findIndex(
|
|
636
|
-
(userDomain: Domain) => userDomain.id === bizplace.domain.id
|
|
637
|
-
)
|
|
638
|
-
if (targetDomainIdx < 0) {
|
|
639
|
-
throw new ApiError('E04', `${user.name} is not a member of ${bizplace.name}`)
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
// Remove domain relation with user
|
|
643
|
-
user.domains.splice(targetDomainIdx, 1)
|
|
644
|
-
|
|
645
|
-
// Remove domain's roles that user has
|
|
646
|
-
user.roles = user.roles.filter((role: Role) => role.domain.id !== bizplace.domain.id)
|
|
647
|
-
|
|
648
|
-
let updatedUser: User = await tx.getRepository(User).save(user)
|
|
186
|
+
let data = await API.terminateUser(body, context, tx)
|
|
649
187
|
|
|
650
188
|
context.body = {
|
|
651
|
-
result: {
|
|
652
|
-
data: {
|
|
653
|
-
id: updatedUser.id,
|
|
654
|
-
name: updatedUser.name,
|
|
655
|
-
email: updatedUser.email
|
|
656
|
-
}
|
|
657
|
-
}
|
|
189
|
+
result: { data }
|
|
658
190
|
}
|
|
659
191
|
})
|
|
660
192
|
} catch (e) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const params = {
|
|
2
|
-
'create-user': ['refUserId', 'name', 'description', 'email', 'password', 'status'],
|
|
3
|
-
'update-user': ['id', 'name', 'description', 'password', 'status'],
|
|
2
|
+
'create-user': ['refUserId', 'name', 'description', 'email', 'password', 'salt', 'status'],
|
|
3
|
+
'update-user': ['id', 'name', 'description', 'password', 'salt', 'status'],
|
|
4
4
|
'create-company': ['refCompanyId', 'userId', 'name', 'description', 'brn', 'address', 'postalCode', 'type', 'status'],
|
|
5
5
|
'update-company': ['userId', 'id', 'name', 'description', 'brn', 'address', 'postalCode'],
|
|
6
6
|
'create-bizplace': [
|