@things-factory/document-template-base 6.1.81 → 6.1.88

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.81",
3
+ "version": "6.1.88",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -25,9 +25,9 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@things-factory/env": "^6.1.79",
28
- "@things-factory/shell": "^6.1.81",
28
+ "@things-factory/shell": "^6.1.84",
29
29
  "form-data": "^3.0.0",
30
30
  "node-fetch": "^2.6.0"
31
31
  },
32
- "gitHead": "cf39cd5eb29e1abd83a71a66fbe797409b560282"
32
+ "gitHead": "c532b48aaef9dc9fca4182e38333de8fcb87e4e0"
33
33
  }
package/server/index.ts CHANGED
@@ -2,3 +2,4 @@ import './routes'
2
2
 
3
3
  export * from './constants'
4
4
  export * from './controllers'
5
+ export * from './service'
@@ -0,0 +1,21 @@
1
+ /* EXPORT ENTITY TYPES */
2
+ export * from './template-file/template-file'
3
+
4
+ /* IMPORT ENTITIES AND RESOLVERS */
5
+ import { entities as TemplateFileEntities, resolvers as TemplateFileResolvers } from './template-file'
6
+
7
+ export const entities = [
8
+ /* ENTITIES */
9
+ ...TemplateFileEntities
10
+ ]
11
+
12
+ export const schema = {
13
+ resolverClasses: [
14
+ /* RESOLVER CLASSES */
15
+ ...TemplateFileResolvers
16
+ ]
17
+ }
18
+
19
+ export const subscribers = [
20
+ /* SUBSCRIBERS */
21
+ ]
@@ -0,0 +1,7 @@
1
+
2
+ import { TemplateFile } from './template-file'
3
+ import { TemplateFileQuery } from './template-file-query'
4
+ import { TemplateFileMutation } from './template-file-mutation'
5
+
6
+ export const entities = [TemplateFile]
7
+ export const resolvers = [TemplateFileQuery, TemplateFileMutation]
@@ -0,0 +1,117 @@
1
+
2
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
3
+ import { TemplateFile } from './template-file'
4
+ import { NewTemplateFile, TemplateFilePatch } from './template-file-type'
5
+
6
+ @Resolver(TemplateFile)
7
+ export class TemplateFileMutation {
8
+ @Directive('@transaction')
9
+ @Mutation(returns => TemplateFile, { description: 'To create new TemplateFile' })
10
+ async createTemplateFile(@Arg('templateFile') templateFile: NewTemplateFile, @Ctx() context: any): Promise<TemplateFile> {
11
+ const { domain, user, tx } = context.state
12
+
13
+ return await tx.getRepository(TemplateFile).save({
14
+ ...templateFile,
15
+ domain,
16
+ creator: user,
17
+ updater: user
18
+ })
19
+ }
20
+
21
+ @Directive('@transaction')
22
+ @Mutation(returns => TemplateFile, { description: 'To modify TemplateFile information' })
23
+ async updateTemplateFile(
24
+ @Arg('id') id: string,
25
+ @Arg('patch') patch: TemplateFilePatch,
26
+ @Ctx() context: any
27
+ ): Promise<TemplateFile> {
28
+ const { domain, user, tx } = context.state
29
+
30
+ const repository = tx.getRepository(TemplateFile)
31
+ const templateFile = await repository.findOne(
32
+ {
33
+ where: { domain: { id: domain.id }, id },
34
+ relations: ['domain','updater','creator','attachment']
35
+ }
36
+ )
37
+
38
+ return await repository.save({
39
+ ...templateFile,
40
+ ...patch,
41
+ updater: user
42
+ })
43
+ }
44
+
45
+ @Directive('@transaction')
46
+ @Mutation(returns => [TemplateFile], { description: "To modify multiple TemplateFiles' information" })
47
+ async updateMultipleTemplateFile(
48
+ @Arg('patches', type => [TemplateFilePatch]) patches: TemplateFilePatch[],
49
+ @Ctx() context: any
50
+ ): Promise<TemplateFile[]> {
51
+ const { domain, user, tx } = context.state
52
+
53
+ let results = []
54
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
55
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
56
+ const templateFileRepo = tx.getRepository(TemplateFile)
57
+
58
+ if (_createRecords.length > 0) {
59
+ for (let i = 0; i < _createRecords.length; i++) {
60
+ const newRecord = _createRecords[i]
61
+
62
+ const result = await templateFileRepo.save({
63
+ ...newRecord,
64
+ domain,
65
+ creator: user,
66
+ updater: user
67
+ })
68
+
69
+ results.push({ ...result, cuFlag: '+' })
70
+ }
71
+ }
72
+
73
+ if (_updateRecords.length > 0) {
74
+ for (let i = 0; i < _updateRecords.length; i++) {
75
+ const updRecord = _updateRecords[i]
76
+ const templateFile = await templateFileRepo.findOne({
77
+ where: { domain: { id: domain.id }, id:updRecord.id },
78
+ relations: ['domain','updater','creator','attachment']
79
+ })
80
+
81
+ const result = await templateFileRepo.save({
82
+ ...templateFile,
83
+ ...updRecord,
84
+ updater: user
85
+ })
86
+
87
+ results.push({ ...result, cuFlag: 'M' })
88
+ }
89
+ }
90
+
91
+ return results
92
+ }
93
+
94
+ @Directive('@transaction')
95
+ @Mutation(returns => Boolean, { description: 'To delete TemplateFile' })
96
+ async deleteTemplateFile(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
97
+ const { domain, tx, user } = context.state
98
+ await tx.getRepository(TemplateFile).remove({ domain, id, updater:user })
99
+ return true
100
+ }
101
+
102
+ @Directive('@transaction')
103
+ @Mutation(returns => Boolean, { description: 'To delete multiple templateFiles' })
104
+ async deleteTemplateFiles(
105
+ @Arg('ids', type => [String]) ids: string[],
106
+ @Ctx() context: any
107
+ ): Promise<boolean> {
108
+ const { domain, tx, user } = context.state
109
+
110
+ let delEntitis = ids.map(id => {
111
+ return {domain,id,updater:user}
112
+ })
113
+
114
+ await tx.getRepository(TemplateFile).remove(delEntitis)
115
+ return true
116
+ }
117
+ }
@@ -0,0 +1,55 @@
1
+
2
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
3
+ import { ListParam, getRepository, getQueryBuilderFromListParams } from '@things-factory/shell'
4
+ import { TemplateFile } from './template-file'
5
+ import { TemplateFileList } from './template-file-type'
6
+
7
+ import { User } from '@things-factory/auth-base'
8
+ import { Domain } from '@things-factory/shell'
9
+ import { Attachment } from '@things-factory/attachment-base'
10
+
11
+ @Resolver(TemplateFile)
12
+ export class TemplateFileQuery {
13
+ @Query(returns => TemplateFile, { description: 'To fetch a TemplateFile' })
14
+ async templateFile(@Arg('id') id: string, @Ctx() context: any): Promise<TemplateFile> {
15
+ const { domain } = context.state
16
+ return await getRepository(TemplateFile).findOne({
17
+ where: { domain: { id: domain.id }, id }
18
+ })
19
+ }
20
+
21
+ @Query(returns => TemplateFileList, { description: 'To fetch multiple TemplateFiles' })
22
+ async templateFiles(@Args() params: ListParam, @Ctx() context: any): Promise<TemplateFileList> {
23
+ const { domain } = context.state
24
+
25
+ const queryBuilder = getQueryBuilderFromListParams({
26
+ domain,
27
+ params,
28
+ repository: await getRepository(TemplateFile),
29
+ searchables: ['name', 'description', 'note']
30
+ })
31
+
32
+ const [items, total] = await queryBuilder.getManyAndCount()
33
+ return { items, total }
34
+ }
35
+
36
+ @FieldResolver(type => Attachment)
37
+ async attachment(@Root() templateFile: TemplateFile): Promise<Attachment> {
38
+ return await getRepository(Attachment).findOneBy({id:templateFile.attachmentId})
39
+ }
40
+
41
+ @FieldResolver(type => Domain)
42
+ async domain(@Root() templateFile: TemplateFile): Promise<Domain> {
43
+ return await getRepository(Domain).findOneBy({id:templateFile.domainId})
44
+ }
45
+
46
+ @FieldResolver(type => User)
47
+ async creator(@Root() templateFile: TemplateFile): Promise<User> {
48
+ return await getRepository(User).findOneBy({id:templateFile.creatorId})
49
+ }
50
+
51
+ @FieldResolver(type => User)
52
+ async updater(@Root() templateFile: TemplateFile): Promise<User> {
53
+ return await getRepository(User).findOneBy({id:templateFile.updaterId})
54
+ }
55
+ }
@@ -0,0 +1,73 @@
1
+
2
+ import { ObjectType, Field, InputType, Int, ID } from 'type-graphql'
3
+ import { ObjectRef } from '@things-factory/shell'
4
+ import { TemplateFile } from './template-file'
5
+
6
+ @InputType()
7
+ export class NewTemplateFile {
8
+ @Field({ nullable: false })
9
+ name: string
10
+
11
+ @Field({ nullable: false })
12
+ description: string
13
+
14
+ @Field({ nullable: true })
15
+ jobType?: string
16
+
17
+ @Field({ nullable: true })
18
+ jobClass?: string
19
+
20
+ @Field({ nullable: true })
21
+ jobCategory?: string
22
+
23
+ @Field({ nullable: true })
24
+ activeFlag?: boolean
25
+
26
+ @Field({ nullable: true })
27
+ note?: string
28
+
29
+ @Field(type => ObjectRef, { nullable: true })
30
+ attachment?: ObjectRef
31
+ }
32
+
33
+ @InputType()
34
+ export class TemplateFilePatch {
35
+ @Field(type => ID, { nullable: true })
36
+ id?: string
37
+
38
+ @Field({ nullable: true })
39
+ name?: string
40
+
41
+ @Field({ nullable: true })
42
+ description?: string
43
+
44
+ @Field({ nullable: true })
45
+ jobType?: string
46
+
47
+ @Field({ nullable: true })
48
+ jobClass?: string
49
+
50
+ @Field({ nullable: true })
51
+ jobCategory?: string
52
+
53
+ @Field({ nullable: true })
54
+ activeFlag?: boolean
55
+
56
+ @Field({ nullable: true })
57
+ note?: string
58
+
59
+ @Field(type => ObjectRef, { nullable: true })
60
+ attachment?: ObjectRef
61
+
62
+ @Field()
63
+ cuFlag: string
64
+ }
65
+
66
+ @ObjectType()
67
+ export class TemplateFileList {
68
+ @Field(type => [TemplateFile])
69
+ items: TemplateFile[]
70
+
71
+ @Field(type => Int)
72
+ total: number
73
+ }
@@ -0,0 +1,94 @@
1
+
2
+ import {
3
+ CreateDateColumn,
4
+ UpdateDateColumn,
5
+ Entity,
6
+ Index,
7
+ Column,
8
+ RelationId,
9
+ ManyToOne,
10
+ OneToOne,
11
+ PrimaryGeneratedColumn,
12
+ } from 'typeorm'
13
+ import { ObjectType, Field, ID } from 'type-graphql'
14
+
15
+ import { User } from '@things-factory/auth-base'
16
+ import { Domain } from '@things-factory/shell'
17
+ import { Attachment } from '@things-factory/attachment-base'
18
+
19
+ @Entity('template_files')
20
+ @Index('ix_template_file_0', (templateFile: TemplateFile) => [templateFile.domain,templateFile.name], { unique: true })
21
+ @Index('ix_template_file_1', (templateFile: TemplateFile) => [templateFile.domain,templateFile.jobType])
22
+ @Index('ix_template_file_2', (templateFile: TemplateFile) => [templateFile.domain,templateFile.jobClass])
23
+ @Index('ix_template_file_3', (templateFile: TemplateFile) => [templateFile.domain,templateFile.jobCategory])
24
+ @Index('ix_template_file_4', (templateFile: TemplateFile) => [templateFile.domain,templateFile.attachment])
25
+ @ObjectType({ description: 'Entity for TemplateFile' })
26
+ export class TemplateFile {
27
+ @PrimaryGeneratedColumn('uuid')
28
+ @Field(type => ID)
29
+ readonly id: string
30
+
31
+ @Column({ name:'name', nullable:false })
32
+ @Field({ nullable:false })
33
+ name: string
34
+
35
+ @Column({ name:'description', nullable:false })
36
+ @Field({ nullable:false })
37
+ description: string
38
+
39
+ @Column({ name:'job_type', nullable:true })
40
+ @Field({ nullable:true })
41
+ jobType?: string
42
+
43
+ @Column({ name:'job_class', nullable:true })
44
+ @Field({ nullable:true })
45
+ jobClass?: string
46
+
47
+ @Column({ name:'job_category', nullable:true })
48
+ @Field({ nullable:true })
49
+ jobCategory?: string
50
+
51
+ @Column({ name:'active_flag', type:'boolean', nullable:true })
52
+ @Field( { nullable:true })
53
+ activeFlag?: boolean
54
+
55
+ @Column({ name:'note', nullable:true })
56
+ @Field({ nullable:true })
57
+ note?: string
58
+
59
+ @ManyToOne(type => Attachment, {createForeignKeyConstraints: false, nullable: true})
60
+ @Field({ nullable: true})
61
+ attachment: Attachment
62
+
63
+ @RelationId((templateFile: TemplateFile) => templateFile.attachment)
64
+ attachmentId?: string
65
+
66
+ @ManyToOne(type => Domain, {createForeignKeyConstraints: false, nullable: false})
67
+ @Field({ nullable: false })
68
+ domain: Domain
69
+
70
+ @RelationId((templateFile: TemplateFile) => templateFile.domain)
71
+ domainId: string
72
+
73
+ @ManyToOne(type => User, {createForeignKeyConstraints: false, nullable: true})
74
+ @Field({ nullable: true })
75
+ creator?: User
76
+
77
+ @RelationId((templateFile: TemplateFile) => templateFile.creator)
78
+ creatorId?: string
79
+
80
+ @ManyToOne(type => User, {createForeignKeyConstraints: false, nullable: true})
81
+ @Field({ nullable: true })
82
+ updater?: User
83
+
84
+ @RelationId((templateFile: TemplateFile) => templateFile.updater)
85
+ updaterId?: string
86
+
87
+ @CreateDateColumn()
88
+ @Field({ nullable: true })
89
+ createdAt?: Date
90
+
91
+ @UpdateDateColumn()
92
+ @Field({ nullable: true })
93
+ updatedAt?: Date
94
+ }