@things-factory/operato-hub 4.3.237 → 4.3.239
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 +79 -107
- package/dist-server/graphql/resolvers/synchronization/powrup-pack-order.js +121 -0
- package/dist-server/graphql/resolvers/synchronization/powrup-pack-order.js.map +1 -0
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +28 -24
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js +22 -18
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js.map +1 -1
- package/dist-server/routers/internal/apis/create-bizplace.js +7 -6
- package/dist-server/routers/internal/apis/create-bizplace.js.map +1 -1
- package/dist-server/routers/internal/apis/create-company.js +5 -6
- 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 +4 -8
- 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 +17 -17
- package/dist-server/routers/internal/powrup-router.js.map +1 -1
- package/dist-server/routers/internal/utils/params.js +34 -59
- package/dist-server/routers/internal/utils/params.js.map +1 -1
- package/package.json +16 -15
- package/server/graphql/resolvers/synchronization/powrup-pack-order.ts +156 -0
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +40 -24
- package/server/routers/api/restful-apis/v1/warehouse/add-release-order.ts +34 -18
- package/server/routers/internal/apis/create-bizplace.ts +7 -6
- package/server/routers/internal/apis/create-company.ts +5 -6
- 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 +4 -9
- package/server/routers/internal/apis/update-user.ts +1 -1
- package/server/routers/internal/powrup-router.ts +17 -17
- package/server/routers/internal/utils/params.ts +34 -59
|
@@ -816,29 +816,32 @@ async function massageOrderItems(
|
|
|
816
816
|
const foundProductBundle: ProductBundle = await qb.getOne()
|
|
817
817
|
|
|
818
818
|
if (foundProductBundle) {
|
|
819
|
-
let orderProduct
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
819
|
+
let orderProduct: OrderProduct
|
|
820
|
+
|
|
821
|
+
// to be further enhanced
|
|
822
|
+
// let orderProduct = {
|
|
823
|
+
// productBundle: foundProductBundle,
|
|
824
|
+
// refCode,
|
|
825
|
+
// packingType: foundProductBundle.packingType,
|
|
826
|
+
// packingSize: packingSize || 1,
|
|
827
|
+
// uom: inputOrderItem?.uom,
|
|
828
|
+
// releaseQty: inputOrderItem.releaseQty,
|
|
829
|
+
// releaseUomValue: inputOrderItem.releaseQty,
|
|
830
|
+
// packQty: 0,
|
|
831
|
+
// actualPackQty: 0,
|
|
832
|
+
// palletQty: 0,
|
|
833
|
+
// actualPalletQty: 0,
|
|
834
|
+
// orderInventories: [],
|
|
835
|
+
// type: 'RELEASE_OF_GOODS',
|
|
836
|
+
// status: ORDER_PRODUCT_STATUS.ASSIGNED,
|
|
837
|
+
// batchId: '-',
|
|
838
|
+
// sellingPrice: inputOrderItem?.sellingPrice
|
|
839
|
+
// ? inputOrderItem.sellingPrice
|
|
840
|
+
// : avgPaidAmount * inputOrderItem.releaseQty,
|
|
841
|
+
// paidAmount: inputOrderItem?.paidAmount
|
|
842
|
+
// ? inputOrderItem.paidAmount
|
|
843
|
+
// : avgPaidAmount * inputOrderItem.releaseQty
|
|
844
|
+
// }
|
|
842
845
|
|
|
843
846
|
const bundleProductSettings: any[] = foundProductBundle.productBundleSettings
|
|
844
847
|
bundleProductSettings.map(bundleProductSetting => {
|
|
@@ -864,9 +867,22 @@ async function massageOrderItems(
|
|
|
864
867
|
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET
|
|
865
868
|
}
|
|
866
869
|
|
|
870
|
+
orderProduct = Object.assign(new OrderProduct(), newOrderInventory)
|
|
871
|
+
|
|
872
|
+
orderProduct = {
|
|
873
|
+
...orderProduct,
|
|
874
|
+
refCode,
|
|
875
|
+
packingType: foundProductBundle.packingType,
|
|
876
|
+
packingSize: packingSize || 1,
|
|
877
|
+
orderInventories: [],
|
|
878
|
+
status: ORDER_PRODUCT_STATUS.ASSIGNED,
|
|
879
|
+
batchId: '-'
|
|
880
|
+
}
|
|
881
|
+
|
|
867
882
|
orderProduct.orderInventories.push(newOrderInventory)
|
|
883
|
+
|
|
884
|
+
orderProducts.push(orderProduct)
|
|
868
885
|
})
|
|
869
|
-
orderProducts.push(orderProduct)
|
|
870
886
|
} else {
|
|
871
887
|
if (sku && refCode) {
|
|
872
888
|
context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`))
|
|
@@ -699,23 +699,26 @@ async function massageOrderItems(
|
|
|
699
699
|
const foundProductBundle: ProductBundle = await qb.getOne()
|
|
700
700
|
|
|
701
701
|
if (foundProductBundle) {
|
|
702
|
-
let orderProduct
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
702
|
+
let orderProduct: OrderProduct
|
|
703
|
+
|
|
704
|
+
// to be further enhanced
|
|
705
|
+
// let orderProduct = {
|
|
706
|
+
// productBundle: foundProductBundle,
|
|
707
|
+
// refCode,
|
|
708
|
+
// packingType: foundProductBundle.packingType,
|
|
709
|
+
// packingSize: packingSize || 1,
|
|
710
|
+
// uom: inputOrderItem?.uom,
|
|
711
|
+
// releaseQty: inputOrderItem.releaseQty,
|
|
712
|
+
// releaseUomValue: inputOrderItem.releaseQty,
|
|
713
|
+
// packQty: 0,
|
|
714
|
+
// actualPackQty: 0,
|
|
715
|
+
// palletQty: 0,
|
|
716
|
+
// actualPalletQty: 0,
|
|
717
|
+
// orderInventories: [],
|
|
718
|
+
// type: 'RELEASE_OF_GOODS',
|
|
719
|
+
// status: ORDER_PRODUCT_STATUS.ASSIGNED,
|
|
720
|
+
// batchId: '-'
|
|
721
|
+
// }
|
|
719
722
|
|
|
720
723
|
const bundleProductSettings: any[] = foundProductBundle.productBundleSettings
|
|
721
724
|
bundleProductSettings.map(bundleProductSetting => {
|
|
@@ -741,9 +744,22 @@ async function massageOrderItems(
|
|
|
741
744
|
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET
|
|
742
745
|
}
|
|
743
746
|
|
|
747
|
+
orderProduct = Object.assign(new OrderProduct(), newOrderInventory)
|
|
748
|
+
|
|
749
|
+
orderProduct = {
|
|
750
|
+
...orderProduct,
|
|
751
|
+
refCode,
|
|
752
|
+
packingType: foundProductBundle.packingType,
|
|
753
|
+
packingSize: packingSize || 1,
|
|
754
|
+
orderInventories: [],
|
|
755
|
+
status: ORDER_PRODUCT_STATUS.ASSIGNED,
|
|
756
|
+
batchId: '-'
|
|
757
|
+
}
|
|
758
|
+
|
|
744
759
|
orderProduct.orderInventories.push(newOrderInventory)
|
|
760
|
+
|
|
761
|
+
orderProducts.push(orderProduct)
|
|
745
762
|
})
|
|
746
|
-
orderProducts.push(orderProduct)
|
|
747
763
|
} else {
|
|
748
764
|
if (sku && refCode) {
|
|
749
765
|
throw new ApiError('E04', t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`))
|
|
@@ -16,24 +16,25 @@ import { ApiError } from '../utils/error-util'
|
|
|
16
16
|
|
|
17
17
|
export async function createBizplace(request, context, tx) {
|
|
18
18
|
const { data: bizplace } = request
|
|
19
|
-
const company: Company = await tx.getRepository(Company).findOne({ where: {
|
|
19
|
+
const company: Company = await tx.getRepository(Company).findOne({ where: { id: bizplace.companyId } })
|
|
20
20
|
|
|
21
21
|
if (!company) {
|
|
22
|
-
throw new ApiError('E04', `${bizplace.
|
|
22
|
+
throw new ApiError('E04', `${bizplace.companyId} not found`)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const oldBizplace = await tx.getRepository(Bizplace).findOne({
|
|
26
26
|
where: {
|
|
27
|
-
|
|
27
|
+
id: bizplace.id
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
if (oldBizplace) {
|
|
31
|
-
throw new ApiError('E04', `${bizplace.
|
|
31
|
+
throw new ApiError('E04', `${bizplace.id} is duplicated`)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
let foundUser: User = await tx.getRepository(User).findOne({ where: {
|
|
34
|
+
let foundUser: User = await tx.getRepository(User).findOne({ where: { id: bizplace.userId } })
|
|
35
35
|
|
|
36
36
|
let createdBizplace: Bizplace = await tx.getRepository(Bizplace).save({
|
|
37
|
+
id: bizplace.id,
|
|
37
38
|
name: bizplace.name,
|
|
38
39
|
description: bizplace?.description || null,
|
|
39
40
|
address: bizplace?.address || '',
|
|
@@ -56,7 +57,7 @@ export async function createBizplace(request, context, tx) {
|
|
|
56
57
|
await initGroups(tx, domain)
|
|
57
58
|
|
|
58
59
|
const userRepo: Repository<User> = tx.getRepository(User)
|
|
59
|
-
const user: User = await userRepo.findOne({ where: {
|
|
60
|
+
const user: User = await userRepo.findOne({ where: { id: bizplace.userId }, relations: ['domains', 'roles'] })
|
|
60
61
|
const roleRepo: Repository<Role> = tx.getRepository(Role)
|
|
61
62
|
const role: Role = await roleRepo.findOne({ where: { domain } })
|
|
62
63
|
const privilegeRepo: Repository<Privilege> = tx.getRepository(Privilege)
|
|
@@ -7,24 +7,22 @@ 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 { id, name, description, brn, address, postalCode, countryCode, type, status, userId, refCompanyId } =
|
|
11
11
|
request.data
|
|
12
12
|
|
|
13
|
-
let foundUser: User = await tx
|
|
14
|
-
.getRepository(User)
|
|
15
|
-
.findOne({ where: { email: userEmail }, relations: ['domains', 'roles'] })
|
|
13
|
+
let foundUser: User = await tx.getRepository(User).findOne({ where: { id: userId }, relations: ['domains', 'roles'] })
|
|
16
14
|
|
|
17
15
|
const subdomain = slugger(name)
|
|
18
16
|
|
|
19
17
|
//check for existing company
|
|
20
18
|
const oldCompany = await tx.getRepository(Company).findOne({
|
|
21
19
|
where: {
|
|
22
|
-
|
|
20
|
+
id
|
|
23
21
|
}
|
|
24
22
|
})
|
|
25
23
|
|
|
26
24
|
if (oldCompany) {
|
|
27
|
-
throw new ApiError('E04', `${
|
|
25
|
+
throw new ApiError('E04', `${id} is duplicated`)
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
const oldDomain = await tx.getRepository(Domain).findOne({
|
|
@@ -48,6 +46,7 @@ export async function createCompany(request, context, tx) {
|
|
|
48
46
|
})
|
|
49
47
|
|
|
50
48
|
const company: Company = await tx.getRepository(Company).save({
|
|
49
|
+
id,
|
|
51
50
|
name,
|
|
52
51
|
description,
|
|
53
52
|
brn,
|
|
@@ -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 { bizplaceId, partnerBizplaceId, userId } = request.data
|
|
8
8
|
|
|
9
9
|
const bizplace: Bizplace = await tx
|
|
10
10
|
.getRepository(Bizplace)
|
|
11
|
-
.findOne({ where: {
|
|
11
|
+
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
12
12
|
|
|
13
13
|
if (!bizplace) {
|
|
14
|
-
throw new ApiError('E04', `${
|
|
14
|
+
throw new ApiError('E04', `${bizplaceId} does not exist`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const partnerBizplace: Bizplace = await tx
|
|
18
18
|
.getRepository(Bizplace)
|
|
19
|
-
.findOne({ where: {
|
|
19
|
+
.findOne({ where: { id: partnerBizplaceId }, relations: ['domain'] })
|
|
20
20
|
|
|
21
21
|
if (!partnerBizplace) {
|
|
22
|
-
throw new ApiError('E04', `${
|
|
22
|
+
throw new ApiError('E04', `${partnerBizplaceId} 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', `${partnerBizplaceId} 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: { id: userId } })
|
|
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
|
+
bizplaceId,
|
|
46
|
+
partnerBizplaceId
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return data
|
|
@@ -4,10 +4,10 @@ import { ApiError } from '../utils/error-util'
|
|
|
4
4
|
|
|
5
5
|
export async function createUser(request, context, tx) {
|
|
6
6
|
let user: NewUser = request?.data || {}
|
|
7
|
-
const { email } = user
|
|
7
|
+
const { id, email } = user
|
|
8
8
|
user.email = email.trim()
|
|
9
9
|
|
|
10
|
-
const oldUser: User = await tx.getRepository(User).findOne(
|
|
10
|
+
const oldUser: User = await tx.getRepository(User).findOne(id)
|
|
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
|
}
|
|
@@ -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 { userId, bizplaceId } = request.data
|
|
9
9
|
|
|
10
|
-
const user: User = await tx.getRepository(User).findOne({ where: {
|
|
10
|
+
const user: User = await tx.getRepository(User).findOne({ where: { id: userId }, relations: ['domains'] })
|
|
11
11
|
|
|
12
12
|
if (!user) {
|
|
13
|
-
throw new ApiError('E04', `${
|
|
13
|
+
throw new ApiError('E04', `${userId} does not exist`)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const bizplace: Bizplace = await tx
|
|
17
17
|
.getRepository(Bizplace)
|
|
18
|
-
.findOne({ where: {
|
|
18
|
+
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
19
19
|
|
|
20
20
|
if (!bizplace) {
|
|
21
|
-
throw new ApiError('E04', `${
|
|
21
|
+
throw new ApiError('E04', `${bizplaceId} 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
|
+
bizplaceId,
|
|
34
|
+
userId
|
|
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 { bizplaceId, partnerBizplaceId } = request.data
|
|
8
8
|
|
|
9
9
|
const bizplace: Bizplace = await tx
|
|
10
10
|
.getRepository(Bizplace)
|
|
11
|
-
.findOne({ where: {
|
|
11
|
+
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
12
12
|
|
|
13
13
|
if (!bizplace) {
|
|
14
|
-
throw new ApiError('E04', `${
|
|
14
|
+
throw new ApiError('E04', `${bizplaceId} does not exist`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const partnerBizplace: Bizplace = await tx
|
|
18
18
|
.getRepository(Bizplace)
|
|
19
|
-
.findOne({ where: {
|
|
19
|
+
.findOne({ where: { id: partnerBizplaceId }, relations: ['domain'] })
|
|
20
20
|
|
|
21
21
|
if (!partnerBizplace) {
|
|
22
|
-
throw new ApiError('E04', `${
|
|
22
|
+
throw new ApiError('E04', `${partnerBizplaceId} 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
|
+
bizplaceId,
|
|
41
|
+
partnerBizplaceId
|
|
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 { userId, bizplaceId } = request.data
|
|
9
9
|
|
|
10
10
|
const user: User = await tx
|
|
11
11
|
.getRepository(User)
|
|
12
|
-
.findOne({ where: {
|
|
12
|
+
.findOne({ where: { id: userId }, relations: ['domains', 'roles', 'roles.domain'] })
|
|
13
13
|
|
|
14
14
|
if (!user) {
|
|
15
|
-
throw new ApiError('E04', `${
|
|
15
|
+
throw new ApiError('E04', `${userId} does not exist`)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const bizplace: Bizplace = await tx
|
|
19
19
|
.getRepository(Bizplace)
|
|
20
|
-
.findOne({ where: {
|
|
20
|
+
.findOne({ where: { id: bizplaceId }, relations: ['domain'] })
|
|
21
21
|
|
|
22
22
|
if (!bizplace) {
|
|
23
|
-
throw new ApiError('E04', `${
|
|
23
|
+
throw new ApiError('E04', `${bizplaceId} 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
|
+
userId,
|
|
41
|
+
bizplaceId
|
|
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
|
+
id: bizplace.id
|
|
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.id} does not exist`)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const company: Company = existingBizplace.company
|
|
@@ -6,22 +6,17 @@ 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 {
|
|
10
|
-
request.data
|
|
9
|
+
const { id, name, description, brn, address, postalCode, countryCode, type, status, userId } = request.data
|
|
11
10
|
|
|
12
|
-
let foundUser: User = await tx
|
|
13
|
-
.getRepository(User)
|
|
14
|
-
.findOne({ where: { email: userEmail }, relations: ['domains', 'roles'] })
|
|
11
|
+
let foundUser: User = await tx.getRepository(User).findOne({ where: { id: userId }, relations: ['domains', 'roles'] })
|
|
15
12
|
|
|
16
13
|
const subdomain = slugger(name)
|
|
17
14
|
|
|
18
15
|
//check for existing company
|
|
19
|
-
const existingCompany: Company = await tx.getRepository(Company).findOne(
|
|
20
|
-
where: { refCompanyId }
|
|
21
|
-
})
|
|
16
|
+
const existingCompany: Company = await tx.getRepository(Company).findOne(id)
|
|
22
17
|
|
|
23
18
|
if (!existingCompany) {
|
|
24
|
-
throw new ApiError('E04', `${
|
|
19
|
+
throw new ApiError('E04', `${id} does not exist`)
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
const existingBizplaces: Bizplace[] = await tx
|
|
@@ -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: { id: user.id } })
|
|
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,14 +1,14 @@
|
|
|
1
1
|
import Router from 'koa-router'
|
|
2
2
|
import { EntityManager, getConnection } from 'typeorm'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Powrup } from '@things-factory/integration-powrup'
|
|
5
5
|
import { Domain } from '@things-factory/shell'
|
|
6
6
|
|
|
7
7
|
import * as API from './apis'
|
|
8
8
|
import { validationMiddleware } from './middlewares/validation-middleware'
|
|
9
9
|
import { ApiError, ApiErrorHandler, throwInternalServerError } from './utils/error-util'
|
|
10
10
|
|
|
11
|
-
const debug = require('debug')('things-factory:
|
|
11
|
+
const debug = require('debug')('things-factory:operato-hub:powrup-router')
|
|
12
12
|
|
|
13
13
|
export const powrupRouter = new Router()
|
|
14
14
|
|
|
@@ -17,7 +17,7 @@ powrupRouter.post('/internal/account/create-user', validationMiddleware, async (
|
|
|
17
17
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
18
18
|
const { body } = context.request
|
|
19
19
|
|
|
20
|
-
await
|
|
20
|
+
await getPowrup(context, null, tx)
|
|
21
21
|
|
|
22
22
|
let data = await API.createUser(body, context, tx)
|
|
23
23
|
|
|
@@ -36,7 +36,7 @@ powrupRouter.post('/internal/account/update-user', validationMiddleware, async (
|
|
|
36
36
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
37
37
|
const { body } = context.request
|
|
38
38
|
|
|
39
|
-
await
|
|
39
|
+
await getPowrup(context, null, tx)
|
|
40
40
|
|
|
41
41
|
let data = await API.updateUser(body, context, tx)
|
|
42
42
|
|
|
@@ -55,7 +55,7 @@ powrupRouter.post('/internal/account/create-company', validationMiddleware, asyn
|
|
|
55
55
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
56
56
|
const { body } = context.request
|
|
57
57
|
|
|
58
|
-
await
|
|
58
|
+
await getPowrup(context, null, tx)
|
|
59
59
|
|
|
60
60
|
let data = await API.createCompany(body, context, tx)
|
|
61
61
|
|
|
@@ -91,7 +91,7 @@ powrupRouter.post('/internal/account/create-bizplace', validationMiddleware, asy
|
|
|
91
91
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
92
92
|
const { body } = context.request
|
|
93
93
|
|
|
94
|
-
await
|
|
94
|
+
await getPowrup(context, null, tx)
|
|
95
95
|
|
|
96
96
|
let data = await API.createBizplace(body, context, tx)
|
|
97
97
|
|
|
@@ -110,7 +110,7 @@ powrupRouter.post('/internal/account/update-bizplace', validationMiddleware, asy
|
|
|
110
110
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
111
111
|
const { body } = context.request
|
|
112
112
|
|
|
113
|
-
await
|
|
113
|
+
await getPowrup(context, null, tx)
|
|
114
114
|
|
|
115
115
|
let data = await API.updateBizplace(body, context, tx)
|
|
116
116
|
|
|
@@ -128,7 +128,7 @@ powrupRouter.post('/internal/account/create-partner', validationMiddleware, asyn
|
|
|
128
128
|
try {
|
|
129
129
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
130
130
|
const { body } = context.request
|
|
131
|
-
await
|
|
131
|
+
await getPowrup(context, null, tx)
|
|
132
132
|
|
|
133
133
|
let data = await API.createPartner(body, context, tx)
|
|
134
134
|
|
|
@@ -146,7 +146,7 @@ powrupRouter.post('/internal/account/terminate-partner', validationMiddleware, a
|
|
|
146
146
|
try {
|
|
147
147
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
148
148
|
const { body } = context.request
|
|
149
|
-
await
|
|
149
|
+
await getPowrup(context, null, tx)
|
|
150
150
|
|
|
151
151
|
let data = await API.terminatePartner(body, context, tx)
|
|
152
152
|
|
|
@@ -164,7 +164,7 @@ powrupRouter.post('/internal/account/invite-user', validationMiddleware, async (
|
|
|
164
164
|
try {
|
|
165
165
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
166
166
|
const { body } = context.request
|
|
167
|
-
await
|
|
167
|
+
await getPowrup(context, null, tx)
|
|
168
168
|
|
|
169
169
|
let data = await API.inviteUser(body, context, tx)
|
|
170
170
|
|
|
@@ -182,7 +182,7 @@ powrupRouter.post('/internal/account/terminate-user', validationMiddleware, asyn
|
|
|
182
182
|
try {
|
|
183
183
|
await getConnection().transaction(async (tx: EntityManager) => {
|
|
184
184
|
const { body } = context.request
|
|
185
|
-
await
|
|
185
|
+
await getPowrup(context, null, tx)
|
|
186
186
|
|
|
187
187
|
let data = await API.terminateUser(body, context, tx)
|
|
188
188
|
|
|
@@ -205,7 +205,7 @@ powrupRouter.get('/warehouse/get', async (context, next) => {
|
|
|
205
205
|
throw new ApiError('E01', apiKey)
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
await
|
|
208
|
+
await getPowrup(context, apiKey, tx)
|
|
209
209
|
|
|
210
210
|
if (!subdomain) {
|
|
211
211
|
throw new ApiError('E01', subdomain)
|
|
@@ -232,13 +232,13 @@ powrupRouter.get('/warehouse/get', async (context, next) => {
|
|
|
232
232
|
}
|
|
233
233
|
})
|
|
234
234
|
|
|
235
|
-
async function
|
|
236
|
-
const
|
|
237
|
-
where: {
|
|
235
|
+
async function getPowrup(context, apiKey, tx) {
|
|
236
|
+
const powrup: Powrup = await tx.getRepository(Powrup).findOne({
|
|
237
|
+
where: { apiKey: apiKey || context.request.body.apiKey }
|
|
238
238
|
})
|
|
239
239
|
|
|
240
|
-
if (
|
|
241
|
-
context.state.
|
|
240
|
+
if (powrup) {
|
|
241
|
+
context.state.powrup = powrup
|
|
242
242
|
} else {
|
|
243
243
|
throw new ApiError('E04', 'apiKey')
|
|
244
244
|
}
|