@things-factory/i18n-base 8.0.0-beta.8 → 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/client/bootstrap.ts +16 -0
- package/client/index.ts +6 -0
- package/client/page/terminology-page.ts +408 -0
- package/client/route.ts +7 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/apis/index.ts +1 -0
- package/server/apis/t.ts +36 -0
- package/server/controllers/clear-cache-for-translation.ts +18 -0
- package/server/index.ts +6 -0
- package/server/middlewares/index.ts +36 -0
- package/server/middlewares/koa-i18next/detect.ts +108 -0
- package/server/middlewares/koa-i18next/index.ts +142 -0
- package/server/middlewares/translations.ts +27 -0
- package/server/routers/translations-router.ts +87 -0
- package/server/routes.ts +31 -0
- package/server/service/index.ts +27 -0
- package/server/service/terminology/index.ts +7 -0
- package/server/service/terminology/terminology-mutation.ts +171 -0
- package/server/service/terminology/terminology-query.ts +50 -0
- package/server/service/terminology/terminology-type.ts +54 -0
- package/server/service/terminology/terminology.ts +75 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Terminology } from './terminology'
|
|
5
|
+
import { NewTerminology, TerminologyPatch } from './terminology-type'
|
|
6
|
+
|
|
7
|
+
import { clearTranslationCacheForCertainDomain } from '../../controllers/clear-cache-for-translation'
|
|
8
|
+
|
|
9
|
+
function clearCache(subdomain: string) {
|
|
10
|
+
/** multiple update/delete시 모든 엔티티에 대해서 subscription 이 걸리므로, EventSubscriber를 사용하지 않음. */
|
|
11
|
+
try {
|
|
12
|
+
clearTranslationCacheForCertainDomain(subdomain)
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error('Failed to delete the translations cache directory:', err)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Resolver(Terminology)
|
|
19
|
+
export class TerminologyMutation {
|
|
20
|
+
@Directive('@transaction')
|
|
21
|
+
@Directive('@privilege(category: "terminology", privilege: "mutation", domainOwnerGranted: true)')
|
|
22
|
+
@Mutation(returns => Terminology, { description: 'To create new Terminology' })
|
|
23
|
+
async createTerminology(@Arg('terminology') terminology: NewTerminology, @Ctx() context: any): Promise<Terminology> {
|
|
24
|
+
const { domain, user, tx } = context.state
|
|
25
|
+
|
|
26
|
+
const result = await tx.getRepository(Terminology).save({
|
|
27
|
+
...terminology,
|
|
28
|
+
domain,
|
|
29
|
+
creator: user,
|
|
30
|
+
updater: user
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
clearCache(domain.subdomain)
|
|
34
|
+
|
|
35
|
+
return result
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Directive('@transaction')
|
|
39
|
+
@Directive('@privilege(category: "terminology", privilege: "mutation", domainOwnerGranted: true)')
|
|
40
|
+
@Mutation(returns => Terminology, { description: 'To modify Terminology information' })
|
|
41
|
+
async updateTerminology(
|
|
42
|
+
@Arg('id') id: string,
|
|
43
|
+
@Arg('patch') patch: TerminologyPatch,
|
|
44
|
+
@Ctx() context: any
|
|
45
|
+
): Promise<Terminology> {
|
|
46
|
+
const { domain, user, tx } = context.state
|
|
47
|
+
|
|
48
|
+
const repository = tx.getRepository(Terminology)
|
|
49
|
+
const terminology = await repository.findOne({
|
|
50
|
+
where: { domain: { id: domain.id }, id }
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const result = await repository.save({
|
|
54
|
+
...terminology,
|
|
55
|
+
...patch,
|
|
56
|
+
updater: user
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
clearCache(domain.subdomain)
|
|
60
|
+
|
|
61
|
+
return result
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Directive('@transaction')
|
|
65
|
+
@Directive('@privilege(category: "terminology", privilege: "mutation", domainOwnerGranted: true)')
|
|
66
|
+
@Mutation(returns => [Terminology], { description: "To modify multiple Terminologies' information" })
|
|
67
|
+
async updateMultipleTerminologies(
|
|
68
|
+
@Arg('patches', type => [TerminologyPatch]) patches: TerminologyPatch[],
|
|
69
|
+
@Ctx() context: any
|
|
70
|
+
): Promise<Terminology[]> {
|
|
71
|
+
const { domain, user, tx } = context.state
|
|
72
|
+
|
|
73
|
+
let results = []
|
|
74
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
75
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
76
|
+
const terminologyRepo = tx.getRepository(Terminology)
|
|
77
|
+
|
|
78
|
+
if (_createRecords.length > 0) {
|
|
79
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
80
|
+
const newRecord = _createRecords[i]
|
|
81
|
+
|
|
82
|
+
const result = await terminologyRepo.save({
|
|
83
|
+
...newRecord,
|
|
84
|
+
domain,
|
|
85
|
+
creator: user,
|
|
86
|
+
updater: user
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
results.push({ ...result, cuFlag: '+' })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (_updateRecords.length > 0) {
|
|
94
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
95
|
+
const newRecord = _updateRecords[i]
|
|
96
|
+
const terminology = await terminologyRepo.findOneBy({ id: newRecord.id })
|
|
97
|
+
|
|
98
|
+
const result = await terminologyRepo.save({
|
|
99
|
+
...terminology,
|
|
100
|
+
...newRecord,
|
|
101
|
+
updater: user
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
clearCache(domain.subdomain)
|
|
109
|
+
|
|
110
|
+
return results
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@Directive('@transaction')
|
|
114
|
+
@Mutation(returns => Boolean, { description: 'To clear translations cache' })
|
|
115
|
+
async clearTranslationsCache(@Ctx() context: any): Promise<boolean> {
|
|
116
|
+
const { domain, tx } = context.state
|
|
117
|
+
|
|
118
|
+
clearCache(domain.subdomain)
|
|
119
|
+
|
|
120
|
+
return true
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@Directive('@transaction')
|
|
124
|
+
@Directive('@privilege(category: "terminology", privilege: "mutation", domainOwnerGranted: true)')
|
|
125
|
+
@Mutation(returns => Boolean, { description: 'To delete Terminology' })
|
|
126
|
+
async deleteTerminology(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
|
|
127
|
+
const { domain, tx } = context.state
|
|
128
|
+
|
|
129
|
+
await tx.getRepository(Terminology).delete({ domain: { id: domain.id }, id })
|
|
130
|
+
|
|
131
|
+
clearCache(domain.subdomain)
|
|
132
|
+
|
|
133
|
+
return true
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Directive('@transaction')
|
|
137
|
+
@Directive('@privilege(category: "terminology", privilege: "mutation", domainOwnerGranted: true)')
|
|
138
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple Terminologies' })
|
|
139
|
+
async deleteTerminologies(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
|
|
140
|
+
const { domain, tx } = context.state
|
|
141
|
+
|
|
142
|
+
await tx.getRepository(Terminology).delete({
|
|
143
|
+
domain: { id: domain.id },
|
|
144
|
+
id: In(ids)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
clearCache(domain.subdomain)
|
|
148
|
+
|
|
149
|
+
return true
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Directive('@transaction')
|
|
153
|
+
@Directive('@privilege(category: "terminology", privilege: "mutation", domainOwnerGranted: true)')
|
|
154
|
+
@Mutation(returns => Boolean, { description: 'To import multiple Terminologies' })
|
|
155
|
+
async importTerminologies(
|
|
156
|
+
@Arg('terminologies', type => [TerminologyPatch]) terminologies: TerminologyPatch[],
|
|
157
|
+
@Ctx() context: any
|
|
158
|
+
): Promise<boolean> {
|
|
159
|
+
const { domain, tx } = context.state
|
|
160
|
+
|
|
161
|
+
await Promise.all(
|
|
162
|
+
terminologies.map(async (terminology: TerminologyPatch) => {
|
|
163
|
+
const createdTerminology: Terminology = await tx.getRepository(Terminology).save({ domain, ...terminology })
|
|
164
|
+
})
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
clearCache(domain.subdomain)
|
|
168
|
+
|
|
169
|
+
return true
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
4
|
+
import { User } from '@things-factory/auth-base'
|
|
5
|
+
|
|
6
|
+
import { Terminology } from './terminology'
|
|
7
|
+
import { TerminologyList } from './terminology-type'
|
|
8
|
+
|
|
9
|
+
@Resolver(Terminology)
|
|
10
|
+
export class TerminologyQuery {
|
|
11
|
+
@Query(returns => Terminology, { description: 'To fetch a Terminology' })
|
|
12
|
+
async terminology(@Arg('id') id: string, @Ctx() context: any): Promise<Terminology> {
|
|
13
|
+
const { domain } = context.state
|
|
14
|
+
|
|
15
|
+
return await getRepository(Terminology).findOne({
|
|
16
|
+
where: { domain: { id: domain.id }, id }
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Query(returns => TerminologyList, { description: 'To fetch multiple Terminologies' })
|
|
21
|
+
async terminologies(@Args(type => ListParam) params: ListParam, @Ctx() context: any): Promise<TerminologyList> {
|
|
22
|
+
const { domain } = context.state
|
|
23
|
+
|
|
24
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
25
|
+
domain,
|
|
26
|
+
params,
|
|
27
|
+
repository: await getRepository(Terminology),
|
|
28
|
+
searchables: ['name', 'category', 'display']
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
32
|
+
|
|
33
|
+
return { items, total }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@FieldResolver(type => Domain)
|
|
37
|
+
async domain(@Root() terminology: Terminology): Promise<Domain> {
|
|
38
|
+
return await getRepository(Domain).findOneBy({ id: terminology.domainId })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@FieldResolver(type => User)
|
|
42
|
+
async updater(@Root() terminology: Terminology): Promise<User> {
|
|
43
|
+
return await getRepository(User).findOneBy({ id: terminology.updaterId })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@FieldResolver(type => User)
|
|
47
|
+
async creator(@Root() terminology: Terminology): Promise<User> {
|
|
48
|
+
return await getRepository(User).findOneBy({ id: terminology.creatorId })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Terminology } from './terminology'
|
|
4
|
+
|
|
5
|
+
@InputType()
|
|
6
|
+
export class NewTerminology {
|
|
7
|
+
@Field()
|
|
8
|
+
name: string
|
|
9
|
+
|
|
10
|
+
@Field({ nullable: true })
|
|
11
|
+
description?: string
|
|
12
|
+
|
|
13
|
+
@Field()
|
|
14
|
+
locale: string
|
|
15
|
+
|
|
16
|
+
@Field()
|
|
17
|
+
category: string
|
|
18
|
+
|
|
19
|
+
@Field()
|
|
20
|
+
display: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@InputType()
|
|
24
|
+
export class TerminologyPatch {
|
|
25
|
+
@Field(type => ID, { nullable: true })
|
|
26
|
+
id?: string
|
|
27
|
+
|
|
28
|
+
@Field({ nullable: true })
|
|
29
|
+
name?: string
|
|
30
|
+
|
|
31
|
+
@Field({ nullable: true })
|
|
32
|
+
description?: string
|
|
33
|
+
|
|
34
|
+
@Field({ nullable: true })
|
|
35
|
+
locale?: string
|
|
36
|
+
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
category?: string
|
|
39
|
+
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
display?: string
|
|
42
|
+
|
|
43
|
+
@Field({ nullable: true })
|
|
44
|
+
cuFlag?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ObjectType()
|
|
48
|
+
export class TerminologyList {
|
|
49
|
+
@Field(type => [Terminology])
|
|
50
|
+
items: Terminology[]
|
|
51
|
+
|
|
52
|
+
@Field(type => Int)
|
|
53
|
+
total: number
|
|
54
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
Index,
|
|
7
|
+
ManyToOne,
|
|
8
|
+
PrimaryGeneratedColumn,
|
|
9
|
+
RelationId,
|
|
10
|
+
UpdateDateColumn
|
|
11
|
+
} from 'typeorm'
|
|
12
|
+
|
|
13
|
+
import { Domain } from '@things-factory/shell'
|
|
14
|
+
import { User } from '@things-factory/auth-base'
|
|
15
|
+
|
|
16
|
+
@Entity()
|
|
17
|
+
@ObjectType({ description: 'Entity for Terminology' })
|
|
18
|
+
@Index('ix_term_0', (term: Terminology) => [term.domain, term.locale, term.category, term.name], { unique: true })
|
|
19
|
+
@Index('ix_term_1', (term: Terminology) => [term.domain])
|
|
20
|
+
@Index('ix_term_2', (term: Terminology) => [term.domain, term.locale])
|
|
21
|
+
@Index('ix_term_3', (term: Terminology) => [term.domain, term.locale, term.name])
|
|
22
|
+
export class Terminology {
|
|
23
|
+
@PrimaryGeneratedColumn('uuid')
|
|
24
|
+
@Field(type => ID)
|
|
25
|
+
readonly id: string
|
|
26
|
+
|
|
27
|
+
@ManyToOne(type => Domain)
|
|
28
|
+
@Field(type => Domain)
|
|
29
|
+
domain?: Domain
|
|
30
|
+
|
|
31
|
+
@RelationId((terminology: Terminology) => terminology.domain)
|
|
32
|
+
domainId?: string
|
|
33
|
+
|
|
34
|
+
@Column()
|
|
35
|
+
@Field()
|
|
36
|
+
name?: string
|
|
37
|
+
|
|
38
|
+
@Column({ nullable: true })
|
|
39
|
+
@Field({ nullable: true })
|
|
40
|
+
description?: string
|
|
41
|
+
|
|
42
|
+
@Field()
|
|
43
|
+
@Column({ length: 20 })
|
|
44
|
+
locale?: string
|
|
45
|
+
|
|
46
|
+
@Field()
|
|
47
|
+
@Column({ length: 20 })
|
|
48
|
+
category?: string
|
|
49
|
+
|
|
50
|
+
@Field()
|
|
51
|
+
@Column()
|
|
52
|
+
display?: string
|
|
53
|
+
|
|
54
|
+
@CreateDateColumn()
|
|
55
|
+
@Field({ nullable: true })
|
|
56
|
+
createdAt?: Date
|
|
57
|
+
|
|
58
|
+
@UpdateDateColumn()
|
|
59
|
+
@Field({ nullable: true })
|
|
60
|
+
updatedAt?: Date
|
|
61
|
+
|
|
62
|
+
@ManyToOne(type => User, { nullable: true })
|
|
63
|
+
@Field(type => User, { nullable: true })
|
|
64
|
+
creator?: User
|
|
65
|
+
|
|
66
|
+
@RelationId((terminology: Terminology) => terminology.creator)
|
|
67
|
+
creatorId?: string
|
|
68
|
+
|
|
69
|
+
@ManyToOne(type => User, { nullable: true })
|
|
70
|
+
@Field(type => User, { nullable: true })
|
|
71
|
+
updater?: User
|
|
72
|
+
|
|
73
|
+
@RelationId((terminology: Terminology) => terminology.updater)
|
|
74
|
+
updaterId?: string
|
|
75
|
+
}
|