@things-factory/biz-base 8.0.0-beta.9 → 8.0.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/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/server/index.ts +3 -0
- package/server/middlewares/index.ts +0 -0
- package/server/migrations/index.ts +9 -0
- package/server/service/biz-option/biz-option-mutation.ts +65 -0
- package/server/service/biz-option/biz-option-query.ts +30 -0
- package/server/service/biz-option/biz-option-types.ts +44 -0
- package/server/service/biz-option/biz-option.ts +70 -0
- package/server/service/biz-option/index.ts +6 -0
- package/server/service/biz-option-detail/biz-option-detail-mutation.ts +59 -0
- package/server/service/biz-option-detail/biz-option-detail-query.ts +27 -0
- package/server/service/biz-option-detail/biz-option-detail-types.ts +38 -0
- package/server/service/biz-option-detail/biz-option-detail.ts +62 -0
- package/server/service/biz-option-detail/index.ts +6 -0
- package/server/service/bizplace/bizplace-mutation.ts +144 -0
- package/server/service/bizplace/bizplace-query.ts +236 -0
- package/server/service/bizplace/bizplace-types.ts +89 -0
- package/server/service/bizplace/bizplace.ts +108 -0
- package/server/service/bizplace/index.ts +6 -0
- package/server/service/company/company-mutation.ts +122 -0
- package/server/service/company/company-query.ts +70 -0
- package/server/service/company/company-types.ts +68 -0
- package/server/service/company/company.ts +105 -0
- package/server/service/company/index.ts +6 -0
- package/server/service/contact-point/contact-point-mutation.ts +165 -0
- package/server/service/contact-point/contact-point-query.ts +43 -0
- package/server/service/contact-point/contact-point-types.ts +152 -0
- package/server/service/contact-point/contact-point.ts +132 -0
- package/server/service/contact-point/index.ts +6 -0
- package/server/service/index.ts +46 -0
- package/server/service/worker/index.ts +6 -0
- package/server/service/worker/worker-mutation.ts +111 -0
- package/server/service/worker/worker-query.ts +37 -0
- package/server/service/worker/worker-types.ts +50 -0
- package/server/service/worker/worker.ts +58 -0
- package/server/utils/get-permitted-bizplaces.ts +342 -0
- package/server/utils/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/biz-base",
|
|
3
|
-
"version": "8.0.0
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/auth-base": "^8.0.0
|
|
27
|
+
"@things-factory/auth-base": "^8.0.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "07ef27d272dd9a067a9648ac7013748510556a18"
|
|
30
30
|
}
|
package/server/index.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const glob = require('glob')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
export var migrations = []
|
|
5
|
+
|
|
6
|
+
glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
|
|
7
|
+
if (file.indexOf('index.js') !== -1) return
|
|
8
|
+
migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
|
|
9
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { getRepository } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { BizOption } from './biz-option'
|
|
7
|
+
import { BizOptionPatch, NewBizOption } from './biz-option-types'
|
|
8
|
+
|
|
9
|
+
@Resolver(BizOption)
|
|
10
|
+
export class BizOptionMutation {
|
|
11
|
+
@Mutation(returns => BizOption)
|
|
12
|
+
async createBizOption(
|
|
13
|
+
@Arg('bizOption') bizOption: NewBizOption,
|
|
14
|
+
@Ctx() context: ResolverContext
|
|
15
|
+
): Promise<BizOption> {
|
|
16
|
+
const { domain, user } = context.state
|
|
17
|
+
|
|
18
|
+
return await getRepository(BizOption).save({
|
|
19
|
+
...bizOption,
|
|
20
|
+
domain: domain,
|
|
21
|
+
creator: user,
|
|
22
|
+
updater: user
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Mutation(returns => BizOption)
|
|
27
|
+
async updateBizOption(
|
|
28
|
+
@Arg('name') name: string,
|
|
29
|
+
@Arg('patch') patch: BizOptionPatch,
|
|
30
|
+
@Ctx() context: ResolverContext
|
|
31
|
+
): Promise<BizOption> {
|
|
32
|
+
const { domain, user } = context.state
|
|
33
|
+
|
|
34
|
+
const repository = getRepository(BizOption)
|
|
35
|
+
const bizOption = await repository.findOne({
|
|
36
|
+
where: { domain: { id: domain.id }, name }
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return await repository.save({
|
|
40
|
+
...bizOption,
|
|
41
|
+
...patch,
|
|
42
|
+
updater: user
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Mutation(returns => Boolean)
|
|
47
|
+
async deleteBizOption(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
48
|
+
const { domain } = context.state
|
|
49
|
+
|
|
50
|
+
await getRepository(BizOption).delete({ domain: { id: domain.id }, name })
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Mutation(returns => Boolean)
|
|
55
|
+
async deleteBizOptions(
|
|
56
|
+
@Arg('names', type => [String]) names: string[],
|
|
57
|
+
@Ctx() context: ResolverContext
|
|
58
|
+
): Promise<Boolean> {
|
|
59
|
+
await getRepository(BizOption).delete({
|
|
60
|
+
domain: { id: context.state.domain.id },
|
|
61
|
+
name: In(names)
|
|
62
|
+
})
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, Query, Resolver } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { BizOption } from './biz-option'
|
|
6
|
+
import { BizOptionList } from './biz-option-types'
|
|
7
|
+
|
|
8
|
+
@Resolver(BizOption)
|
|
9
|
+
export class BizOptionQuery {
|
|
10
|
+
@Query(returns => BizOption)
|
|
11
|
+
async bizOption(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<BizOption> {
|
|
12
|
+
return await getRepository(BizOption).findOne({
|
|
13
|
+
where: { domain: { id: context.state.domain.id }, name },
|
|
14
|
+
relations: ['domain', 'bizplace', 'bizOptionDetails', 'creator', 'updater']
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Query(returns => BizOptionList)
|
|
19
|
+
async bizOptions(
|
|
20
|
+
@Args(type => ListParam) params: ListParam,
|
|
21
|
+
@Ctx() context: ResolverContext
|
|
22
|
+
): Promise<BizOptionList> {
|
|
23
|
+
const convertedParams = convertListParams(params)
|
|
24
|
+
const [items, total] = await getRepository(BizOption).findAndCount({
|
|
25
|
+
...convertedParams,
|
|
26
|
+
relations: ['domain', 'bizplace', 'bizOptionDetails', 'creator', 'updater']
|
|
27
|
+
})
|
|
28
|
+
return { items, total }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Field, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { BizOption } from './biz-option'
|
|
6
|
+
|
|
7
|
+
@ObjectType()
|
|
8
|
+
export class BizOptionList {
|
|
9
|
+
@Field(type => [BizOption], { nullable: true })
|
|
10
|
+
items?: BizOption[]
|
|
11
|
+
|
|
12
|
+
@Field(type => Int, { nullable: true })
|
|
13
|
+
total?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@InputType()
|
|
17
|
+
export class BizOptionPatch {
|
|
18
|
+
@Field({ nullable: true })
|
|
19
|
+
id?: string
|
|
20
|
+
|
|
21
|
+
@Field({ nullable: true })
|
|
22
|
+
name?: string
|
|
23
|
+
|
|
24
|
+
@Field({ nullable: true })
|
|
25
|
+
description?: string
|
|
26
|
+
|
|
27
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
28
|
+
bizplace?: ObjectRef
|
|
29
|
+
|
|
30
|
+
@Field(type => [ObjectRef], { nullable: true })
|
|
31
|
+
bizOptionDetails?: ObjectRef[]
|
|
32
|
+
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
cuFlag?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@InputType()
|
|
38
|
+
export class NewBizOption {
|
|
39
|
+
@Field()
|
|
40
|
+
name: string
|
|
41
|
+
|
|
42
|
+
@Field({ nullable: true })
|
|
43
|
+
description?: string
|
|
44
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
Index,
|
|
7
|
+
ManyToOne,
|
|
8
|
+
OneToMany,
|
|
9
|
+
PrimaryGeneratedColumn,
|
|
10
|
+
UpdateDateColumn
|
|
11
|
+
} from 'typeorm'
|
|
12
|
+
|
|
13
|
+
import { User } from '@things-factory/auth-base'
|
|
14
|
+
import { Domain } from '@things-factory/shell'
|
|
15
|
+
|
|
16
|
+
import { BizOptionDetail } from '../biz-option-detail/biz-option-detail'
|
|
17
|
+
import { Bizplace } from '../bizplace/bizplace'
|
|
18
|
+
|
|
19
|
+
@Entity()
|
|
20
|
+
@Index('ix_biz-option_0', (bizOption: BizOption) => [bizOption.bizplace, bizOption.name], { unique: true })
|
|
21
|
+
@ObjectType()
|
|
22
|
+
export class BizOption {
|
|
23
|
+
@PrimaryGeneratedColumn('uuid')
|
|
24
|
+
@Field(type => ID)
|
|
25
|
+
id: string
|
|
26
|
+
|
|
27
|
+
@ManyToOne(type => Domain, { nullable: true })
|
|
28
|
+
@Field({ nullable: true })
|
|
29
|
+
domain: Domain
|
|
30
|
+
|
|
31
|
+
@Column()
|
|
32
|
+
@Field()
|
|
33
|
+
name: string
|
|
34
|
+
|
|
35
|
+
@ManyToOne(type => Bizplace, {
|
|
36
|
+
nullable: false
|
|
37
|
+
})
|
|
38
|
+
@Field(type => Bizplace, { nullable: true })
|
|
39
|
+
bizplace: Bizplace
|
|
40
|
+
|
|
41
|
+
@OneToMany(type => BizOptionDetail, bizOptionDetail => bizOptionDetail.bizOption)
|
|
42
|
+
@Field(type => BizOptionDetail, { nullable: true })
|
|
43
|
+
bizOptionDetails: BizOptionDetail[]
|
|
44
|
+
|
|
45
|
+
@Column({
|
|
46
|
+
nullable: true
|
|
47
|
+
})
|
|
48
|
+
@Field({ nullable: true })
|
|
49
|
+
description: string
|
|
50
|
+
|
|
51
|
+
@CreateDateColumn()
|
|
52
|
+
@Field({ nullable: true })
|
|
53
|
+
createdAt: Date
|
|
54
|
+
|
|
55
|
+
@UpdateDateColumn()
|
|
56
|
+
@Field({ nullable: true })
|
|
57
|
+
updatedAt: Date
|
|
58
|
+
|
|
59
|
+
@ManyToOne(type => User, {
|
|
60
|
+
nullable: true
|
|
61
|
+
})
|
|
62
|
+
@Field({ nullable: true })
|
|
63
|
+
creator: User
|
|
64
|
+
|
|
65
|
+
@ManyToOne(type => User, {
|
|
66
|
+
nullable: true
|
|
67
|
+
})
|
|
68
|
+
@Field({ nullable: true })
|
|
69
|
+
updater: User
|
|
70
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { getRepository } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { BizOptionDetail } from './biz-option-detail'
|
|
7
|
+
import { BizOptionDetailPatch, NewBizOptionDetail } from './biz-option-detail-types'
|
|
8
|
+
|
|
9
|
+
@Resolver(BizOptionDetail)
|
|
10
|
+
export class BizOptionDetailMutation {
|
|
11
|
+
@Mutation(returns => BizOptionDetail)
|
|
12
|
+
async createBizOptionDetail(
|
|
13
|
+
@Arg('bizOptionDetail') bizOptionDetail: NewBizOptionDetail,
|
|
14
|
+
@Ctx() context: ResolverContext
|
|
15
|
+
): Promise<BizOptionDetail> {
|
|
16
|
+
return await getRepository(BizOptionDetail).save({
|
|
17
|
+
...bizOptionDetail,
|
|
18
|
+
domain: context.state.domain,
|
|
19
|
+
creator: context.state.user,
|
|
20
|
+
updater: context.state.user
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Mutation(returns => BizOptionDetail)
|
|
25
|
+
async updateBizOptionDetail(
|
|
26
|
+
@Arg('name') name: string,
|
|
27
|
+
@Arg('patch') patch: BizOptionDetailPatch,
|
|
28
|
+
@Ctx() context: ResolverContext
|
|
29
|
+
): Promise<BizOptionDetail> {
|
|
30
|
+
const repository = getRepository(BizOptionDetail)
|
|
31
|
+
const bizOptionDetail = await repository.findOne({
|
|
32
|
+
where: { domain: { id: context.state.domain.id }, name }
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return await repository.save({
|
|
36
|
+
...bizOptionDetail,
|
|
37
|
+
...patch,
|
|
38
|
+
updater: context.state.user
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Mutation(returns => Boolean)
|
|
43
|
+
async deleteBizOptionDetail(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
44
|
+
await getRepository(BizOptionDetail).delete({ domain: { id: context.state.domain.id }, name })
|
|
45
|
+
return true
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Mutation(returns => Boolean)
|
|
49
|
+
async deleteBizOptionDetails(
|
|
50
|
+
@Arg('names', type => [String]) names: string[],
|
|
51
|
+
@Ctx() context: ResolverContext
|
|
52
|
+
): Promise<Boolean> {
|
|
53
|
+
await getRepository(BizOptionDetail).delete({
|
|
54
|
+
domain: { id: context.state.domain.id },
|
|
55
|
+
name: In(names)
|
|
56
|
+
})
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, Query, Resolver } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { BizOptionDetail } from './biz-option-detail'
|
|
6
|
+
import { BizOptionDetailList } from './biz-option-detail-types'
|
|
7
|
+
|
|
8
|
+
@Resolver(BizOptionDetail)
|
|
9
|
+
export class BizOptionDetailQuery {
|
|
10
|
+
@Query(returns => BizOptionDetail)
|
|
11
|
+
async bizOptionDetail(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<BizOptionDetail> {
|
|
12
|
+
return await getRepository(BizOptionDetail).findOne({
|
|
13
|
+
where: { domain: { id: context.state.domain.id }, name },
|
|
14
|
+
relations: ['domain', 'bizOption', 'creator', 'updater']
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Query(returns => BizOptionDetailList)
|
|
19
|
+
async bizOptionDetails(@Args(type => ListParam) params: ListParam): Promise<BizOptionDetailList> {
|
|
20
|
+
const convertedParams = convertListParams(params)
|
|
21
|
+
const [items, total] = await getRepository(BizOptionDetail).findAndCount({
|
|
22
|
+
...convertedParams,
|
|
23
|
+
relations: ['domain', 'bizOption', 'creator', 'updater']
|
|
24
|
+
})
|
|
25
|
+
return { items, total }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Field, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { BizOptionDetail } from './biz-option-detail'
|
|
6
|
+
|
|
7
|
+
@ObjectType()
|
|
8
|
+
export class BizOptionDetailList {
|
|
9
|
+
@Field(type => [BizOptionDetail], { nullable: true })
|
|
10
|
+
items?: BizOptionDetail[]
|
|
11
|
+
|
|
12
|
+
@Field(type => Int, { nullable: true })
|
|
13
|
+
total?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@InputType()
|
|
17
|
+
export class NewBizOptionDetail {
|
|
18
|
+
@Field()
|
|
19
|
+
name: string
|
|
20
|
+
|
|
21
|
+
@Field({ nullable: true })
|
|
22
|
+
description?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@InputType()
|
|
26
|
+
export class BizOptionDetailPatch {
|
|
27
|
+
@Field({ nullable: true })
|
|
28
|
+
id?: string
|
|
29
|
+
|
|
30
|
+
@Field({ nullable: true })
|
|
31
|
+
name?: string
|
|
32
|
+
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
description?: string
|
|
35
|
+
|
|
36
|
+
@Field({ nullable: true })
|
|
37
|
+
bizOption?: ObjectRef
|
|
38
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import { Column, CreateDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { User } from '@things-factory/auth-base'
|
|
5
|
+
import { Domain } from '@things-factory/shell'
|
|
6
|
+
|
|
7
|
+
import { BizOption } from '../biz-option/biz-option'
|
|
8
|
+
|
|
9
|
+
@Entity()
|
|
10
|
+
@Index(
|
|
11
|
+
'ix_biz-option-detail_0',
|
|
12
|
+
(bizOptionDetail: BizOptionDetail) => [bizOptionDetail.bizOption, bizOptionDetail.name],
|
|
13
|
+
{
|
|
14
|
+
unique: true
|
|
15
|
+
}
|
|
16
|
+
)
|
|
17
|
+
@ObjectType()
|
|
18
|
+
export class BizOptionDetail {
|
|
19
|
+
@PrimaryGeneratedColumn('uuid')
|
|
20
|
+
@Field(type => ID)
|
|
21
|
+
id: string
|
|
22
|
+
|
|
23
|
+
@ManyToOne(type => Domain, { nullable: true })
|
|
24
|
+
@Field({ nullable: true })
|
|
25
|
+
domain: Domain
|
|
26
|
+
|
|
27
|
+
@Column()
|
|
28
|
+
@Field()
|
|
29
|
+
name: string
|
|
30
|
+
|
|
31
|
+
@ManyToOne(type => BizOption, bizOption => bizOption.bizOptionDetails, {
|
|
32
|
+
nullable: false
|
|
33
|
+
})
|
|
34
|
+
@Field(type => BizOption, { nullable: true })
|
|
35
|
+
bizOption: BizOption
|
|
36
|
+
|
|
37
|
+
@Column({
|
|
38
|
+
nullable: true
|
|
39
|
+
})
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
description: string
|
|
42
|
+
|
|
43
|
+
@CreateDateColumn()
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
createdAt: Date
|
|
46
|
+
|
|
47
|
+
@UpdateDateColumn()
|
|
48
|
+
@Field({ nullable: true })
|
|
49
|
+
updatedAt: Date
|
|
50
|
+
|
|
51
|
+
@ManyToOne(type => User, {
|
|
52
|
+
nullable: true
|
|
53
|
+
})
|
|
54
|
+
@Field({ nullable: true })
|
|
55
|
+
creator: User
|
|
56
|
+
|
|
57
|
+
@ManyToOne(type => User, {
|
|
58
|
+
nullable: true
|
|
59
|
+
})
|
|
60
|
+
@Field({ nullable: true })
|
|
61
|
+
updater: User
|
|
62
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BizOptionDetail } from './biz-option-detail'
|
|
2
|
+
import { BizOptionDetailMutation } from './biz-option-detail-mutation'
|
|
3
|
+
import { BizOptionDetailQuery } from './biz-option-detail-query'
|
|
4
|
+
|
|
5
|
+
export const entities = [BizOptionDetail]
|
|
6
|
+
export const resolvers = [BizOptionDetailQuery, BizOptionDetailMutation]
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
4
|
+
import { slugger } from '@things-factory/utils'
|
|
5
|
+
|
|
6
|
+
import { Company } from '../company/company'
|
|
7
|
+
import { Bizplace } from './bizplace'
|
|
8
|
+
import { BizplacePatch, NewBizplace } from './bizplace-types'
|
|
9
|
+
|
|
10
|
+
@Resolver(Bizplace)
|
|
11
|
+
export class BizplaceMutation {
|
|
12
|
+
@Directive('@privilege(category: "bizplace", privilege: "mutation")')
|
|
13
|
+
@Mutation(returns => Bizplace)
|
|
14
|
+
async createBizplace(@Arg('bizplace') bizplace: NewBizplace, @Ctx() context: ResolverContext): Promise<Bizplace> {
|
|
15
|
+
const { domain, user } = context.state
|
|
16
|
+
if (bizplace.company && bizplace.company.id) {
|
|
17
|
+
bizplace.company = await getRepository(Company).findOneBy({ id: bizplace.company.id })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return await getRepository(Bizplace).save({
|
|
21
|
+
...bizplace,
|
|
22
|
+
domain,
|
|
23
|
+
creator: user,
|
|
24
|
+
updater: user
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Directive('@privilege(category: "bizplace", privilege: "mutation")')
|
|
29
|
+
@Mutation(returns => Bizplace)
|
|
30
|
+
async updateBizplace(
|
|
31
|
+
@Arg('name') name: string,
|
|
32
|
+
@Arg('patch') patch: BizplacePatch,
|
|
33
|
+
@Ctx() context: ResolverContext
|
|
34
|
+
): Promise<Bizplace> {
|
|
35
|
+
const { domain, user } = context.state
|
|
36
|
+
const bizplace = await getRepository(Bizplace).findOneBy({ domain: { id: domain.id }, name })
|
|
37
|
+
|
|
38
|
+
if (patch.company && patch.company.id) {
|
|
39
|
+
patch.company = await getRepository(Company).findOneBy({ id: patch.company.id })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return await getRepository(Bizplace).save({
|
|
43
|
+
...bizplace,
|
|
44
|
+
...patch,
|
|
45
|
+
updater: user
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Directive('@privilege(category: "bizplace", privilege: "mutation")')
|
|
50
|
+
@Mutation(returns => [Bizplace])
|
|
51
|
+
async updateMultipleBizplace(
|
|
52
|
+
@Arg('patches', type => [BizplacePatch]) patches: BizplacePatch[],
|
|
53
|
+
@Ctx() context: ResolverContext
|
|
54
|
+
): Promise<Bizplace[]> {
|
|
55
|
+
let results = []
|
|
56
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
57
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
58
|
+
const bizplaceRepo = getRepository(Bizplace)
|
|
59
|
+
const companyRepo = getRepository(Company)
|
|
60
|
+
|
|
61
|
+
if (_createRecords.length > 0) {
|
|
62
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
63
|
+
const newRecord = _createRecords[i]
|
|
64
|
+
|
|
65
|
+
if (newRecord.company && newRecord.company.id) {
|
|
66
|
+
newRecord.company = await companyRepo.findOneBy({ id: newRecord.company.id })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const result = await bizplaceRepo.save({
|
|
70
|
+
domain: context.state.domain,
|
|
71
|
+
creator: context.state.user,
|
|
72
|
+
updater: context.state.user,
|
|
73
|
+
...newRecord
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
results.push({ ...result, cuFlag: '+' })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (_updateRecords.length > 0) {
|
|
81
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
82
|
+
const newRecord = _updateRecords[i]
|
|
83
|
+
const bizplace = await bizplaceRepo.findOneBy({ id: newRecord.id })
|
|
84
|
+
|
|
85
|
+
if (newRecord.company && newRecord.company.id) {
|
|
86
|
+
newRecord.company = await companyRepo.findOneBy({ id: newRecord.company.id })
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const result = await bizplaceRepo.save({
|
|
90
|
+
...bizplace,
|
|
91
|
+
...newRecord,
|
|
92
|
+
updater: context.state.user
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return results
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Directive('@privilege(category: "bizplace", privilege: "mutation")')
|
|
103
|
+
@Mutation(returns => Bizplace)
|
|
104
|
+
async updateBizplaceCheckDomain(
|
|
105
|
+
@Arg('name') name: string,
|
|
106
|
+
@Arg('patch') patch: BizplacePatch,
|
|
107
|
+
@Ctx() context: ResolverContext
|
|
108
|
+
): Promise<Bizplace> {
|
|
109
|
+
let bizplace: Bizplace = await getRepository(Bizplace).findOne({ where: { name }, relations: ['domain'] })
|
|
110
|
+
let domain: Domain = bizplace.domain
|
|
111
|
+
|
|
112
|
+
if (domain) {
|
|
113
|
+
if (bizplace.name !== patch.name) {
|
|
114
|
+
domain = await getRepository(Domain).save({
|
|
115
|
+
...domain,
|
|
116
|
+
name: patch.name,
|
|
117
|
+
subdomain: slugger(patch.name)
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return await getRepository(Bizplace).save({
|
|
123
|
+
...bizplace,
|
|
124
|
+
...patch,
|
|
125
|
+
updater: context.state.user
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Directive('@privilege(category: "bizplace", privilege: "mutation")')
|
|
130
|
+
@Mutation(returns => Boolean)
|
|
131
|
+
async deleteBizplace(@Arg('id') id: string): Promise<Boolean> {
|
|
132
|
+
await getRepository(Bizplace).delete(id)
|
|
133
|
+
|
|
134
|
+
return true
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@Directive('@privilege(category: "bizplace", privilege: "mutation")')
|
|
138
|
+
@Mutation(returns => Boolean)
|
|
139
|
+
async deleteBizplaces(@Arg('ids', type => [String]) ids: string[]): Promise<Boolean> {
|
|
140
|
+
await getRepository(Bizplace).delete(ids)
|
|
141
|
+
|
|
142
|
+
return true
|
|
143
|
+
}
|
|
144
|
+
}
|