@things-factory/biz-base 5.0.7 → 6.0.0-alpha.0
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/dist-server/index.js +4 -17
- package/dist-server/index.js.map +1 -1
- package/dist-server/middlewares/index.js.map +1 -1
- package/dist-server/migrations/index.js.map +1 -1
- package/dist-server/service/biz-option/biz-option-mutation.js +38 -45
- package/dist-server/service/biz-option/biz-option-mutation.js.map +1 -1
- package/dist-server/service/biz-option/biz-option-query.js +17 -30
- package/dist-server/service/biz-option/biz-option-query.js.map +1 -1
- package/dist-server/service/biz-option/biz-option-types.js +24 -33
- package/dist-server/service/biz-option/biz-option-types.js.map +1 -1
- package/dist-server/service/biz-option/biz-option.js +22 -31
- package/dist-server/service/biz-option/biz-option.js.map +1 -1
- package/dist-server/service/biz-option/index.js.map +1 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-mutation.js +34 -44
- package/dist-server/service/biz-option-detail/biz-option-detail-mutation.js.map +1 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-query.js +16 -29
- package/dist-server/service/biz-option-detail/biz-option-detail-query.js.map +1 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-types.js +20 -29
- package/dist-server/service/biz-option-detail/biz-option-detail-types.js.map +1 -1
- package/dist-server/service/biz-option-detail/biz-option-detail.js +20 -29
- package/dist-server/service/biz-option-detail/biz-option-detail.js.map +1 -1
- package/dist-server/service/biz-option-detail/index.js.map +1 -1
- package/dist-server/service/bizplace/bizplace-mutation.js +53 -65
- package/dist-server/service/bizplace/bizplace-mutation.js.map +1 -1
- package/dist-server/service/bizplace/bizplace-query.js +79 -88
- package/dist-server/service/bizplace/bizplace-query.js.map +1 -1
- package/dist-server/service/bizplace/bizplace-types.js +53 -62
- package/dist-server/service/bizplace/bizplace-types.js.map +1 -1
- package/dist-server/service/bizplace/bizplace.js +33 -42
- package/dist-server/service/bizplace/bizplace.js.map +1 -1
- package/dist-server/service/bizplace/index.js.map +1 -1
- package/dist-server/service/company/company-mutation.js +40 -51
- package/dist-server/service/company/company-mutation.js.map +1 -1
- package/dist-server/service/company/company-query.js +28 -44
- package/dist-server/service/company/company-query.js.map +1 -1
- package/dist-server/service/company/company-types.js +42 -50
- package/dist-server/service/company/company-types.js.map +1 -1
- package/dist-server/service/company/company.js +38 -47
- package/dist-server/service/company/company.js.map +1 -1
- package/dist-server/service/company/index.js.map +1 -1
- package/dist-server/service/contact-point/contact-point-mutation.js +45 -56
- package/dist-server/service/contact-point/contact-point-mutation.js.map +1 -1
- package/dist-server/service/contact-point/contact-point-query.js +17 -30
- package/dist-server/service/contact-point/contact-point-query.js.map +1 -1
- package/dist-server/service/contact-point/contact-point-types.js +80 -89
- package/dist-server/service/contact-point/contact-point-types.js.map +1 -1
- package/dist-server/service/contact-point/contact-point.js +48 -57
- package/dist-server/service/contact-point/contact-point.js.map +1 -1
- package/dist-server/service/contact-point/index.js.map +1 -1
- package/dist-server/service/index.js +13 -26
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/worker/index.js.map +1 -1
- package/dist-server/service/worker/worker-mutation.js +40 -50
- package/dist-server/service/worker/worker-mutation.js.map +1 -1
- package/dist-server/service/worker/worker-query.js +16 -28
- package/dist-server/service/worker/worker-query.js.map +1 -1
- package/dist-server/service/worker/worker-types.js +28 -37
- package/dist-server/service/worker/worker-types.js.map +1 -1
- package/dist-server/service/worker/worker.js +22 -31
- package/dist-server/service/worker/worker.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/dist-server/utils/get-permitted-bizplaces.js +30 -24
- package/dist-server/utils/get-permitted-bizplaces.js.map +1 -1
- package/dist-server/utils/index.js +2 -15
- package/dist-server/utils/index.js.map +1 -1
- package/package.json +3 -3
- package/server/service/biz-option/biz-option-mutation.ts +26 -12
- package/server/service/biz-option/biz-option-query.ts +4 -5
- package/server/service/biz-option-detail/biz-option-detail-mutation.ts +13 -8
- package/server/service/biz-option-detail/biz-option-detail-query.ts +3 -4
- package/server/service/bizplace/bizplace-mutation.ts +11 -12
- package/server/service/bizplace/bizplace-query.ts +44 -37
- package/server/service/company/company-mutation.ts +15 -9
- package/server/service/company/company-query.ts +9 -14
- package/server/service/contact-point/contact-point-mutation.ts +18 -16
- package/server/service/contact-point/contact-point-query.ts +4 -5
- package/server/service/worker/worker-mutation.ts +10 -10
- package/server/service/worker/worker-query.ts +4 -4
- package/server/utils/get-permitted-bizplaces.ts +15 -9
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { Arg, Args, Ctx, Directive, Query, Resolver } from 'type-graphql'
|
|
2
|
-
import { EntityManager, FindManyOptions,
|
|
2
|
+
import { EntityManager, FindManyOptions, In, Not, Repository } from 'typeorm'
|
|
3
3
|
|
|
4
4
|
import { User, UserList } from '@things-factory/auth-base'
|
|
5
|
-
import { convertListParams, ListParam } from '@things-factory/shell'
|
|
5
|
+
import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
getMyBizplace,
|
|
9
9
|
getPartnerBizplaceIds,
|
|
10
10
|
getPartnersBizplaces,
|
|
11
11
|
getPartnersCompanyBizplaces,
|
|
12
|
-
getPermittedBizplaceIds
|
|
12
|
+
getPermittedBizplaceIds,
|
|
13
|
+
getUserBizplaces
|
|
13
14
|
} from '../../utils'
|
|
14
15
|
import { Bizplace } from './bizplace'
|
|
15
|
-
import { BizplaceList
|
|
16
|
+
import { BizplaceList } from './bizplace-types'
|
|
16
17
|
|
|
17
18
|
@Resolver(Bizplace)
|
|
18
19
|
export class BizplaceQuery {
|
|
19
20
|
@Directive('@privilege(category: "bizplace", privilege: "query")')
|
|
20
21
|
@Query(returns => [Bizplace])
|
|
21
|
-
async customerBizplaces(@Ctx() context:
|
|
22
|
+
async customerBizplaces(@Ctx() context: ResolverContext): Promise<Bizplace[]> {
|
|
22
23
|
const { domain, user } = context.state
|
|
23
24
|
return await getRepository(Bizplace).find({
|
|
24
25
|
where: {
|
|
25
|
-
domain,
|
|
26
|
+
domain: { id: domain.id },
|
|
26
27
|
id: Not(In([await getMyBizplace(domain, user)]))
|
|
27
28
|
},
|
|
28
29
|
relations: ['domain', 'creator', 'updater']
|
|
@@ -31,7 +32,7 @@ export class BizplaceQuery {
|
|
|
31
32
|
|
|
32
33
|
@Directive('@privilege(category: "bizplace", privilege: "query", domainOwnerGranted: true)')
|
|
33
34
|
@Query(returns => Bizplace)
|
|
34
|
-
async businessBizplace(@Ctx() context:
|
|
35
|
+
async businessBizplace(@Ctx() context: ResolverContext): Promise<Bizplace> {
|
|
35
36
|
const { domain, user } = context.state
|
|
36
37
|
const myBizplace = await getMyBizplace(domain, user)
|
|
37
38
|
return await getRepository(Bizplace).findOne({
|
|
@@ -40,37 +41,37 @@ export class BizplaceQuery {
|
|
|
40
41
|
})
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
/* TODO make it work */
|
|
43
45
|
@Directive('@privilege(category: "bizplace", privilege: "query", domainOwnerGranted: true)')
|
|
44
|
-
@Query(returns => [
|
|
45
|
-
async userBizplaces(@Arg('email') email: string, @Ctx() context:
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
relations: ['bizplaces']
|
|
53
|
-
}
|
|
54
|
-
)
|
|
55
|
-
const bizplaces = await getRepository(Bizplace).find({ domain: context.state.domain })
|
|
56
|
-
const userBizplaces = user.bizplaces
|
|
57
|
-
return bizplaces.map((bizplace: Bizplace) => {
|
|
58
|
-
return {
|
|
59
|
-
id: bizplace.id,
|
|
60
|
-
name: bizplace.name,
|
|
61
|
-
description: bizplace.description,
|
|
62
|
-
userBizplaceId: userBizplaces
|
|
63
|
-
.map(userBiz => userBiz.bizplace.id)
|
|
64
|
-
.slice(0, 1)
|
|
65
|
-
.shift(),
|
|
66
|
-
assigned: userBizplaces.filter((userBizplace: Bizplace) => userBizplace.id === bizplace.id).length > 0
|
|
67
|
-
}
|
|
46
|
+
@Query(returns => [Bizplace])
|
|
47
|
+
async userBizplaces(@Arg('email') email: string, @Ctx() context: ResolverContext): Promise<Bizplace[]> {
|
|
48
|
+
const { domain } = context.state
|
|
49
|
+
|
|
50
|
+
const user: User = await getRepository(User).findOneBy({
|
|
51
|
+
email: email != '' ? email : context.state.user.email
|
|
68
52
|
})
|
|
53
|
+
|
|
54
|
+
return await getUserBizplaces(user)
|
|
55
|
+
|
|
56
|
+
// const bizplaces = await getRepository(Bizplace).find({ domain })
|
|
57
|
+
// // const userBizplaces = user.bizplaces
|
|
58
|
+
// return bizplaces.map((bizplace: Bizplace) => {
|
|
59
|
+
// return {
|
|
60
|
+
// id: bizplace.id,
|
|
61
|
+
// name: bizplace.name,
|
|
62
|
+
// description: bizplace.description,
|
|
63
|
+
// userBizplaceId: userBizplaces
|
|
64
|
+
// .map(userBiz => userBiz.bizplace.id)
|
|
65
|
+
// .slice(0, 1)
|
|
66
|
+
// .shift(),
|
|
67
|
+
// assigned: userBizplaces.filter((userBizplace: Bizplace) => userBizplace.id === bizplace.id).length > 0
|
|
68
|
+
// }
|
|
69
|
+
// })
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
@Directive('@privilege(category: "bizplace", privilege: "query", domainOwnerGranted: true)')
|
|
72
73
|
@Query(returns => BizplaceList)
|
|
73
|
-
async bizplaces(@Args() params: ListParam, @Ctx() context:
|
|
74
|
+
async bizplaces(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<BizplaceList> {
|
|
74
75
|
let bizplace_ids = []
|
|
75
76
|
let bizplaceIndex: any = params.filters.findIndex(x => x.name === 'bizplace')
|
|
76
77
|
if (bizplaceIndex > -1) {
|
|
@@ -111,7 +112,7 @@ export class BizplaceQuery {
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
@Query(returns => UserList)
|
|
114
|
-
async bizplaceUsers(@Args() params: ListParam, @Ctx() context:
|
|
115
|
+
async bizplaceUsers(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<UserList> {
|
|
115
116
|
const { domain, user } = context.state
|
|
116
117
|
const myBizplace: Bizplace = await getMyBizplace(domain, user)
|
|
117
118
|
return await bizplaceUsers(myBizplace, {
|
|
@@ -121,7 +122,7 @@ export class BizplaceQuery {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
@Query(returns => BizplaceList)
|
|
124
|
-
async partnersBizplaces(@Args() params: ListParam, @Ctx() context:
|
|
125
|
+
async partnersBizplaces(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<BizplaceList> {
|
|
125
126
|
let partnersBizplaceIds = []
|
|
126
127
|
let bizplaceIndex: any = params.filters.findIndex(x => x.name === 'bizplace')
|
|
127
128
|
if (bizplaceIndex > -1) {
|
|
@@ -162,7 +163,10 @@ export class BizplaceQuery {
|
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
@Query(returns => BizplaceList)
|
|
165
|
-
async permittedPartnersCompanyBizplaces(
|
|
166
|
+
async permittedPartnersCompanyBizplaces(
|
|
167
|
+
@Args() params: ListParam,
|
|
168
|
+
@Ctx() context: ResolverContext
|
|
169
|
+
): Promise<BizplaceList> {
|
|
166
170
|
let partnersBizplaceIds = []
|
|
167
171
|
let bizplaceIndex: any = params.filters.findIndex(x => x.name === 'bizplace')
|
|
168
172
|
if (bizplaceIndex > -1) {
|
|
@@ -206,7 +210,10 @@ export async function bizplaceUsers(
|
|
|
206
210
|
const userRepo: Repository<User> = trxMgr?.getRepository(User) || getRepository(User)
|
|
207
211
|
|
|
208
212
|
if (!bizplace?.users?.length) {
|
|
209
|
-
bizplace = await bizplaceRepo.findOne(
|
|
213
|
+
bizplace = await bizplaceRepo.findOne({
|
|
214
|
+
where: { id: bizplace.id },
|
|
215
|
+
relations: ['users']
|
|
216
|
+
})
|
|
210
217
|
}
|
|
211
218
|
const users: User[] = bizplace.users
|
|
212
219
|
const userIds: string[] = users.map((user: User) => user.id)
|
|
@@ -214,7 +221,7 @@ export async function bizplaceUsers(
|
|
|
214
221
|
const [items, total] = await userRepo.findAndCount({
|
|
215
222
|
...params,
|
|
216
223
|
where: {
|
|
217
|
-
...params.where,
|
|
224
|
+
...(params.where as any),
|
|
218
225
|
id: In(userIds)
|
|
219
226
|
}
|
|
220
227
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { EntityManager,
|
|
2
|
+
import { EntityManager, Repository } from 'typeorm'
|
|
3
3
|
|
|
4
4
|
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import { Domain } from '@things-factory/shell'
|
|
5
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
6
6
|
import { slugger } from '@things-factory/utils'
|
|
7
7
|
|
|
8
8
|
import { Company } from './company'
|
|
@@ -12,7 +12,7 @@ import { CompanyPatch, NewCompany } from './company-types'
|
|
|
12
12
|
export class CompanyMutation {
|
|
13
13
|
@Directive('@transaction')
|
|
14
14
|
@Mutation(returns => Company)
|
|
15
|
-
async createCompany(@Arg('company') company: NewCompany, @Ctx() context:
|
|
15
|
+
async createCompany(@Arg('company') company: NewCompany, @Ctx() context: ResolverContext): Promise<Company> {
|
|
16
16
|
const { domain, user, tx } = context.state
|
|
17
17
|
return await createCompany(company, domain, user, tx)
|
|
18
18
|
}
|
|
@@ -23,7 +23,7 @@ export class CompanyMutation {
|
|
|
23
23
|
async updateCompany(
|
|
24
24
|
@Arg('name') name: string,
|
|
25
25
|
@Arg('patch') patch: CompanyPatch,
|
|
26
|
-
@Ctx() context:
|
|
26
|
+
@Ctx() context: ResolverContext
|
|
27
27
|
): Promise<Company> {
|
|
28
28
|
const { domain, user, tx } = context.state
|
|
29
29
|
return await updateCompany(name, patch, domain, user, tx)
|
|
@@ -32,7 +32,10 @@ export class CompanyMutation {
|
|
|
32
32
|
@Directive('@privilege(category: "company", privilege: "mutation")')
|
|
33
33
|
@Directive('@transaction')
|
|
34
34
|
@Mutation(returns => [Company])
|
|
35
|
-
async updateMultipleCompany(
|
|
35
|
+
async updateMultipleCompany(
|
|
36
|
+
@Arg('patches', type => [CompanyPatch]) patches: CompanyPatch[],
|
|
37
|
+
@Ctx() context: ResolverContext
|
|
38
|
+
) {
|
|
36
39
|
let results = []
|
|
37
40
|
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
38
41
|
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
@@ -58,7 +61,7 @@ export class CompanyMutation {
|
|
|
58
61
|
|
|
59
62
|
@Directive('@transaction')
|
|
60
63
|
@Mutation(returns => Boolean)
|
|
61
|
-
async deleteCompany(@Arg('id') id: string, context:
|
|
64
|
+
async deleteCompany(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
62
65
|
await deleteCompany(id, context.state.tx)
|
|
63
66
|
|
|
64
67
|
return true
|
|
@@ -67,7 +70,10 @@ export class CompanyMutation {
|
|
|
67
70
|
@Directive('@transaction')
|
|
68
71
|
@Directive('@privilege(category: "company", privilege: "mutation")')
|
|
69
72
|
@Mutation(returns => Boolean)
|
|
70
|
-
async deleteCompanies(
|
|
73
|
+
async deleteCompanies(
|
|
74
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
75
|
+
@Ctx() context: ResolverContext
|
|
76
|
+
): Promise<Boolean> {
|
|
71
77
|
await deleteCompanies(ids, context.state.tx)
|
|
72
78
|
|
|
73
79
|
return true
|
|
@@ -93,8 +99,8 @@ export async function createCompany(company: NewCompany, domain: Domain, user: U
|
|
|
93
99
|
|
|
94
100
|
export async function updateCompany(name: string, patch: CompanyPatch, domain: Domain, user: User, tx?: EntityManager) {
|
|
95
101
|
const repository: Repository<Company> = tx ? tx.getRepository(Company) : getRepository(Company)
|
|
96
|
-
const company = await repository.
|
|
97
|
-
domain,
|
|
102
|
+
const company = await repository.findOneBy({
|
|
103
|
+
domain: { id: domain.id },
|
|
98
104
|
name
|
|
99
105
|
})
|
|
100
106
|
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import { Args, Ctx, Directive, Query, Resolver } from 'type-graphql'
|
|
2
|
-
import {
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
3
|
|
|
4
4
|
import { getDomainUsers, getUserDomains, User, UserList } from '@things-factory/auth-base'
|
|
5
|
-
import { convertListParams, Domain, ListParam } from '@things-factory/shell'
|
|
5
|
+
import { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
|
6
6
|
|
|
7
7
|
import { Bizplace } from '../bizplace/bizplace'
|
|
8
8
|
import { BizplaceList } from '../bizplace/bizplace-types'
|
|
9
9
|
import { Company } from './company'
|
|
10
10
|
import { CompanyList } from './company-types'
|
|
11
11
|
|
|
12
|
-
const debug = require('debug')('things-factory:biz-base:company-resolver')
|
|
13
|
-
|
|
14
12
|
@Resolver(Company)
|
|
15
13
|
export class CompanyQuery {
|
|
16
14
|
@Directive('@privilege(category: "company", privilege: "query", domainOwnerGranted: true)')
|
|
17
15
|
@Query(returns => Company)
|
|
18
|
-
async company(@Ctx() context:
|
|
16
|
+
async company(@Ctx() context: ResolverContext): Promise<Company> {
|
|
19
17
|
const { domain } = context.state
|
|
20
|
-
debug('company', domain?.subdomain)
|
|
21
18
|
|
|
22
|
-
const foundCompany: Company | null = await getRepository(Company).
|
|
19
|
+
const foundCompany: Company | null = await getRepository(Company).findOneBy({
|
|
23
20
|
domain
|
|
24
21
|
})
|
|
25
22
|
|
|
@@ -29,7 +26,7 @@ export class CompanyQuery {
|
|
|
29
26
|
|
|
30
27
|
@Directive('@privilege(category: "company", privilege: "query")')
|
|
31
28
|
@Query(returns => CompanyList)
|
|
32
|
-
async companies(@Args() params: ListParam, @Ctx() context:
|
|
29
|
+
async companies(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<CompanyList> {
|
|
33
30
|
const { domain } = context.state
|
|
34
31
|
const convertedParams = convertListParams(params, { domain })
|
|
35
32
|
|
|
@@ -42,17 +39,16 @@ export class CompanyQuery {
|
|
|
42
39
|
|
|
43
40
|
@Directive('@privilege(category: "company", privilege: "query", domainOwnerGranted: true)')
|
|
44
41
|
@Query(returns => BizplaceList)
|
|
45
|
-
async companyBizplaces(@Ctx() context:
|
|
42
|
+
async companyBizplaces(@Ctx() context: ResolverContext): Promise<BizplaceList> {
|
|
46
43
|
const { domain, user } = context.state
|
|
47
|
-
debug('companyBizplaces', domain?.subdomain)
|
|
48
44
|
|
|
49
45
|
const userDomains: Domain[] = await getUserDomains(user)
|
|
50
|
-
const company: Company = await getRepository(Company).
|
|
46
|
+
const company: Company = await getRepository(Company).findOneBy({
|
|
51
47
|
domain
|
|
52
48
|
})
|
|
53
49
|
|
|
54
50
|
const [items, total] = await getRepository(Bizplace).findAndCount({
|
|
55
|
-
where: { company, domain: In(userDomains.map(({ id }: Domain) => id)) },
|
|
51
|
+
where: { company: { id: company.id }, domain: { id: In(userDomains.map(({ id }: Domain) => id)) } },
|
|
56
52
|
relations: ['domain']
|
|
57
53
|
})
|
|
58
54
|
|
|
@@ -61,9 +57,8 @@ export class CompanyQuery {
|
|
|
61
57
|
|
|
62
58
|
@Directive('@privilege(category: "company", privilege: "query", domainOwnerGranted: true)')
|
|
63
59
|
@Query(returns => UserList)
|
|
64
|
-
async companyUsers(@Ctx() context:
|
|
60
|
+
async companyUsers(@Ctx() context: ResolverContext): Promise<UserList> {
|
|
65
61
|
const { domain } = context.state
|
|
66
|
-
debug('companyUsers', domain?.subdomain)
|
|
67
62
|
|
|
68
63
|
const items: User[] = await getDomainUsers(domain)
|
|
69
64
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { EntityManager,
|
|
2
|
+
import { EntityManager, Repository } from 'typeorm'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { Domain } from '@things-factory/shell'
|
|
4
|
+
import { getRepository } from '@things-factory/shell'
|
|
6
5
|
|
|
7
6
|
import { Bizplace } from '../bizplace/bizplace'
|
|
8
7
|
import { ContactPoint } from './contact-point'
|
|
@@ -14,9 +13,9 @@ export class ContactPointMutation {
|
|
|
14
13
|
@Mutation(returns => ContactPoint)
|
|
15
14
|
async createContactPoint(
|
|
16
15
|
@Arg('contactPoint') contactPoint: NewContactPoint,
|
|
17
|
-
@Ctx() context:
|
|
16
|
+
@Ctx() context: ResolverContext
|
|
18
17
|
): Promise<ContactPoint> {
|
|
19
|
-
return await createContactPoint(contactPoint, context)
|
|
18
|
+
return await createContactPoint(contactPoint as any, context)
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
@Directive('@privilege(category: "contact_point", privilege: "mutation")')
|
|
@@ -24,12 +23,12 @@ export class ContactPointMutation {
|
|
|
24
23
|
async updateContactPoint(
|
|
25
24
|
@Arg('id') id: string,
|
|
26
25
|
@Arg('patch') patch: ContactPointPatch,
|
|
27
|
-
@Ctx() context:
|
|
26
|
+
@Ctx() context: ResolverContext
|
|
28
27
|
): Promise<ContactPoint> {
|
|
29
|
-
const contactPoint = await getRepository(ContactPoint).
|
|
28
|
+
const contactPoint = await getRepository(ContactPoint).findOneBy({ id })
|
|
30
29
|
|
|
31
30
|
if (patch.bizplace && patch.bizplace.id) {
|
|
32
|
-
patch.bizplace = await getRepository(Bizplace).
|
|
31
|
+
patch.bizplace = await getRepository(Bizplace).findOneBy({ id: patch.bizplace.id })
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
return await getRepository(ContactPoint).save({
|
|
@@ -43,9 +42,9 @@ export class ContactPointMutation {
|
|
|
43
42
|
@Mutation(returns => [ContactPoint])
|
|
44
43
|
async updateMultipleContactPoint(
|
|
45
44
|
@Arg('patches', type => [ContactPointPatch]) patches: ContactPointPatch[],
|
|
46
|
-
@Ctx() context:
|
|
45
|
+
@Ctx() context: ResolverContext
|
|
47
46
|
): Promise<ContactPoint[]> {
|
|
48
|
-
const { tx }
|
|
47
|
+
const { tx } = context.state
|
|
49
48
|
let results = []
|
|
50
49
|
const { createRecords, updateRecords, deleteRecords } = patches.reduce(
|
|
51
50
|
(records, patch) => {
|
|
@@ -91,7 +90,7 @@ export class ContactPointMutation {
|
|
|
91
90
|
|
|
92
91
|
@Directive('@privilege(category: "contact_point", privilege: "mutation")')
|
|
93
92
|
@Mutation(returns => Boolean)
|
|
94
|
-
async deleteContactPoint(@Arg('id') id: string, @Ctx() context:
|
|
93
|
+
async deleteContactPoint(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
95
94
|
await deleteContactPoint(id, context.state.tx)
|
|
96
95
|
|
|
97
96
|
return true
|
|
@@ -99,7 +98,10 @@ export class ContactPointMutation {
|
|
|
99
98
|
|
|
100
99
|
@Directive('@privilege(category: "contact_point", privilege: "mutation")')
|
|
101
100
|
@Mutation(returns => Boolean)
|
|
102
|
-
async deleteContactPoints(
|
|
101
|
+
async deleteContactPoints(
|
|
102
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
103
|
+
@Ctx() context: ResolverContext
|
|
104
|
+
): Promise<Boolean> {
|
|
103
105
|
await getRepository(ContactPoint).delete(ids)
|
|
104
106
|
|
|
105
107
|
return true
|
|
@@ -111,7 +113,7 @@ export async function createContactPoint(
|
|
|
111
113
|
context: any,
|
|
112
114
|
tx?: EntityManager
|
|
113
115
|
): Promise<ContactPoint> {
|
|
114
|
-
const { domain, user }
|
|
116
|
+
const { domain, user } = context.state
|
|
115
117
|
|
|
116
118
|
const bizplaceRepo: Repository<Bizplace> = tx?.getRepository(Bizplace) || getRepository(Bizplace)
|
|
117
119
|
const contactPointRepo: Repository<ContactPoint> = tx?.getRepository(ContactPoint) || getRepository(ContactPoint)
|
|
@@ -119,7 +121,7 @@ export async function createContactPoint(
|
|
|
119
121
|
if (!contactPoint.bizplace?.id) {
|
|
120
122
|
contactPoint.bizplace = await bizplaceRepo.findOne({ where: { name: domain.name } })
|
|
121
123
|
} else {
|
|
122
|
-
contactPoint.bizplace = await bizplaceRepo.
|
|
124
|
+
contactPoint.bizplace = await bizplaceRepo.findOneBy({ id: contactPoint.bizplace.id })
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
return await contactPointRepo.save({
|
|
@@ -139,7 +141,7 @@ export async function updateContactPoint(
|
|
|
139
141
|
const bizplaceRepo: Repository<Bizplace> = tx?.getRepository(Bizplace) || getRepository(Bizplace)
|
|
140
142
|
const contactPointRepo: Repository<ContactPoint> = tx?.getRepository(ContactPoint) || getRepository(ContactPoint)
|
|
141
143
|
|
|
142
|
-
const { domain, user }
|
|
144
|
+
const { domain, user } = context.state
|
|
143
145
|
let contactPoint: ContactPoint = await contactPointRepo.findOne({ where: { id }, relations: ['bizplace'] })
|
|
144
146
|
|
|
145
147
|
if (!contactPoint?.bizplace?.id) {
|
|
@@ -147,7 +149,7 @@ export async function updateContactPoint(
|
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
if (patch?.bizplace?.id) {
|
|
150
|
-
patch.bizplace = await bizplaceRepo.
|
|
152
|
+
patch.bizplace = await bizplaceRepo.findOneBy({ id: patch.bizplace.id })
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
return await contactPointRepo.save({
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Arg, Args, Ctx, Directive, Query, Resolver } from 'type-graphql'
|
|
2
|
-
import { getRepository } from 'typeorm'
|
|
3
2
|
|
|
4
|
-
import { buildQuery, ListParam } from '@things-factory/shell'
|
|
3
|
+
import { buildQuery, getRepository, ListParam } from '@things-factory/shell'
|
|
5
4
|
|
|
6
5
|
import { ContactPoint } from './contact-point'
|
|
7
6
|
import { ContactPointList } from './contact-point-types'
|
|
@@ -10,16 +9,16 @@ import { ContactPointList } from './contact-point-types'
|
|
|
10
9
|
export class ContactPointQuery {
|
|
11
10
|
@Directive('@privilege(category: "contact_point", privilege: "query")')
|
|
12
11
|
@Query(returns => ContactPoint)
|
|
13
|
-
async contactPoint(@Arg('name') name: string, @Ctx() context:
|
|
12
|
+
async contactPoint(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<ContactPoint> {
|
|
14
13
|
return await getRepository(ContactPoint).findOne({
|
|
15
|
-
where: { domain: context.state.domain, name },
|
|
14
|
+
where: { domain: { id: context.state.domain.id }, name },
|
|
16
15
|
relations: ['domain', 'bizplace', 'creator', 'updater']
|
|
17
16
|
})
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
@Directive('@privilege(category: "contact_point", privilege: "query")')
|
|
21
20
|
@Query(returns => ContactPointList)
|
|
22
|
-
async contactPoints(@Args() params: ListParam, @Ctx() context:
|
|
21
|
+
async contactPoints(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ContactPointList> {
|
|
23
22
|
const queryBuilder = getRepository(ContactPoint).createQueryBuilder()
|
|
24
23
|
buildQuery(queryBuilder, params, context, {
|
|
25
24
|
searchables: ['name', 'address', 'postCode', 'phone']
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { EntityManager,
|
|
2
|
+
import { EntityManager, In, Repository } from 'typeorm'
|
|
3
3
|
|
|
4
|
-
import { Domain } from '@things-factory/shell'
|
|
4
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
5
5
|
|
|
6
6
|
import { getMyBizplace } from '../../utils'
|
|
7
7
|
import { Worker } from './worker'
|
|
@@ -11,7 +11,7 @@ import { NewWorker, WorkerPatch } from './worker-types'
|
|
|
11
11
|
export class WorkerMutation {
|
|
12
12
|
@Directive('@privilege(category: "worker", privilege: "mutation")')
|
|
13
13
|
@Mutation(returns => Worker)
|
|
14
|
-
async createWorker(@Arg('worker') worker: NewWorker, @Ctx() context:
|
|
14
|
+
async createWorker(@Arg('worker') worker: NewWorker, @Ctx() context: ResolverContext): Promise<Worker> {
|
|
15
15
|
return await createWorker(worker, context.state.domain, context.state.user)
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ export class WorkerMutation {
|
|
|
20
20
|
async updateWorker(
|
|
21
21
|
@Arg('id') id: string,
|
|
22
22
|
@Arg('patch', type => WorkerPatch) patch: WorkerPatch,
|
|
23
|
-
@Ctx() context:
|
|
23
|
+
@Ctx() context: ResolverContext
|
|
24
24
|
): Promise<Worker> {
|
|
25
25
|
return await updateWorker(id, patch, context.state.domain, context.state.user)
|
|
26
26
|
}
|
|
@@ -30,9 +30,9 @@ export class WorkerMutation {
|
|
|
30
30
|
@Mutation(returns => [Worker])
|
|
31
31
|
async updateMultipleWorker(
|
|
32
32
|
@Arg('patches', type => [WorkerPatch]) patches: WorkerPatch[],
|
|
33
|
-
@Ctx() context:
|
|
33
|
+
@Ctx() context: ResolverContext
|
|
34
34
|
): Promise<Worker[]> {
|
|
35
|
-
const { tx }
|
|
35
|
+
const { tx } = context.state
|
|
36
36
|
|
|
37
37
|
let results = []
|
|
38
38
|
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
@@ -65,7 +65,7 @@ export class WorkerMutation {
|
|
|
65
65
|
|
|
66
66
|
@Directive('@privilege(category: "worker", privilege: "mutation")')
|
|
67
67
|
@Mutation(returns => Boolean)
|
|
68
|
-
async deleteWorkers(@Arg('ids', type => [String]) ids: string[], @Ctx() context:
|
|
68
|
+
async deleteWorkers(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
69
69
|
return deleteWorkers({ ids }, context)
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -84,8 +84,8 @@ export async function createWorker(worker: NewWorker, domain: Domain, user: any,
|
|
|
84
84
|
|
|
85
85
|
export async function updateWorker(id: string, patch: WorkerPatch, domain: Domain, user: any, trxMgr?: EntityManager) {
|
|
86
86
|
const repository: Repository<Worker> = trxMgr ? trxMgr.getRepository(Worker) : getRepository(Worker)
|
|
87
|
-
const worker = await repository.
|
|
88
|
-
domain,
|
|
87
|
+
const worker = await repository.findOneBy({
|
|
88
|
+
domain: { id: domain.id },
|
|
89
89
|
id
|
|
90
90
|
})
|
|
91
91
|
|
|
@@ -104,7 +104,7 @@ export async function deleteWorker(id: string, trxMgr?: EntityManager) {
|
|
|
104
104
|
export async function deleteWorkers({ ids }, _context: any) {
|
|
105
105
|
const { domain } = _context.state
|
|
106
106
|
await getRepository(Worker).delete({
|
|
107
|
-
domain,
|
|
107
|
+
domain: { id: domain.id },
|
|
108
108
|
id: In(ids)
|
|
109
109
|
})
|
|
110
110
|
return true
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Arg, Args, Ctx, Directive, Query, Resolver } from 'type-graphql'
|
|
2
|
-
import {
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
3
|
|
|
4
|
-
import { convertListParams, ListParam } from '@things-factory/shell'
|
|
4
|
+
import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
5
|
|
|
6
6
|
import { getPermittedBizplaceIds } from '../../utils'
|
|
7
7
|
import { Worker } from './worker'
|
|
@@ -11,7 +11,7 @@ import { WorkerList } from './worker-types'
|
|
|
11
11
|
export class WorkerQuery {
|
|
12
12
|
@Directive('@privilege(category: "worker", privilege: "query")')
|
|
13
13
|
@Query(returns => Worker)
|
|
14
|
-
async worker(@Arg('name') name: string, @Ctx() context:
|
|
14
|
+
async worker(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Worker> {
|
|
15
15
|
return await getRepository(Worker).findOne({
|
|
16
16
|
where: {
|
|
17
17
|
domain: context.state.domain,
|
|
@@ -24,7 +24,7 @@ export class WorkerQuery {
|
|
|
24
24
|
|
|
25
25
|
@Directive('@privilege(category: "worker", privilege: "query")')
|
|
26
26
|
@Query(returns => WorkerList)
|
|
27
|
-
async workers(@Args() params: ListParam, @Ctx() context:
|
|
27
|
+
async workers(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<WorkerList> {
|
|
28
28
|
const convertedParams = convertListParams(params)
|
|
29
29
|
convertedParams.where.bizplace = In(await getPermittedBizplaceIds(context.state.domain, context.state.user))
|
|
30
30
|
const [items, total] = await getRepository(Worker).findAndCount({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EntityManager,
|
|
1
|
+
import { EntityManager, In, SelectQueryBuilder } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { checkUserBelongsDomain, Partner, User } from '@things-factory/auth-base'
|
|
4
|
-
import { Domain } from '@things-factory/shell'
|
|
4
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
5
5
|
|
|
6
6
|
import { Bizplace } from '../service/bizplace/bizplace'
|
|
7
7
|
|
|
@@ -78,7 +78,7 @@ export async function getOutletBizplace(outletId: string, tx?: EntityManager) {
|
|
|
78
78
|
export async function getCompanyBizplace(
|
|
79
79
|
domain: Domain,
|
|
80
80
|
user: User,
|
|
81
|
-
customerBizplaceId
|
|
81
|
+
customerBizplaceId?: string,
|
|
82
82
|
tx?: EntityManager
|
|
83
83
|
): Promise<Bizplace> {
|
|
84
84
|
const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)
|
|
@@ -88,7 +88,10 @@ export async function getCompanyBizplace(
|
|
|
88
88
|
if (user) {
|
|
89
89
|
let myBizplace: Bizplace = await getMyBizplace(domain, user, tx)
|
|
90
90
|
if (!myBizplace.company?.id) {
|
|
91
|
-
myBizplace = await bizplaceRepo.findOne(
|
|
91
|
+
myBizplace = await bizplaceRepo.findOne({
|
|
92
|
+
where: { id: myBizplace.id },
|
|
93
|
+
relations: ['company', 'company.domain']
|
|
94
|
+
})
|
|
92
95
|
companyDomain = myBizplace.company.domain
|
|
93
96
|
}
|
|
94
97
|
}
|
|
@@ -136,16 +139,16 @@ export async function getPartnerBizplaceIds(domain: Domain, user: User, tx?: Ent
|
|
|
136
139
|
|
|
137
140
|
let partnerBizplaces: Bizplace[] = []
|
|
138
141
|
|
|
139
|
-
const domainBizplace: Bizplace = await bizplaceRepo.findOne({ where: { domain } })
|
|
142
|
+
const domainBizplace: Bizplace = await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } })
|
|
140
143
|
if (!domainBizplace) {
|
|
141
144
|
} else {
|
|
142
145
|
const partners: Partner[] = await partnerRepo.find({
|
|
143
|
-
where: { domainBizplace }
|
|
146
|
+
where: { domain: { id: domainBizplace.id } } /* CONFIRMME regarding TYPEORM - compare original logic */,
|
|
144
147
|
relations: ['partnerBizplace', 'partnerBizplace.company', 'partnerBizplace.company.domain']
|
|
145
148
|
})
|
|
146
149
|
|
|
147
150
|
for (let partner of partners) {
|
|
148
|
-
partnerBizplaces.push(partner.partnerBizplace)
|
|
151
|
+
partnerBizplaces.push((partner as any).partnerBizplace)
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
return partnerBizplaces.map((bizplace: Bizplace) => bizplace.id || null)
|
|
@@ -286,7 +289,7 @@ export async function getCustomerBizplaces(domain: Domain, tx?: EntityManager):
|
|
|
286
289
|
})
|
|
287
290
|
}
|
|
288
291
|
|
|
289
|
-
export async function getSubdomainBizplace(subdomain:
|
|
292
|
+
export async function getSubdomainBizplace(subdomain: string, tx?: EntityManager): Promise<Bizplace> {
|
|
290
293
|
const domainRepo = tx ? tx.getRepository(Domain) : getRepository(Domain)
|
|
291
294
|
|
|
292
295
|
const domain: Domain = await domainRepo.findOne({
|
|
@@ -301,7 +304,10 @@ export async function getUserBizplaces(user: User, tx?: EntityManager): Promise<
|
|
|
301
304
|
let userBizplaces: Bizplace[] = []
|
|
302
305
|
|
|
303
306
|
if (!user.domains?.length) {
|
|
304
|
-
user = await userRepo.findOne(
|
|
307
|
+
user = await userRepo.findOne({
|
|
308
|
+
where: { id: user.id },
|
|
309
|
+
relations: ['domains']
|
|
310
|
+
})
|
|
305
311
|
}
|
|
306
312
|
|
|
307
313
|
const userDomains: Domain[] = user.domains
|