@things-factory/operato-hub 4.3.231 → 4.3.233
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 +75 -104
- package/dist-server/routers/api/restful-apis/v1/utils/params.js +2 -0
- package/dist-server/routers/api/restful-apis/v1/utils/params.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js +5 -1
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-details.js +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-details.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-list.js +1 -0
- package/dist-server/routers/api/restful-apis/v1/warehouse/get-release-order-list.js.map +1 -1
- package/dist-server/routers/internal/apis/create-bizplace.js +32 -3
- package/dist-server/routers/internal/apis/create-bizplace.js.map +1 -1
- package/dist-server/routers/internal/apis/create-company.js +5 -2
- package/dist-server/routers/internal/apis/create-company.js.map +1 -1
- package/dist-server/routers/internal/apis/create-partner.js +9 -9
- package/dist-server/routers/internal/apis/create-partner.js.map +1 -1
- package/dist-server/routers/internal/apis/create-user.js +2 -2
- package/dist-server/routers/internal/apis/create-user.js.map +1 -1
- package/dist-server/routers/internal/apis/invite-user.js +7 -7
- package/dist-server/routers/internal/apis/invite-user.js.map +1 -1
- package/dist-server/routers/internal/apis/terminate-partner.js +7 -7
- package/dist-server/routers/internal/apis/terminate-partner.js.map +1 -1
- package/dist-server/routers/internal/apis/terminate-user.js +7 -7
- package/dist-server/routers/internal/apis/terminate-user.js.map +1 -1
- package/dist-server/routers/internal/apis/update-bizplace.js +2 -2
- package/dist-server/routers/internal/apis/update-bizplace.js.map +1 -1
- package/dist-server/routers/internal/apis/update-company.js +19 -22
- package/dist-server/routers/internal/apis/update-company.js.map +1 -1
- package/dist-server/routers/internal/apis/update-user.js +1 -1
- package/dist-server/routers/internal/apis/update-user.js.map +1 -1
- package/dist-server/routers/internal/powrup-router.js +73 -0
- package/dist-server/routers/internal/powrup-router.js.map +1 -1
- package/dist-server/routers/internal/utils/params.js +45 -30
- package/dist-server/routers/internal/utils/params.js.map +1 -1
- package/openapi/v1/outbound.yaml +409 -390
- package/package.json +4 -4
- package/server/routers/api/restful-apis/v1/utils/params.ts +2 -0
- package/server/routers/api/restful-apis/v1/warehouse/add-release-order.ts +8 -4
- package/server/routers/api/restful-apis/v1/warehouse/get-release-order-details.ts +1 -0
- package/server/routers/api/restful-apis/v1/warehouse/get-release-order-list.ts +1 -0
- package/server/routers/internal/apis/create-bizplace.ts +49 -5
- package/server/routers/internal/apis/create-company.ts +6 -2
- package/server/routers/internal/apis/create-partner.ts +9 -9
- package/server/routers/internal/apis/create-user.ts +2 -2
- package/server/routers/internal/apis/invite-user.ts +7 -7
- package/server/routers/internal/apis/terminate-partner.ts +7 -7
- package/server/routers/internal/apis/terminate-user.ts +7 -7
- package/server/routers/internal/apis/update-bizplace.ts +2 -2
- package/server/routers/internal/apis/update-company.ts +20 -22
- package/server/routers/internal/apis/update-user.ts +1 -1
- package/server/routers/internal/powrup-router.ts +88 -0
- package/server/routers/internal/utils/params.ts +45 -30
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.233",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@things-factory/pdf": "^4.3.227",
|
|
92
92
|
"@things-factory/product-ui": "^4.3.227",
|
|
93
93
|
"@things-factory/resource-ui": "^4.3.227",
|
|
94
|
-
"@things-factory/sales-base": "^4.3.
|
|
94
|
+
"@things-factory/sales-base": "^4.3.232",
|
|
95
95
|
"@things-factory/scene-data-transform": "^4.3.227",
|
|
96
96
|
"@things-factory/scene-excel": "^4.3.227",
|
|
97
97
|
"@things-factory/scene-firebase": "^4.3.227",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"@things-factory/shell": "^4.3.227",
|
|
108
108
|
"@things-factory/system-ui": "^4.3.227",
|
|
109
109
|
"@things-factory/warehouse-base": "^4.3.229",
|
|
110
|
-
"@things-factory/worksheet-base": "^4.3.
|
|
110
|
+
"@things-factory/worksheet-base": "^4.3.232",
|
|
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": "544826ef621347e85325f8ebc6018598ac64259d"
|
|
123
123
|
}
|
|
@@ -268,6 +268,7 @@ export const params = {
|
|
|
268
268
|
'refNo',
|
|
269
269
|
'refNo2',
|
|
270
270
|
'refNo3',
|
|
271
|
+
'refOrderId',
|
|
271
272
|
'type',
|
|
272
273
|
'transporter',
|
|
273
274
|
'trackingNo',
|
|
@@ -339,6 +340,7 @@ export const params = {
|
|
|
339
340
|
'releaseGood.refNo',
|
|
340
341
|
'releaseGood.refNo2',
|
|
341
342
|
'releaseGood.refNo3',
|
|
343
|
+
'releaseGood.refOrderId',
|
|
342
344
|
'releaseGood.marketplaceOrderStatus',
|
|
343
345
|
'releaseGood.billingAddress',
|
|
344
346
|
'releaseGood.deliveryAddress1',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Brackets,
|
|
2
3
|
EntityManager,
|
|
3
4
|
getConnection,
|
|
4
5
|
getRepository,
|
|
6
|
+
ILike,
|
|
5
7
|
In,
|
|
6
8
|
Not,
|
|
7
9
|
Repository,
|
|
8
|
-
SelectQueryBuilder
|
|
9
|
-
ILike,
|
|
10
|
-
Brackets
|
|
10
|
+
SelectQueryBuilder
|
|
11
11
|
} from 'typeorm'
|
|
12
12
|
import { v4 as uuidv4 } from 'uuid'
|
|
13
13
|
|
|
@@ -16,6 +16,7 @@ import { User } from '@things-factory/auth-base'
|
|
|
16
16
|
import { Bizplace, getCompanyBizplace } from '@things-factory/biz-base'
|
|
17
17
|
import { GeoCountry } from '@things-factory/geography'
|
|
18
18
|
import { generateId } from '@things-factory/id-rule-base'
|
|
19
|
+
import { LastMileDelivery } from '@things-factory/integration-lmd'
|
|
19
20
|
import { Sellercraft } from '@things-factory/integration-sellercraft'
|
|
20
21
|
import { MarketplaceOrder } from '@things-factory/marketplace-base'
|
|
21
22
|
import { ProductBundle, ProductDetail } from '@things-factory/product-base'
|
|
@@ -39,7 +40,6 @@ import {
|
|
|
39
40
|
import { Setting } from '@things-factory/setting-base'
|
|
40
41
|
import { Domain } from '@things-factory/shell'
|
|
41
42
|
import { Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
42
|
-
import { LastMileDelivery } from '@things-factory/integration-lmd'
|
|
43
43
|
|
|
44
44
|
import { businessMiddleware, loggingMiddleware, validationMiddleware } from '../middlewares'
|
|
45
45
|
import { ApiError, ApiErrorHandler, throwInternalServerError } from '../utils/error-util'
|
|
@@ -96,6 +96,7 @@ router.post(
|
|
|
96
96
|
refNo: bodyReq.refNo,
|
|
97
97
|
refNo2: bodyReq?.refNo2,
|
|
98
98
|
refNo3: bodyReq?.refNo3,
|
|
99
|
+
refOrderId: bodyReq?.refOrderId,
|
|
99
100
|
releaseDate: bodyReq.releaseDate,
|
|
100
101
|
type: bodyReq.type,
|
|
101
102
|
marketplaceOrderStatus: bodyReq?.marketplaceOrderStatus,
|
|
@@ -207,6 +208,7 @@ router.post(
|
|
|
207
208
|
refNo: result.refNo,
|
|
208
209
|
refNo2: result.refNo2,
|
|
209
210
|
refNo3: result.refNo3,
|
|
211
|
+
refOrderId: result.refOrderId,
|
|
210
212
|
status: result.status,
|
|
211
213
|
truckNo: result.truckNo,
|
|
212
214
|
ownTransport: result.ownTransport,
|
|
@@ -262,6 +264,7 @@ router.post(
|
|
|
262
264
|
refNo: result.refNo,
|
|
263
265
|
refNo2: result.refNo2,
|
|
264
266
|
refNo3: result.refNo3,
|
|
267
|
+
refOrderId: result.refOrderId,
|
|
265
268
|
status: result.status,
|
|
266
269
|
truckNo: result.truckNo,
|
|
267
270
|
ownTransport: result.ownTransport,
|
|
@@ -474,6 +477,7 @@ async function createReleaseGood(
|
|
|
474
477
|
refNo: releaseGood.refNo,
|
|
475
478
|
refNo2: releaseGood.refNo2 || null,
|
|
476
479
|
refNo3: releaseGood.refNo3 || null,
|
|
480
|
+
refOrderId: releaseGood?.refOrderId || null,
|
|
477
481
|
remark: releaseGood?.remark || null,
|
|
478
482
|
releaseDate: releaseGood.releaseDate,
|
|
479
483
|
truckNo: releaseGood.truckNo,
|
|
@@ -52,6 +52,7 @@ router.get(
|
|
|
52
52
|
refNo: releaseGood.refNo,
|
|
53
53
|
refNo2: releaseGood.refNo2,
|
|
54
54
|
refNo3: releaseGood.refNo3,
|
|
55
|
+
refOrderId: releaseGood.refOrderId,
|
|
55
56
|
type: releaseGood.type,
|
|
56
57
|
releaseDate: releaseGood.releaseDate,
|
|
57
58
|
collectionOrderNo: releaseGood.collectionOrderNo,
|
|
@@ -62,6 +62,7 @@ router.get(
|
|
|
62
62
|
refNo: releaseGood.refNo,
|
|
63
63
|
refNo2: releaseGood.refNo2,
|
|
64
64
|
refNo3: releaseGood.refNo3,
|
|
65
|
+
refOrderId: releaseGood.refOrderId,
|
|
65
66
|
type: releaseGood.type,
|
|
66
67
|
releaseDate: releaseGood.releaseDate,
|
|
67
68
|
collectionOrderNo: releaseGood.collectionOrderNo,
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Repository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { Privilege, Role, User } from '@things-factory/auth-base'
|
|
2
4
|
import { Bizplace, Company } from '@things-factory/biz-base'
|
|
5
|
+
import { Domain } from '@things-factory/shell'
|
|
3
6
|
|
|
4
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
generateBizplaceDomain,
|
|
9
|
+
initCodes,
|
|
10
|
+
initGroups,
|
|
11
|
+
initMenus,
|
|
12
|
+
initSettings
|
|
13
|
+
} from '../../../controllers/bizplace-initializer'
|
|
14
|
+
import { generateBizplaceDomainRoles } from '../../../controllers/bizplace-initializer/generate-bizplace-domain-roles'
|
|
5
15
|
import { ApiError } from '../utils/error-util'
|
|
6
16
|
|
|
7
17
|
export async function createBizplace(request, context, tx) {
|
|
8
18
|
const { data: bizplace } = request
|
|
9
|
-
const company: Company = await tx.getRepository(Company).findOne({ where: {
|
|
19
|
+
const company: Company = await tx.getRepository(Company).findOne({ where: { refCompanyId: bizplace.refCompanyId } })
|
|
20
|
+
|
|
21
|
+
if (!company) {
|
|
22
|
+
throw new ApiError('E04', `${bizplace.refCompanyId} not found`)
|
|
23
|
+
}
|
|
10
24
|
|
|
11
25
|
const oldBizplace = await tx.getRepository(Bizplace).findOne({
|
|
12
26
|
where: {
|
|
@@ -17,7 +31,7 @@ export async function createBizplace(request, context, tx) {
|
|
|
17
31
|
throw new ApiError('E04', `${bizplace.name} is duplicated`)
|
|
18
32
|
}
|
|
19
33
|
|
|
20
|
-
let foundUser: User = await tx.getRepository(User).findOne({ where: {
|
|
34
|
+
let foundUser: User = await tx.getRepository(User).findOne({ where: { email: bizplace.userEmail } })
|
|
21
35
|
|
|
22
36
|
let createdBizplace: Bizplace = await tx.getRepository(Bizplace).save({
|
|
23
37
|
name: bizplace.name,
|
|
@@ -32,7 +46,37 @@ export async function createBizplace(request, context, tx) {
|
|
|
32
46
|
creator: foundUser
|
|
33
47
|
})
|
|
34
48
|
|
|
35
|
-
await generateBizplaceDomain(createdBizplace.id, foundUser, tx)
|
|
49
|
+
let domain: Domain = await generateBizplaceDomain(createdBizplace.id, foundUser, tx)
|
|
50
|
+
if (bizplace?.extType && bizplace?.extType == 'warehouse') {
|
|
51
|
+
domain.extType = bizplace.extType
|
|
52
|
+
await generateBizplaceDomainRoles(domain, tx)
|
|
53
|
+
await initMenus(tx, domain)
|
|
54
|
+
await initCodes(tx, domain)
|
|
55
|
+
await initSettings(tx, domain)
|
|
56
|
+
await initGroups(tx, domain)
|
|
57
|
+
|
|
58
|
+
const userRepo: Repository<User> = tx.getRepository(User)
|
|
59
|
+
const user: User = await userRepo.findOne({ where: { email: bizplace.userEmail }, relations: ['domains', 'roles'] })
|
|
60
|
+
const roleRepo: Repository<Role> = tx.getRepository(Role)
|
|
61
|
+
const role: Role = await roleRepo.findOne({ where: { domain } })
|
|
62
|
+
const privilegeRepo: Repository<Privilege> = tx.getRepository(Privilege)
|
|
63
|
+
const privileges: Privilege = await privilegeRepo.find()
|
|
64
|
+
|
|
65
|
+
const domains: Domain[] = user.domains
|
|
66
|
+
domains.push(domain)
|
|
67
|
+
user.domains = domains
|
|
68
|
+
|
|
69
|
+
const roles: Role[] = await user.roles
|
|
70
|
+
roles.push(role)
|
|
71
|
+
user.roles = roles
|
|
72
|
+
|
|
73
|
+
role.privileges = privileges
|
|
74
|
+
|
|
75
|
+
await userRepo.save(user)
|
|
76
|
+
await roleRepo.save(role)
|
|
77
|
+
|
|
78
|
+
await tx.getRepository(Domain).update({ id: domain.id }, { extType: bizplace.extType })
|
|
79
|
+
}
|
|
36
80
|
|
|
37
81
|
let data = {
|
|
38
82
|
id: createdBizplace.id,
|
|
@@ -7,9 +7,12 @@ import { generateBusinessRoles } from '../../../controllers/company-initializer'
|
|
|
7
7
|
import { ApiError } from '../utils/error-util'
|
|
8
8
|
|
|
9
9
|
export async function createCompany(request, context, tx) {
|
|
10
|
-
const { name, description, brn, address, postalCode, countryCode, type, status,
|
|
10
|
+
const { name, description, brn, address, postalCode, countryCode, type, status, userEmail, refCompanyId } =
|
|
11
|
+
request.data
|
|
11
12
|
|
|
12
|
-
let foundUser: User = await tx
|
|
13
|
+
let foundUser: User = await tx
|
|
14
|
+
.getRepository(User)
|
|
15
|
+
.findOne({ where: { email: userEmail }, relations: ['domains', 'roles'] })
|
|
13
16
|
|
|
14
17
|
const subdomain = slugger(name)
|
|
15
18
|
|
|
@@ -71,6 +74,7 @@ export async function createCompany(request, context, tx) {
|
|
|
71
74
|
address: company.address,
|
|
72
75
|
postalCode: company.postalCode || '',
|
|
73
76
|
latlng: '',
|
|
77
|
+
refBizplaceId: refCompanyId || null,
|
|
74
78
|
domain,
|
|
75
79
|
company
|
|
76
80
|
})
|
|
@@ -4,22 +4,22 @@ import { Bizplace } from '@things-factory/biz-base'
|
|
|
4
4
|
import { ApiError } from '../utils/error-util'
|
|
5
5
|
|
|
6
6
|
export async function createPartner(request, context, tx) {
|
|
7
|
-
const {
|
|
7
|
+
const { refBizplaceId, partnerRefBizplaceId, userEmail } = request.data
|
|
8
8
|
|
|
9
9
|
const bizplace: Bizplace = await tx
|
|
10
10
|
.getRepository(Bizplace)
|
|
11
|
-
.findOne({ where: {
|
|
11
|
+
.findOne({ where: { refBizplaceId }, relations: ['domain'] })
|
|
12
12
|
|
|
13
13
|
if (!bizplace) {
|
|
14
|
-
throw new ApiError('E04', `${
|
|
14
|
+
throw new ApiError('E04', `${refBizplaceId} does not exist`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const partnerBizplace: Bizplace = await tx
|
|
18
18
|
.getRepository(Bizplace)
|
|
19
|
-
.findOne({ where: {
|
|
19
|
+
.findOne({ where: { refBizplaceId: partnerRefBizplaceId }, relations: ['domain'] })
|
|
20
20
|
|
|
21
21
|
if (!partnerBizplace) {
|
|
22
|
-
throw new ApiError('E04', `${
|
|
22
|
+
throw new ApiError('E04', `${partnerRefBizplaceId} does not exist`)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const isExistingCustomer: boolean = Boolean(
|
|
@@ -29,10 +29,10 @@ export async function createPartner(request, context, tx) {
|
|
|
29
29
|
)
|
|
30
30
|
|
|
31
31
|
if (isExistingCustomer) {
|
|
32
|
-
throw new ApiError('E04', `${
|
|
32
|
+
throw new ApiError('E04', `${partnerRefBizplaceId} already registered as partner`)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
let user: User = await tx.getRepository(User).findOne({ where: {
|
|
35
|
+
let user: User = await tx.getRepository(User).findOne({ where: { email: userEmail } })
|
|
36
36
|
|
|
37
37
|
await tx.getRepository(Partner).save({
|
|
38
38
|
domain: bizplace.domain,
|
|
@@ -42,8 +42,8 @@ export async function createPartner(request, context, tx) {
|
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
let data = {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
refBizplaceId,
|
|
46
|
+
partnerRefBizplaceId
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return data
|
|
@@ -7,7 +7,7 @@ export async function createUser(request, context, tx) {
|
|
|
7
7
|
const { email } = user
|
|
8
8
|
user.email = email.trim()
|
|
9
9
|
|
|
10
|
-
const oldUser: User = await tx.getRepository(User).findOne({ where: {
|
|
10
|
+
const oldUser: User = await tx.getRepository(User).findOne({ where: { email: user.email } })
|
|
11
11
|
if (oldUser) {
|
|
12
12
|
throw new ApiError('E04', context.t('error.x already exists in y', { x: context.t('field.user'), y: 'operato' }))
|
|
13
13
|
}
|
|
@@ -21,7 +21,7 @@ export async function createUser(request, context, tx) {
|
|
|
21
21
|
status: user?.status || 'inactive',
|
|
22
22
|
salt: user?.salt || salt,
|
|
23
23
|
passwordUpdatedAt: new Date(),
|
|
24
|
-
password: user?.password
|
|
24
|
+
password: user?.password && user?.salt ? user.password : User.encode(user.password, salt)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
let data = {
|
|
@@ -5,20 +5,20 @@ import { Domain } from '@things-factory/shell'
|
|
|
5
5
|
import { ApiError } from '../utils/error-util'
|
|
6
6
|
|
|
7
7
|
export async function inviteUser(request, context, tx) {
|
|
8
|
-
const {
|
|
8
|
+
const { userEmail, refBizplaceId } = request.data
|
|
9
9
|
|
|
10
|
-
const user: User = await tx.getRepository(User).findOne({ where: {
|
|
10
|
+
const user: User = await tx.getRepository(User).findOne({ where: { email: userEmail }, relations: ['domains'] })
|
|
11
11
|
|
|
12
12
|
if (!user) {
|
|
13
|
-
throw new ApiError('E04', `${
|
|
13
|
+
throw new ApiError('E04', `${userEmail} does not exist`)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const bizplace: Bizplace = await tx
|
|
17
17
|
.getRepository(Bizplace)
|
|
18
|
-
.findOne({ where: {
|
|
18
|
+
.findOne({ where: { refBizplaceId }, relations: ['domain'] })
|
|
19
19
|
|
|
20
20
|
if (!bizplace) {
|
|
21
|
-
throw new ApiError('E04', `${
|
|
21
|
+
throw new ApiError('E04', `${refBizplaceId} does not exist`)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const existingDomains: Domain[] = user.domains
|
|
@@ -30,8 +30,8 @@ export async function inviteUser(request, context, tx) {
|
|
|
30
30
|
await tx.getRepository(User).save(user)
|
|
31
31
|
|
|
32
32
|
let data = {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
refBizplaceId,
|
|
34
|
+
userEmail
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
return data
|
|
@@ -4,22 +4,22 @@ import { Bizplace } from '@things-factory/biz-base'
|
|
|
4
4
|
import { ApiError } from '../utils/error-util'
|
|
5
5
|
|
|
6
6
|
export async function terminatePartner(request, context, tx) {
|
|
7
|
-
const {
|
|
7
|
+
const { refBizplaceId, partnerRefBizplaceId } = request.data
|
|
8
8
|
|
|
9
9
|
const bizplace: Bizplace = await tx
|
|
10
10
|
.getRepository(Bizplace)
|
|
11
|
-
.findOne({ where: {
|
|
11
|
+
.findOne({ where: { refBizplaceId }, relations: ['domain'] })
|
|
12
12
|
|
|
13
13
|
if (!bizplace) {
|
|
14
|
-
throw new ApiError('E04', `${
|
|
14
|
+
throw new ApiError('E04', `${refBizplaceId} does not exist`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const partnerBizplace: Bizplace = await tx
|
|
18
18
|
.getRepository(Bizplace)
|
|
19
|
-
.findOne({ where: {
|
|
19
|
+
.findOne({ where: { refBizplaceId: partnerRefBizplaceId }, relations: ['domain'] })
|
|
20
20
|
|
|
21
21
|
if (!partnerBizplace) {
|
|
22
|
-
throw new ApiError('E04', `${
|
|
22
|
+
throw new ApiError('E04', `${partnerRefBizplaceId} does not exist`)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const partner: Partner = await tx.getRepository(Partner).findOne({
|
|
@@ -37,8 +37,8 @@ export async function terminatePartner(request, context, tx) {
|
|
|
37
37
|
await terminateGrantedRoles(bizplace.domain, partnerBizplace.domain, tx)
|
|
38
38
|
|
|
39
39
|
let data = {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
refBizplaceId,
|
|
41
|
+
partnerRefBizplaceId
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return data
|
|
@@ -5,22 +5,22 @@ import { Domain } from '@things-factory/shell'
|
|
|
5
5
|
import { ApiError } from '../utils/error-util'
|
|
6
6
|
|
|
7
7
|
export async function terminateUser(request, context, tx) {
|
|
8
|
-
const {
|
|
8
|
+
const { userEmail, refBizplaceId } = request.data
|
|
9
9
|
|
|
10
10
|
const user: User = await tx
|
|
11
11
|
.getRepository(User)
|
|
12
|
-
.findOne({ where: {
|
|
12
|
+
.findOne({ where: { email: userEmail }, relations: ['domains', 'roles', 'roles.domain'] })
|
|
13
13
|
|
|
14
14
|
if (!user) {
|
|
15
|
-
throw new ApiError('E04', `${
|
|
15
|
+
throw new ApiError('E04', `${userEmail} does not exist`)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const bizplace: Bizplace = await tx
|
|
19
19
|
.getRepository(Bizplace)
|
|
20
|
-
.findOne({ where: {
|
|
20
|
+
.findOne({ where: { refBizplaceId }, relations: ['domain'] })
|
|
21
21
|
|
|
22
22
|
if (!bizplace) {
|
|
23
|
-
throw new ApiError('E04', `${
|
|
23
|
+
throw new ApiError('E04', `${refBizplaceId} does not exist`)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const targetDomainIdx: number = user.domains.findIndex((userDomain: Domain) => userDomain.id === bizplace.domain.id)
|
|
@@ -37,8 +37,8 @@ export async function terminateUser(request, context, tx) {
|
|
|
37
37
|
await tx.getRepository(User).save(user)
|
|
38
38
|
|
|
39
39
|
let data = {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
refBizplaceId,
|
|
41
|
+
userEmail
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return data
|
|
@@ -9,12 +9,12 @@ export async function updateBizplace(request, context, tx) {
|
|
|
9
9
|
|
|
10
10
|
const existingBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
|
|
11
11
|
where: {
|
|
12
|
-
|
|
12
|
+
refBizplaceId: bizplace.refBizplaceId
|
|
13
13
|
},
|
|
14
14
|
relations: ['company', 'domain']
|
|
15
15
|
})
|
|
16
16
|
if (!existingBizplace) {
|
|
17
|
-
throw new ApiError('E04', `${bizplace.
|
|
17
|
+
throw new ApiError('E04', `${bizplace.refBizplaceId} does not exist`)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const company: Company = existingBizplace.company
|
|
@@ -6,39 +6,37 @@ import { slugger } from '@things-factory/utils'
|
|
|
6
6
|
import { ApiError } from '../utils/error-util'
|
|
7
7
|
|
|
8
8
|
export async function updateCompany(request, context, tx) {
|
|
9
|
-
const {
|
|
9
|
+
const { refCompanyId, name, description, brn, address, postalCode, countryCode, type, status, userEmail } =
|
|
10
|
+
request.data
|
|
10
11
|
|
|
11
|
-
let foundUser: User = await tx
|
|
12
|
+
let foundUser: User = await tx
|
|
13
|
+
.getRepository(User)
|
|
14
|
+
.findOne({ where: { email: userEmail }, relations: ['domains', 'roles'] })
|
|
12
15
|
|
|
13
16
|
const subdomain = slugger(name)
|
|
14
17
|
|
|
15
18
|
//check for existing company
|
|
16
19
|
const existingCompany: Company = await tx.getRepository(Company).findOne({
|
|
17
|
-
where: {
|
|
20
|
+
where: { refCompanyId }
|
|
18
21
|
})
|
|
19
22
|
|
|
20
23
|
if (!existingCompany) {
|
|
21
24
|
throw new ApiError('E04', `${name} does not exist`)
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
relations: ['bizplace']
|
|
29
|
-
})
|
|
27
|
+
const existingBizplaces: Bizplace[] = await tx
|
|
28
|
+
.getRepository(Bizplace)
|
|
29
|
+
.find({ where: { company: existingCompany }, relations: ['domain'] })
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
31
|
+
let companyBizplace: Bizplace = existingBizplaces.find(biz => biz.domain.extType == 'company')
|
|
32
|
+
let companyDomain: Domain = companyBizplace.domain
|
|
34
33
|
|
|
35
34
|
// update company
|
|
36
35
|
await tx.getRepository(Domain).update(
|
|
37
|
-
{ id:
|
|
36
|
+
{ id: companyDomain.id },
|
|
38
37
|
{
|
|
39
|
-
subdomain: name ? subdomain :
|
|
40
|
-
name: name ? name :
|
|
41
|
-
updater: foundUser
|
|
38
|
+
subdomain: name ? subdomain : companyDomain.subdomain,
|
|
39
|
+
name: name ? name : companyDomain.name
|
|
42
40
|
}
|
|
43
41
|
)
|
|
44
42
|
|
|
@@ -55,19 +53,19 @@ export async function updateCompany(request, context, tx) {
|
|
|
55
53
|
}
|
|
56
54
|
)
|
|
57
55
|
await tx.getRepository(Bizplace).update(
|
|
58
|
-
{ id:
|
|
56
|
+
{ id: companyBizplace.id },
|
|
59
57
|
{
|
|
60
|
-
name: name ||
|
|
61
|
-
description: description ||
|
|
62
|
-
address: address ||
|
|
63
|
-
postalCode: postalCode ||
|
|
58
|
+
name: name || companyBizplace.name,
|
|
59
|
+
description: description || companyBizplace.description,
|
|
60
|
+
address: address || companyBizplace.address,
|
|
61
|
+
postalCode: postalCode || companyBizplace.postalCode || '',
|
|
64
62
|
latlng: '',
|
|
65
63
|
updater: foundUser
|
|
66
64
|
}
|
|
67
65
|
)
|
|
68
66
|
|
|
69
67
|
const updatedCompany: Company = await tx.getRepository(Company).findOne({
|
|
70
|
-
where: { id }
|
|
68
|
+
where: { id: existingCompany.id }
|
|
71
69
|
})
|
|
72
70
|
|
|
73
71
|
let data = {
|
|
@@ -5,7 +5,7 @@ import { ApiError } from '../utils/error-util'
|
|
|
5
5
|
export async function updateUser(request, context, tx) {
|
|
6
6
|
let user: NewUser = request?.data || {}
|
|
7
7
|
|
|
8
|
-
const existingUser: User = await tx.getRepository(User).findOne({ where: {
|
|
8
|
+
const existingUser: User = await tx.getRepository(User).findOne({ where: { email: user.email } })
|
|
9
9
|
if (!existingUser) {
|
|
10
10
|
throw new ApiError('E04', context.t('error.x does not exists in y', { x: context.t('field.user'), y: 'operato' }))
|
|
11
11
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import { EntityManager, getConnection } from 'typeorm'
|
|
3
3
|
|
|
4
|
+
import { Bizplace } from '@things-factory/biz-base'
|
|
4
5
|
import { Integration } from '@things-factory/integration-base'
|
|
5
6
|
|
|
6
7
|
import * as API from './apis'
|
|
@@ -195,6 +196,93 @@ powrupRouter.post('/internal/account/terminate-user', validationMiddleware, asyn
|
|
|
195
196
|
}
|
|
196
197
|
})
|
|
197
198
|
|
|
199
|
+
powrupRouter.post('/integration/create', validationMiddleware, async (context, next) => {
|
|
200
|
+
try {
|
|
201
|
+
await getConnection().transaction(async (tx: EntityManager) => {
|
|
202
|
+
const { body } = context.request
|
|
203
|
+
|
|
204
|
+
const { bizplaceId, name, description } = body
|
|
205
|
+
|
|
206
|
+
const bizplace: Bizplace = await tx
|
|
207
|
+
.getRepository(Bizplace)
|
|
208
|
+
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
209
|
+
|
|
210
|
+
if (!bizplace) {
|
|
211
|
+
throw new ApiError('E04', `${bizplaceId} not found`)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let existingIntegration: Integration = await tx
|
|
215
|
+
.getRepository(Integration)
|
|
216
|
+
.findOne({ where: { name, domain: bizplace.domain } })
|
|
217
|
+
|
|
218
|
+
if (existingIntegration) {
|
|
219
|
+
throw new ApiError('E04', `${name} already exist`)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let integration: Integration = {
|
|
223
|
+
name,
|
|
224
|
+
description,
|
|
225
|
+
platform: 'powrup',
|
|
226
|
+
active: true,
|
|
227
|
+
domain: bizplace.domain
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let createdIntegration: Integration = await tx.getRepository(Integration).create(integration)
|
|
231
|
+
|
|
232
|
+
let data = {
|
|
233
|
+
id: createdIntegration.id,
|
|
234
|
+
name: createdIntegration.name
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
context.body = {
|
|
238
|
+
result: { data }
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
} catch (e) {
|
|
242
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
243
|
+
else throwInternalServerError(context, e)
|
|
244
|
+
}
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
powrupRouter.post('/integration/update', validationMiddleware, async (context, next) => {
|
|
248
|
+
try {
|
|
249
|
+
await getConnection().transaction(async (tx: EntityManager) => {
|
|
250
|
+
const { body } = context.request
|
|
251
|
+
|
|
252
|
+
const { id, name, description, active } = body
|
|
253
|
+
|
|
254
|
+
let existingIntegration: Integration = await tx.getRepository(Integration).findOne(id)
|
|
255
|
+
|
|
256
|
+
if (!existingIntegration) {
|
|
257
|
+
throw new ApiError('E04', `${id} not found`)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
await tx.getRepository(Integration).update(
|
|
261
|
+
{ id: existingIntegration.id },
|
|
262
|
+
{
|
|
263
|
+
name: name || existingIntegration.name,
|
|
264
|
+
description: description || existingIntegration.description,
|
|
265
|
+
active: active || existingIntegration.active
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
let updatedIntegration: Integration = await tx.getRepository(Integration).findOne(existingIntegration.id)
|
|
270
|
+
|
|
271
|
+
let data = {
|
|
272
|
+
id: updatedIntegration.id,
|
|
273
|
+
name: updatedIntegration.name
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
context.body = {
|
|
277
|
+
result: { data }
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
} catch (e) {
|
|
281
|
+
if (e instanceof ApiError) ApiErrorHandler(context, e)
|
|
282
|
+
else throwInternalServerError(context, e)
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
|
|
198
286
|
async function getIntegration(context, tx) {
|
|
199
287
|
const integration: Integration = await tx.getRepository(Integration).findOne({
|
|
200
288
|
where: { name: context.request.body.apiKey }
|