@things-factory/document-template-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,120 +0,0 @@
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
- }
@@ -1,48 +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 { DocTemplate } from './doc-template'
4
- import { DocTemplateList } from './doc-template-type'
5
-
6
- import { User } from '@things-factory/auth-base'
7
- import { Domain } from '@things-factory/shell'
8
-
9
- @Resolver(DocTemplate)
10
- export class DocTemplateQuery {
11
- @Query(returns => DocTemplate, { description: 'To fetch a DocTemplate' })
12
- async docTemplate(@Arg('id') id: string, @Ctx() context: any): Promise<DocTemplate> {
13
- const { domain } = context.state
14
- return await getRepository(DocTemplate).findOne({
15
- where: { domain: { id: domain.id }, id }
16
- })
17
- }
18
-
19
- @Query(returns => DocTemplateList, { description: 'To fetch multiple DocTemplates' })
20
- async docTemplates(@Args(type => ListParam) params: ListParam, @Ctx() context: any): Promise<DocTemplateList> {
21
- const { domain } = context.state
22
-
23
- const queryBuilder = getQueryBuilderFromListParams({
24
- domain,
25
- params,
26
- repository: await getRepository(DocTemplate),
27
- searchables: ['name', 'description']
28
- })
29
-
30
- const [items, total] = await queryBuilder.getManyAndCount()
31
- return { items, total }
32
- }
33
-
34
- @FieldResolver(type => Domain)
35
- async domain(@Root() docTemplate: DocTemplate): Promise<Domain> {
36
- return await getRepository(Domain).findOneBy({ id: docTemplate.domainId })
37
- }
38
-
39
- @FieldResolver(type => User)
40
- async creator(@Root() docTemplate: DocTemplate): Promise<User> {
41
- return await getRepository(User).findOneBy({ id: docTemplate.creatorId })
42
- }
43
-
44
- @FieldResolver(type => User)
45
- async updater(@Root() docTemplate: DocTemplate): Promise<User> {
46
- return await getRepository(User).findOneBy({ id: docTemplate.updaterId })
47
- }
48
- }
@@ -1,80 +0,0 @@
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
- }
@@ -1,89 +0,0 @@
1
- import {
2
- CreateDateColumn,
3
- UpdateDateColumn,
4
- Entity,
5
- Index,
6
- Column,
7
- RelationId,
8
- ManyToOne,
9
- PrimaryGeneratedColumn
10
- } from 'typeorm'
11
- import { ObjectType, Field, Int, ID, Float, registerEnumType } from 'type-graphql'
12
-
13
- import { User } from '@things-factory/auth-base'
14
- import { Domain } from '@things-factory/shell'
15
-
16
- @Entity('doc_templates')
17
- @Index('ix_doc_template_0', (docTemplate: DocTemplate) => [docTemplate.domain, docTemplate.name], { unique: true })
18
- @Index('ix_doc_template_1', (docTemplate: DocTemplate) => [docTemplate.domain, docTemplate.activeFlag])
19
- @ObjectType({ description: 'Entity for DocTemplate' })
20
- export class DocTemplate {
21
- @PrimaryGeneratedColumn('uuid')
22
- @Field(type => ID)
23
- readonly id: string
24
-
25
- @Column({ name: 'name', nullable: false })
26
- @Field({ nullable: false })
27
- name: string
28
-
29
- @Column({ name: 'description', nullable: false })
30
- @Field({ nullable: false })
31
- description: string
32
-
33
- @Column({ name: 'job_type', nullable: true })
34
- @Field({ nullable: true })
35
- jobType?: string
36
-
37
- @Column({ name: 'job_class', nullable: true })
38
- @Field({ nullable: true })
39
- jobClass?: string
40
-
41
- @Column({ name: 'job_category', nullable: true })
42
- @Field({ nullable: true })
43
- jobCategory?: string
44
-
45
- @Column({ name: 'template', type: 'text', nullable: true })
46
- @Field({ nullable: true })
47
- template?: string
48
-
49
- @Column({ name: 'logic', type: 'text', nullable: true })
50
- @Field({ nullable: true })
51
- logic?: string
52
-
53
- @Column({ name: 'active_flag', type: 'boolean', nullable: true })
54
- @Field({ nullable: true })
55
- activeFlag?: boolean
56
-
57
- @Column({ name: 'note', nullable: true })
58
- @Field({ nullable: true })
59
- note?: string
60
-
61
- @ManyToOne(type => Domain, { createForeignKeyConstraints: false, nullable: false })
62
- @Field({ nullable: false })
63
- domain: Domain
64
-
65
- @RelationId((docTemplate: DocTemplate) => docTemplate.domain)
66
- domainId: string
67
-
68
- @ManyToOne(type => User, { createForeignKeyConstraints: false, nullable: true })
69
- @Field(type => User, { nullable: true })
70
- creator?: User
71
-
72
- @RelationId((docTemplate: DocTemplate) => docTemplate.creator)
73
- creatorId?: string
74
-
75
- @ManyToOne(type => User, { createForeignKeyConstraints: false, nullable: true })
76
- @Field(type => User, { nullable: true })
77
- updater?: User
78
-
79
- @RelationId((docTemplate: DocTemplate) => docTemplate.updater)
80
- updaterId?: string
81
-
82
- @CreateDateColumn()
83
- @Field({ nullable: true })
84
- createdAt?: Date
85
-
86
- @UpdateDateColumn()
87
- @Field({ nullable: true })
88
- updatedAt?: Date
89
- }
@@ -1,7 +0,0 @@
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,25 +0,0 @@
1
- /* EXPORT ENTITY TYPES */
2
- export * from './doc-template/doc-template'
3
- export * from './template-file/template-file'
4
-
5
- /* IMPORT ENTITIES AND RESOLVERS */
6
- import { entities as DocTemplateEntities, resolvers as DocTemplateResolvers } from './doc-template'
7
- import { entities as TemplateFileEntities, resolvers as TemplateFileResolvers } from './template-file'
8
-
9
- export const entities = [
10
- /* ENTITIES */
11
- ...DocTemplateEntities,
12
- ...TemplateFileEntities
13
- ]
14
-
15
- export const schema = {
16
- resolverClasses: [
17
- /* RESOLVER CLASSES */
18
- ...DocTemplateResolvers,
19
- ...TemplateFileResolvers
20
- ]
21
- }
22
-
23
- export const subscribers = [
24
- /* SUBSCRIBERS */
25
- ]
@@ -1,7 +0,0 @@
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]
@@ -1,117 +0,0 @@
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
- }
@@ -1,54 +0,0 @@
1
- import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
- import { ListParam, getRepository, getQueryBuilderFromListParams } from '@things-factory/shell'
3
- import { TemplateFile } from './template-file'
4
- import { TemplateFileList } from './template-file-type'
5
-
6
- import { User } from '@things-factory/auth-base'
7
- import { Domain } from '@things-factory/shell'
8
- import { Attachment } from '@things-factory/attachment-base'
9
-
10
- @Resolver(TemplateFile)
11
- export class TemplateFileQuery {
12
- @Query(returns => TemplateFile, { description: 'To fetch a TemplateFile' })
13
- async templateFile(@Arg('id') id: string, @Ctx() context: any): Promise<TemplateFile> {
14
- const { domain } = context.state
15
- return await getRepository(TemplateFile).findOne({
16
- where: { domain: { id: domain.id }, id }
17
- })
18
- }
19
-
20
- @Query(returns => TemplateFileList, { description: 'To fetch multiple TemplateFiles' })
21
- async templateFiles(@Args(type => ListParam) params: ListParam, @Ctx() context: any): Promise<TemplateFileList> {
22
- const { domain } = context.state
23
-
24
- const queryBuilder = getQueryBuilderFromListParams({
25
- domain,
26
- params,
27
- repository: await getRepository(TemplateFile),
28
- searchables: ['name', 'description', 'note']
29
- })
30
-
31
- const [items, total] = await queryBuilder.getManyAndCount()
32
- return { items, total }
33
- }
34
-
35
- @FieldResolver(type => Attachment)
36
- async attachment(@Root() templateFile: TemplateFile): Promise<Attachment> {
37
- return await getRepository(Attachment).findOneBy({ id: templateFile.attachmentId })
38
- }
39
-
40
- @FieldResolver(type => Domain)
41
- async domain(@Root() templateFile: TemplateFile): Promise<Domain> {
42
- return await getRepository(Domain).findOneBy({ id: templateFile.domainId })
43
- }
44
-
45
- @FieldResolver(type => User)
46
- async creator(@Root() templateFile: TemplateFile): Promise<User> {
47
- return await getRepository(User).findOneBy({ id: templateFile.creatorId })
48
- }
49
-
50
- @FieldResolver(type => User)
51
- async updater(@Root() templateFile: TemplateFile): Promise<User> {
52
- return await getRepository(User).findOneBy({ id: templateFile.updaterId })
53
- }
54
- }
@@ -1,73 +0,0 @@
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
- }