@things-factory/document-template-base 6.1.94 → 6.1.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/document-template-base",
3
- "version": "6.1.94",
3
+ "version": "6.1.96",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,10 +24,10 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/env": "^6.1.90",
28
- "@things-factory/shell": "^6.1.94",
27
+ "@things-factory/env": "^6.1.96",
28
+ "@things-factory/shell": "^6.1.96",
29
29
  "form-data": "^3.0.0",
30
30
  "node-fetch": "^2.6.0"
31
31
  },
32
- "gitHead": "d8e03a082bcb10fc9417b3d3bb18268bdb2a649c"
32
+ "gitHead": "535ca1d403d6c2d6e25314ece79f4b77d877c75b"
33
33
  }
@@ -0,0 +1,120 @@
1
+
2
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
3
+ import { In } from 'typeorm'
4
+ import { DocTemplate } from './doc-template'
5
+ import { NewDocTemplate, DocTemplatePatch } from './doc-template-type'
6
+ import { Domain, getRepository } from '@things-factory/shell'
7
+ import { User } from '@things-factory/auth-base'
8
+
9
+ @Resolver(DocTemplate)
10
+ export class DocTemplateMutation {
11
+ @Directive('@transaction')
12
+ @Mutation(returns => DocTemplate, { description: 'To create new DocTemplate' })
13
+ async createDocTemplate(@Arg('docTemplate') docTemplate: NewDocTemplate, @Ctx() context: any): Promise<DocTemplate> {
14
+ const { domain, user, tx } = context.state
15
+
16
+ return await tx.getRepository(DocTemplate).save({
17
+ ...docTemplate,
18
+ domain,
19
+ creator: user,
20
+ updater: user
21
+ })
22
+ }
23
+
24
+ @Directive('@transaction')
25
+ @Mutation(returns => DocTemplate, { description: 'To modify DocTemplate information' })
26
+ async updateDocTemplate(
27
+ @Arg('id') id: string,
28
+ @Arg('patch') patch: DocTemplatePatch,
29
+ @Ctx() context: any
30
+ ): Promise<DocTemplate> {
31
+ const { domain, user, tx } = context.state
32
+
33
+ const repository = tx.getRepository(DocTemplate)
34
+ const docTemplate = await repository.findOne(
35
+ {
36
+ where: { domain: { id: domain.id }, id },
37
+ relations: ['domain','updater','creator']
38
+ }
39
+ )
40
+
41
+ return await repository.save({
42
+ ...docTemplate,
43
+ ...patch,
44
+ updater: user
45
+ })
46
+ }
47
+
48
+ @Directive('@transaction')
49
+ @Mutation(returns => [DocTemplate], { description: "To modify multiple DocTemplates' information" })
50
+ async updateMultipleDocTemplate(
51
+ @Arg('patches', type => [DocTemplatePatch]) patches: DocTemplatePatch[],
52
+ @Ctx() context: any
53
+ ): Promise<DocTemplate[]> {
54
+ const { domain, user, tx } = context.state
55
+
56
+ let results = []
57
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
58
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
59
+ const docTemplateRepo = tx.getRepository(DocTemplate)
60
+
61
+ if (_createRecords.length > 0) {
62
+ for (let i = 0; i < _createRecords.length; i++) {
63
+ const newRecord = _createRecords[i]
64
+
65
+ const result = await docTemplateRepo.save({
66
+ ...newRecord,
67
+ domain,
68
+ creator: user,
69
+ updater: user
70
+ })
71
+
72
+ results.push({ ...result, cuFlag: '+' })
73
+ }
74
+ }
75
+
76
+ if (_updateRecords.length > 0) {
77
+ for (let i = 0; i < _updateRecords.length; i++) {
78
+ const updRecord = _updateRecords[i]
79
+ const docTemplate = await docTemplateRepo.findOne({
80
+ where: { domain: { id: domain.id }, id:updRecord.id },
81
+ relations: ['domain','updater','creator']
82
+ })
83
+
84
+ const result = await docTemplateRepo.save({
85
+ ...docTemplate,
86
+ ...updRecord,
87
+ updater: user
88
+ })
89
+
90
+ results.push({ ...result, cuFlag: 'M' })
91
+ }
92
+ }
93
+
94
+ return results
95
+ }
96
+
97
+ @Directive('@transaction')
98
+ @Mutation(returns => Boolean, { description: 'To delete DocTemplate' })
99
+ async deleteDocTemplate(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
100
+ const { domain, tx, user } = context.state
101
+ await tx.getRepository(DocTemplate).remove({ domain, id, updater:user })
102
+ return true
103
+ }
104
+
105
+ @Directive('@transaction')
106
+ @Mutation(returns => Boolean, { description: 'To delete multiple docTemplates' })
107
+ async deleteDocTemplates(
108
+ @Arg('ids', type => [String]) ids: string[],
109
+ @Ctx() context: any
110
+ ): Promise<boolean> {
111
+ const { domain, tx, user } = context.state
112
+
113
+ let delEntitis = ids.map(id => {
114
+ return {domain,id,updater:user}
115
+ })
116
+
117
+ await tx.getRepository(DocTemplate).remove(delEntitis)
118
+ return true
119
+ }
120
+ }
@@ -0,0 +1,49 @@
1
+
2
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
3
+ import { ListParam, convertListParams, getRepository, getQueryBuilderFromListParams } from '@things-factory/shell'
4
+ import { DocTemplate } from './doc-template'
5
+ import { DocTemplateList } from './doc-template-type'
6
+
7
+ import { User } from '@things-factory/auth-base'
8
+ import { Domain } from '@things-factory/shell'
9
+
10
+ @Resolver(DocTemplate)
11
+ export class DocTemplateQuery {
12
+ @Query(returns => DocTemplate, { description: 'To fetch a DocTemplate' })
13
+ async docTemplate(@Arg('id') id: string, @Ctx() context: any): Promise<DocTemplate> {
14
+ const { domain } = context.state
15
+ return await getRepository(DocTemplate).findOne({
16
+ where: { domain: { id: domain.id }, id }
17
+ })
18
+ }
19
+
20
+ @Query(returns => DocTemplateList, { description: 'To fetch multiple DocTemplates' })
21
+ async docTemplates(@Args() params: ListParam, @Ctx() context: any): Promise<DocTemplateList> {
22
+ const { domain } = context.state
23
+
24
+ const queryBuilder = getQueryBuilderFromListParams({
25
+ domain,
26
+ params,
27
+ repository: await getRepository(DocTemplate),
28
+ searchables: ['name', 'description']
29
+ })
30
+
31
+ const [items, total] = await queryBuilder.getManyAndCount()
32
+ return { items, total }
33
+ }
34
+
35
+ @FieldResolver(type => Domain)
36
+ async domain(@Root() docTemplate: DocTemplate): Promise<Domain> {
37
+ return await getRepository(Domain).findOneBy({id:docTemplate.domainId})
38
+ }
39
+
40
+ @FieldResolver(type => User)
41
+ async creator(@Root() docTemplate: DocTemplate): Promise<User> {
42
+ return await getRepository(User).findOneBy({id:docTemplate.creatorId})
43
+ }
44
+
45
+ @FieldResolver(type => User)
46
+ async updater(@Root() docTemplate: DocTemplate): Promise<User> {
47
+ return await getRepository(User).findOneBy({id:docTemplate.updaterId})
48
+ }
49
+ }
@@ -0,0 +1,80 @@
1
+
2
+ import { ObjectType, Field, InputType, Int, ID, Float, registerEnumType } from 'type-graphql'
3
+ import { ObjectRef } from '@things-factory/shell'
4
+ import { DocTemplate } from './doc-template'
5
+
6
+ @InputType()
7
+ export class NewDocTemplate {
8
+
9
+ @Field( { nullable: false })
10
+ name: string
11
+
12
+ @Field( { nullable: false })
13
+ description: string
14
+
15
+ @Field( { nullable: true })
16
+ jobType?: string
17
+
18
+ @Field( { nullable: true })
19
+ jobClass?: string
20
+
21
+ @Field( { nullable: true })
22
+ jobCategory?: string
23
+
24
+ @Field( { nullable: true })
25
+ template?: string
26
+
27
+ @Field( { nullable: true })
28
+ logic?: string
29
+
30
+ @Field( { nullable: true })
31
+ activeFlag?: boolean
32
+
33
+ @Field( { nullable: true })
34
+ note?: string
35
+ }
36
+
37
+ @InputType()
38
+ export class DocTemplatePatch {
39
+ @Field(type => ID, { nullable: true })
40
+ id?: string
41
+
42
+ @Field( { nullable: true })
43
+ name?: string
44
+
45
+ @Field( { nullable: true })
46
+ description?: string
47
+
48
+ @Field( { nullable: true })
49
+ jobType?: string
50
+
51
+ @Field( { nullable: true })
52
+ jobClass?: string
53
+
54
+ @Field( { nullable: true })
55
+ jobCategory?: string
56
+
57
+ @Field( { nullable: true })
58
+ template?: string
59
+
60
+ @Field( { nullable: true })
61
+ logic?: string
62
+
63
+ @Field( { nullable: true })
64
+ activeFlag?: boolean
65
+
66
+ @Field( { nullable: true })
67
+ note?: string
68
+
69
+ @Field()
70
+ cuFlag: string
71
+ }
72
+
73
+ @ObjectType()
74
+ export class DocTemplateList {
75
+ @Field(type => [DocTemplate])
76
+ items: DocTemplate[]
77
+
78
+ @Field(type => Int)
79
+ total: number
80
+ }
@@ -0,0 +1,90 @@
1
+
2
+ import {
3
+ CreateDateColumn,
4
+ UpdateDateColumn,
5
+ Entity,
6
+ Index,
7
+ Column,
8
+ RelationId,
9
+ ManyToOne,
10
+ PrimaryGeneratedColumn
11
+ } from 'typeorm'
12
+ import { ObjectType, Field, Int, ID, Float, registerEnumType } from 'type-graphql'
13
+
14
+ import { User } from '@things-factory/auth-base'
15
+ import { Domain } from '@things-factory/shell'
16
+
17
+ @Entity('doc_templates')
18
+ @Index('ix_doc_template_0', (docTemplate: DocTemplate) => [docTemplate.domain,docTemplate.name], { unique: true })
19
+ @Index('ix_doc_template_1', (docTemplate: DocTemplate) => [docTemplate.domain,docTemplate.activeFlag])
20
+ @ObjectType({ description: 'Entity for DocTemplate' })
21
+ export class DocTemplate {
22
+ @PrimaryGeneratedColumn('uuid')
23
+ @Field(type => ID)
24
+ readonly id: string
25
+
26
+ @Column({ name:'name', nullable:false })
27
+ @Field({ nullable:false })
28
+ name: string
29
+
30
+ @Column({ name:'description', nullable:false })
31
+ @Field({ nullable:false })
32
+ description: string
33
+
34
+ @Column({ name:'job_type', nullable:true })
35
+ @Field({ nullable:true })
36
+ jobType?: string
37
+
38
+ @Column({ name:'job_class', nullable:true })
39
+ @Field({ nullable:true })
40
+ jobClass?: string
41
+
42
+ @Column({ name:'job_category', nullable:true })
43
+ @Field({ nullable:true })
44
+ jobCategory?: string
45
+
46
+ @Column({ name:'template', type:'text', nullable:true })
47
+ @Field({ nullable:true })
48
+ template?: string
49
+
50
+ @Column({ name:'logic', type:'text', nullable:true })
51
+ @Field({ nullable:true })
52
+ logic?: string
53
+
54
+ @Column({ name:'active_flag', type:'boolean', nullable:true })
55
+ @Field({ nullable:true })
56
+ activeFlag?: boolean
57
+
58
+ @Column({ name:'note', nullable:true })
59
+ @Field({ nullable:true })
60
+ note?: string
61
+
62
+ @ManyToOne(type => Domain, {createForeignKeyConstraints: false, nullable: false})
63
+ @Field({ nullable: false })
64
+ domain: Domain
65
+
66
+ @RelationId((docTemplate: DocTemplate) => docTemplate.domain)
67
+ domainId: string
68
+
69
+ @ManyToOne(type => User, {createForeignKeyConstraints: false, nullable: true})
70
+ @Field({ nullable: true })
71
+ creator?: User
72
+
73
+ @RelationId((docTemplate: DocTemplate) => docTemplate.creator)
74
+ creatorId?: string
75
+
76
+ @ManyToOne(type => User, {createForeignKeyConstraints: false, nullable: true})
77
+ @Field({ nullable: true })
78
+ updater?: User
79
+
80
+ @RelationId((docTemplate: DocTemplate) => docTemplate.updater)
81
+ updaterId?: string
82
+
83
+ @CreateDateColumn()
84
+ @Field({ nullable: true })
85
+ createdAt?: Date
86
+
87
+ @UpdateDateColumn()
88
+ @Field({ nullable: true })
89
+ updatedAt?: Date
90
+ }
@@ -0,0 +1,7 @@
1
+
2
+ import { DocTemplate } from './doc-template'
3
+ import { DocTemplateQuery } from './doc-template-query'
4
+ import { DocTemplateMutation } from './doc-template-mutation'
5
+
6
+ export const entities = [DocTemplate]
7
+ export const resolvers = [DocTemplateQuery, DocTemplateMutation]
@@ -1,17 +1,21 @@
1
1
  /* EXPORT ENTITY TYPES */
2
+ export * from './doc-template/doc-template'
2
3
  export * from './template-file/template-file'
3
4
 
4
5
  /* IMPORT ENTITIES AND RESOLVERS */
6
+ import { entities as DocTemplateEntities, resolvers as DocTemplateResolvers } from './doc-template'
5
7
  import { entities as TemplateFileEntities, resolvers as TemplateFileResolvers } from './template-file'
6
8
 
7
9
  export const entities = [
8
10
  /* ENTITIES */
11
+ ...DocTemplateEntities,
9
12
  ...TemplateFileEntities
10
13
  ]
11
14
 
12
15
  export const schema = {
13
16
  resolverClasses: [
14
17
  /* RESOLVER CLASSES */
18
+ ...DocTemplateResolvers,
15
19
  ...TemplateFileResolvers
16
20
  ]
17
21
  }