@things-factory/id-rule-base 8.0.0-beta.9 → 8.0.2
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 +8 -0
- package/client/editors/grist-code-input-popup.ts +196 -0
- package/client/editors/grist-code-input.ts +121 -0
- package/client/index.ts +0 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/server/constants/index.ts +1 -0
- package/server/constants/sequence-type.ts +3 -0
- package/server/controllers/id-generator.ts +75 -0
- package/server/controllers/index.ts +1 -0
- package/server/index.ts +6 -0
- package/server/migrations/index.ts +9 -0
- package/server/routes.ts +25 -0
- package/server/service/doc-number/doc-number-mutation.ts +121 -0
- package/server/service/doc-number/doc-number-query.ts +142 -0
- package/server/service/doc-number/doc-number-type.ts +115 -0
- package/server/service/doc-number/doc-number.ts +160 -0
- package/server/service/doc-number/index.ts +7 -0
- package/server/service/id-rule/id-rule-mutation.ts +34 -0
- package/server/service/id-rule/id-rule-query.ts +25 -0
- package/server/service/id-rule/id-rule-types.ts +20 -0
- package/server/service/id-rule/id-rule.ts +49 -0
- package/server/service/id-rule/index.ts +6 -0
- package/server/service/index.ts +16 -0
- package/server/service/sequence/index.ts +5 -0
- package/server/service/sequence/sequence-mutation.ts +56 -0
- package/server/service/sequence/sequence.ts +49 -0
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|