@things-factory/id-rule-base 8.0.0 → 9.0.0-beta.3

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.
@@ -1,142 +0,0 @@
1
- import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
- import { ListParam, convertListParams, getRepository, getQueryBuilderFromListParams } from '@things-factory/shell'
3
- import { DocNumber } from './doc-number'
4
- import { DocNumberList } from './doc-number-type'
5
-
6
- import { User } from '@things-factory/auth-base'
7
- import { Domain } from '@things-factory/shell'
8
-
9
- @Resolver(DocNumber)
10
- export class DocNumberQuery {
11
- @Query(returns => DocNumber, { description: 'To fetch a DocNumber' })
12
- async docNumber(@Arg('id') id: string, @Ctx() context: any): Promise<DocNumber> {
13
- const { domain } = context.state
14
- return await getRepository(DocNumber).findOne({
15
- where: { domain: { id: domain.id }, id }
16
- })
17
- }
18
-
19
- @Query(returns => DocNumberList, { description: 'To fetch multiple DocNumbers' })
20
- async docNumbers(@Args(type => ListParam) params: ListParam, @Ctx() context: any): Promise<DocNumberList> {
21
- const { domain } = context.state
22
-
23
- const queryBuilder = getQueryBuilderFromListParams({
24
- domain,
25
- params,
26
- repository: await getRepository(DocNumber),
27
- searchables: ['code', 'description']
28
- })
29
-
30
- const [items, total] = await queryBuilder.getManyAndCount()
31
- return { items, total }
32
- }
33
-
34
- @Query(returns => DocNumber, { description: 'To generate a new DocNumber' })
35
- async getNewDocNumber(@Arg('id') id: string, @Ctx() context: any): Promise<DocNumber> {
36
- const { domain } = context.state
37
-
38
- // 1. find one by id - TODO by Lock
39
- let docNumber = await getRepository(DocNumber).findOne({
40
- where: { domain: { id: domain.id }, id }
41
- })
42
-
43
- // 2. find one by code - TODO by Lock
44
- if (docNumber == null) {
45
- docNumber = await getRepository(DocNumber).findOne({
46
- where: { domain: { id: domain.id }, code: id }
47
- })
48
- }
49
-
50
- // 3. TODO throw exception
51
- if (docNumber == null) {
52
- return null
53
- }
54
-
55
- // 4. 시퀀스 증가
56
- let newDocNum = docNumber.currentNo
57
-
58
- if (docNumber.useDbSeqFlag) {
59
- // TODO DATABASE SEQUENCE 호출
60
- newDocNum += 1
61
- } else {
62
- newDocNum = docNumber.currentNo ? docNumber.currentNo + 1 : 1
63
- }
64
-
65
- // 5. 문서 번호 expression 구성
66
- if (!docNumber.expression) {
67
- docNumber.updateExpression()
68
- }
69
-
70
- let expression = docNumber.expression
71
-
72
- // 6. 시퀀스 번호 사이클 처리
73
- if (newDocNum > docNumber.endNo) {
74
- newDocNum = docNumber.startNo
75
- }
76
-
77
- // 7. 자리수 설정
78
- let newDocNoStr = newDocNum.toString()
79
- let docNumLength = newDocNoStr.length
80
- let docNoDigit = docNumber.seqDigitNum ? docNumber.seqDigitNum : 1
81
-
82
- // 8. 시퀀스 번호가 시퀀스 번호 사이즈보다 작은 경우 앞에 0을 붙임
83
- if (docNoDigit > docNumLength) {
84
- let addZeroCnt = docNoDigit - docNumLength
85
- for (let i = 0; i < addZeroCnt; i++) {
86
- newDocNoStr = '0' + newDocNoStr
87
- }
88
- }
89
-
90
- // 9. 문서 번호 구성
91
- let newDocNumber = expression.replace('${SEQ}', newDocNoStr)
92
- let docUpdateInterval = docNumber.updateInterval
93
- if (docUpdateInterval && docUpdateInterval != 'NONE') {
94
- const today = new Date()
95
- let todayStr =
96
- today.getFullYear() +
97
- (today.getMonth() > 9 ? '' + today.getMonth() + 1 : '0' + today.getMonth() + 1) +
98
- today.getDate()
99
- let intervalVal = ''
100
-
101
- if (docUpdateInterval == 'yy') {
102
- intervalVal = todayStr.substring(2, 4)
103
- } else if (docUpdateInterval == 'yyyy') {
104
- intervalVal = todayStr.substring(0, 4)
105
- } else if (docUpdateInterval == 'yyMM') {
106
- intervalVal = todayStr.substring(2, 6)
107
- } else if (docUpdateInterval == 'yyyyMM') {
108
- intervalVal = todayStr.substring(0, 6)
109
- } else if (docUpdateInterval == 'yyMMdd') {
110
- intervalVal = todayStr.substring(2, 8)
111
- } else if (docUpdateInterval == 'yyyyMMdd') {
112
- intervalVal = todayStr
113
- }
114
-
115
- newDocNumber = newDocNumber.replace('${' + docUpdateInterval + '}', intervalVal)
116
- }
117
-
118
- // 10. 현재 시퀀스 번호 저장
119
- docNumber.domain = domain
120
- docNumber.currentNo = newDocNum
121
- docNumber.lastDocNumber = newDocNumber
122
- await getRepository(DocNumber).save(docNumber)
123
-
124
- // 11. 최종
125
- return docNumber
126
- }
127
-
128
- @FieldResolver(type => Domain)
129
- async domain(@Root() docNumber: DocNumber): Promise<Domain> {
130
- return await getRepository(Domain).findOneBy({ id: docNumber.domainId })
131
- }
132
-
133
- @FieldResolver(type => User)
134
- async creator(@Root() docNumber: DocNumber): Promise<User> {
135
- return await getRepository(User).findOneBy({ id: docNumber.creatorId })
136
- }
137
-
138
- @FieldResolver(type => User)
139
- async updater(@Root() docNumber: DocNumber): Promise<User> {
140
- return await getRepository(User).findOneBy({ id: docNumber.updaterId })
141
- }
142
- }
@@ -1,115 +0,0 @@
1
-
2
- import { ObjectType, Field, InputType, Int, ID, Float, registerEnumType } from 'type-graphql'
3
- import { DocNumber } from './doc-number'
4
-
5
- @InputType()
6
- export class NewDocNumber {
7
-
8
- @Field({ nullable: false })
9
- code: string
10
-
11
- @Field({ nullable: false })
12
- description: string
13
-
14
- @Field(type => Int, { nullable: true })
15
- startNo: number
16
-
17
- @Field(type => Int, { nullable: true })
18
- endNo: number
19
-
20
- @Field(type => Int, { nullable: true })
21
- currentNo?: number
22
-
23
- @Field({ nullable:true })
24
- prefix?: string
25
-
26
- @Field({ nullable:true })
27
- suffix?: string
28
-
29
- @Field({ nullable: true })
30
- updateInterval?: string
31
-
32
- @Field({ nullable: true })
33
- useDbSeqFlag?: boolean
34
-
35
- @Field({ nullable: false })
36
- seqName: string
37
-
38
- @Field(type => Int, { nullable: true })
39
- seqDigitNum?: number
40
-
41
- @Field({ nullable: true })
42
- separator?: string
43
-
44
- @Field({ nullable: true })
45
- expression?: string
46
-
47
- @Field({ nullable: true })
48
- lastDocNumber?: string
49
-
50
- @Field({ nullable: true })
51
- activeFlag?: boolean
52
- }
53
-
54
- @InputType()
55
- export class DocNumberPatch {
56
- @Field(type => ID, { nullable: true })
57
- id?: string
58
-
59
- @Field({ nullable: true })
60
- code?: string
61
-
62
- @Field({ nullable: true })
63
- description?: string
64
-
65
- @Field(type => Int, { nullable: true })
66
- startNo?: number
67
-
68
- @Field(type => Int, { nullable: true })
69
- endNo?: number
70
-
71
- @Field(type => Int, { nullable: true })
72
- currentNo?: number
73
-
74
- @Field({ nullable:true })
75
- prefix?: string
76
-
77
- @Field({ nullable:true })
78
- suffix?: string
79
-
80
- @Field({ nullable: true })
81
- updateInterval?: string
82
-
83
- @Field({ nullable: true })
84
- useDbSeqFlag?: boolean
85
-
86
- @Field({ nullable: true })
87
- seqName?: string
88
-
89
- @Field(type => Int, { nullable: true })
90
- seqDigitNum?: number
91
-
92
- @Field({ nullable: true })
93
- separator?: string
94
-
95
- @Field({ nullable: true })
96
- expression?: string
97
-
98
- @Field({ nullable: true })
99
- lastDocNumber?: string
100
-
101
- @Field({ nullable: true })
102
- activeFlag?: boolean
103
-
104
- @Field()
105
- cuFlag: string
106
- }
107
-
108
- @ObjectType()
109
- export class DocNumberList {
110
- @Field(type => [DocNumber])
111
- items: DocNumber[]
112
-
113
- @Field(type => Int)
114
- total: number
115
- }
@@ -1,160 +0,0 @@
1
- import {
2
- CreateDateColumn,
3
- UpdateDateColumn,
4
- Entity,
5
- Index,
6
- Column,
7
- RelationId,
8
- ManyToOne,
9
- PrimaryGeneratedColumn,
10
- BeforeInsert
11
- } from 'typeorm'
12
- import { ObjectType, Field, Int, ID } from 'type-graphql'
13
-
14
- import { User } from '@things-factory/auth-base'
15
- import { Domain } from '@things-factory/shell'
16
-
17
- @Entity('doc_numbers')
18
- @Index('ix_doc_number_0', (docNumber: DocNumber) => [docNumber.domain, docNumber.code], { unique: true })
19
- @ObjectType({ description: 'Entity for DocNumber' })
20
- export class DocNumber {
21
- @PrimaryGeneratedColumn('uuid')
22
- @Field(type => ID)
23
- readonly id: string
24
-
25
- @Column()
26
- @Field()
27
- code: string
28
-
29
- @Column()
30
- @Field()
31
- description: string
32
-
33
- @Column({ nullable: true })
34
- @Field({ nullable: true })
35
- prefix?: string
36
-
37
- @Column({ nullable: true })
38
- @Field({ nullable: true })
39
- suffix?: string
40
-
41
- @Column({ type: 'integer', nullable: true })
42
- @Field(type => Int, { nullable: true })
43
- startNo?: number
44
-
45
- @Column({ type: 'integer', nullable: true })
46
- @Field(type => Int, { nullable: true })
47
- endNo?: number
48
-
49
- @Column({ type: 'integer', nullable: true })
50
- @Field(type => Int, { nullable: true })
51
- currentNo?: number
52
-
53
- @Column({ nullable: true })
54
- @Field({ nullable: true })
55
- updateInterval?: string
56
-
57
- @Column({ nullable: true, default: false })
58
- @Field({ nullable: true })
59
- useDbSeqFlag?: boolean
60
-
61
- @Column({ nullable: true })
62
- @Field({ nullable: true })
63
- seqName?: string
64
-
65
- @Column({ type: 'integer', nullable: false })
66
- @Field(type => Int, { nullable: false })
67
- seqDigitNum: number
68
-
69
- @Column({ nullable: true })
70
- @Field({ nullable: true })
71
- separator?: string
72
-
73
- @Column({ nullable: true })
74
- @Field({ nullable: true })
75
- expression?: string
76
-
77
- @Column({ nullable: true })
78
- @Field({ nullable: true })
79
- lastDocNumber?: string
80
-
81
- @Column({ type: 'boolean', nullable: true, default: false })
82
- @Field({ nullable: true })
83
- activeFlag?: boolean
84
-
85
- @ManyToOne(type => Domain, { createForeignKeyConstraints: false, nullable: false })
86
- @Field({ nullable: false })
87
- domain: Domain
88
-
89
- @RelationId((docNumber: DocNumber) => docNumber.domain)
90
- domainId: string
91
-
92
- @ManyToOne(type => User, { createForeignKeyConstraints: false, nullable: true })
93
- @Field(type => User, { nullable: true })
94
- creator?: User
95
-
96
- @RelationId((docNumber: DocNumber) => docNumber.creator)
97
- creatorId?: string
98
-
99
- @ManyToOne(type => User, { createForeignKeyConstraints: false, nullable: true })
100
- @Field(type => User, { nullable: true })
101
- updater?: User
102
-
103
- @RelationId((docNumber: DocNumber) => docNumber.updater)
104
- updaterId?: string
105
-
106
- @CreateDateColumn()
107
- @Field({ nullable: true })
108
- createdAt?: Date
109
-
110
- @UpdateDateColumn()
111
- @Field({ nullable: true })
112
- updatedAt?: Date
113
-
114
- @BeforeInsert()
115
- updateExpression() {
116
- if (!this.expression || this.expression.length == 0) {
117
- if (!this.startNo || this.startNo < 1) {
118
- this.startNo = 1
119
- }
120
-
121
- if (!this.endNo || this.endNo <= 1) {
122
- let maxNo = ''
123
- for (let i = 0; i < this.seqDigitNum; i++) {
124
- maxNo = maxNo + '9'
125
- }
126
- this.endNo = Number(maxNo)
127
- }
128
-
129
- let expr = ''
130
-
131
- if (this.prefix) {
132
- expr = this.prefix
133
-
134
- if (this.separator) {
135
- expr += this.separator
136
- }
137
- }
138
-
139
- if (this.updateInterval && this.updateInterval != 'NONE') {
140
- expr += '${' + this.updateInterval + '}'
141
-
142
- if (this.separator) {
143
- expr += this.separator
144
- }
145
- }
146
-
147
- expr += '${SEQ}'
148
-
149
- if (this.suffix) {
150
- if (this.separator) {
151
- expr += this.separator
152
- }
153
-
154
- expr += this.suffix
155
- }
156
-
157
- this.expression = expr
158
- }
159
- }
160
- }
@@ -1,7 +0,0 @@
1
-
2
- import { DocNumber } from './doc-number'
3
- import { DocNumberQuery } from './doc-number-query'
4
- import { DocNumberMutation } from './doc-number-mutation'
5
-
6
- export const entities = [DocNumber]
7
- export const resolvers = [DocNumberQuery, DocNumberMutation]
@@ -1,34 +0,0 @@
1
- import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
2
-
3
- import { getRepository } from '@things-factory/shell'
4
-
5
- import { IdRule } from './id-rule'
6
- import { IdRulePatch, NewIdRule } from './id-rule-types'
7
-
8
- @Resolver(IdRule)
9
- export class IdRuleMutation {
10
- @Mutation(returns => IdRule)
11
- async createIdRule(@Arg('idRule') idRule: NewIdRule, @Ctx() context: any) {
12
- return await getRepository(IdRule).save({
13
- ...idRule,
14
- domain: context.state.domain
15
- })
16
- }
17
-
18
- @Mutation(returns => IdRule)
19
- async updateIdRule(
20
- @Arg('type') type: string,
21
- @Arg('patch') patch: IdRulePatch,
22
- @Ctx() context: any
23
- ): Promise<IdRule> {
24
- const repository = getRepository(IdRule)
25
- const idRule = await repository.findOne({
26
- where: { type: type as any, domain: { id: context.state.domain.id } }
27
- })
28
-
29
- return await repository.save({
30
- ...idRule,
31
- ...patch
32
- })
33
- }
34
- }
@@ -1,25 +0,0 @@
1
- import { Arg, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
-
3
- import { Domain, getRepository } from '@things-factory/shell'
4
-
5
- import { IdRule } from './id-rule'
6
-
7
- @Resolver(IdRule)
8
- export class IdRuleQuery {
9
- @Query(returns => IdRule, { nullable: true })
10
- async idRule(@Arg('type') type: string, @Ctx() context: any): Promise<IdRule> {
11
- const rule = await getRepository(IdRule).findOne({
12
- where: {
13
- domain: { id: context.state.domain.id },
14
- type: type as any
15
- }
16
- })
17
-
18
- return rule
19
- }
20
-
21
- @FieldResolver(type => Domain)
22
- async domain(@Root() idRule: IdRule) {
23
- return await getRepository(Domain).findOneBy({ id: idRule.domainId })
24
- }
25
- }
@@ -1,20 +0,0 @@
1
- import { Field, InputType } from 'type-graphql'
2
-
3
-
4
- @InputType()
5
- export class IdRulePatch {
6
- @Field({ nullable: true })
7
- type?: string
8
-
9
- @Field({ nullable: true })
10
- rule?: string
11
- }
12
-
13
- @InputType()
14
- export class NewIdRule {
15
- @Field()
16
- type: string
17
-
18
- @Field()
19
- rule: string
20
- }
@@ -1,49 +0,0 @@
1
- import {
2
- Field,
3
- ID,
4
- ObjectType
5
- } from 'type-graphql'
6
- import {
7
- Column,
8
- CreateDateColumn,
9
- Entity,
10
- Index,
11
- ManyToOne,
12
- PrimaryGeneratedColumn,
13
- RelationId,
14
- UpdateDateColumn
15
- } from 'typeorm'
16
-
17
- import { Domain } from '@things-factory/shell'
18
-
19
- @Entity()
20
- @Index('ix_id_rule_1', (idRule: IdRule) => [idRule.domain])
21
- @ObjectType()
22
- export class IdRule {
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((idRule: IdRule) => idRule.domain)
32
- domainId: string
33
-
34
- @Column()
35
- @Field({ nullable: true })
36
- type: string
37
-
38
- @Column()
39
- @Field()
40
- rule: string
41
-
42
- @CreateDateColumn()
43
- @Field({ nullable: true })
44
- createdAt: Date
45
-
46
- @UpdateDateColumn()
47
- @Field({ nullable: true })
48
- updatedAt: Date
49
- }
@@ -1,6 +0,0 @@
1
- import { IdRule } from './id-rule'
2
- import { IdRuleMutation } from './id-rule-mutation'
3
- import { IdRuleQuery } from './id-rule-query'
4
-
5
- export const entities = [IdRule]
6
- export const resolvers = [IdRuleQuery, IdRuleMutation]
@@ -1,16 +0,0 @@
1
- import { entities as IdRuleEntities, resolvers as IdRuleResolvers } from './id-rule'
2
- import { entities as SequenceEntities, resolvers as SequenceResolvers } from './sequence'
3
- import { entities as DocNumberEntities, resolvers as DocNumberResolvers } from './doc-number'
4
-
5
- /* EXPORT ENTITY TYPES */
6
- export * from './id-rule/id-rule'
7
- /* EXPORT TYPES */
8
- export * from './id-rule/id-rule-types'
9
- export * from './sequence/sequence'
10
- export * from './doc-number/doc-number'
11
-
12
- export const entities = [...IdRuleEntities, ...SequenceEntities, ...DocNumberEntities]
13
-
14
- export const schema = {
15
- resolverClasses: [...IdRuleResolvers, ...SequenceResolvers, ...DocNumberResolvers]
16
- }
@@ -1,5 +0,0 @@
1
- import { Sequence } from './sequence'
2
- import { SequenceMutation } from './sequence-mutation'
3
-
4
- export const entities = [Sequence]
5
- export const resolvers = [SequenceMutation]
@@ -1,56 +0,0 @@
1
- import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
2
-
3
- import { getRepository } from '@things-factory/shell'
4
-
5
- import { SEQUENCE_TYPE } from '../../constants'
6
- import { Sequence } from './sequence'
7
-
8
- @Resolver(Sequence)
9
- export class SequenceMutation {
10
- @Mutation(returns => Sequence)
11
- async upsertSequence(
12
- @Arg('type') type: string,
13
- @Arg('counter') counter: number,
14
- @Arg('bizplaceId') bizplaceId: string,
15
- @Ctx() context: any
16
- ) {
17
- const { domain } = context.state
18
- const seqRepo = getRepository(Sequence)
19
- const now = new Date()
20
- const expiresAt = new Date(now.setMonth(now.getMonth() + 12))
21
-
22
- const patternObj: any = {
23
- type,
24
- date: new Date().toISOString().split('T')[0],
25
- bizplaceId
26
- }
27
-
28
- const pattern: string = JSON.stringify(patternObj)
29
-
30
- const foundSeq = await seqRepo.findOne({
31
- where: { pattern, type: SEQUENCE_TYPE.PRODUCT_LABEL_COUNTER, domain: { id: domain.id } }
32
- })
33
-
34
- if (foundSeq) {
35
- await seqRepo.update(
36
- { id: foundSeq.id },
37
- {
38
- pattern,
39
- seq: counter ? foundSeq.seq + counter : foundSeq.seq + 1,
40
- expiresAt,
41
- updatedAt: now
42
- }
43
- )
44
-
45
- return await seqRepo.findOneBy({ id: foundSeq.id })
46
- } else {
47
- return await seqRepo.save({
48
- domain,
49
- pattern,
50
- seq: counter || 1,
51
- expiresAt,
52
- type: SEQUENCE_TYPE.PRODUCT_LABEL_COUNTER
53
- })
54
- }
55
- }
56
- }
@@ -1,49 +0,0 @@
1
- import { Field, ID, ObjectType } from 'type-graphql'
2
- import { Column, CreateDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'
3
-
4
- import { Domain } from '@things-factory/shell'
5
-
6
- @Entity()
7
- @Index('ix_sequence_0', (seq: Sequence) => [seq.domain, seq.pattern], { unique: true })
8
- @Index('ix_sequence_1', (seq: Sequence) => [seq.pattern])
9
- @Index('ix_sequence_2', (seq: Sequence) => [seq.expiresAt])
10
- @ObjectType()
11
- export class Sequence {
12
- @PrimaryGeneratedColumn('uuid')
13
- @Field(type => ID)
14
- readonly id: string
15
-
16
- @ManyToOne(type => Domain)
17
- @Field(type => Domain)
18
- domain: Domain
19
-
20
- @RelationId((sequence: Sequence) => sequence.domain)
21
- domainId?: string
22
-
23
- @Column()
24
- @Field()
25
- pattern: string
26
-
27
- @Column({
28
- type: 'smallint'
29
- })
30
- @Field()
31
- seq: number
32
-
33
- //// to differentiate between normal pattern sequence VS label counter ////
34
- @Column({ nullable: true })
35
- @Field()
36
- type: string
37
-
38
- @Column({ nullable: true })
39
- @Field()
40
- expiresAt: Date
41
-
42
- @CreateDateColumn()
43
- @Field({ nullable: true })
44
- createdAt: Date
45
-
46
- @UpdateDateColumn()
47
- @Field({ nullable: true })
48
- updatedAt: Date
49
- }