@things-factory/quotation 8.0.0-beta.0 → 8.0.0-beta.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.
@@ -1,123 +0,0 @@
1
- import {
2
- Activity,
3
- ActivityInstance,
4
- ActivityInstanceStatus,
5
- ActivityThread,
6
- UpdateActivityInstanceStateAddendum
7
- } from '@things-factory/worklist'
8
-
9
- async function callback(
10
- activityInstance: ActivityInstance,
11
- addendum: UpdateActivityInstanceStateAddendum,
12
- context: ResolverContext
13
- ) {
14
- const { domain, tx } = context.state
15
- const { input, output, state } = activityInstance
16
- const { causedBy } = addendum || {}
17
-
18
- if (state == ActivityInstanceStatus.Ended) {
19
- const activity = (await tx.getRepository(Activity).findOneBy({
20
- domain: { id: domain.id },
21
- name: 'Quotation'
22
- })) as Activity
23
-
24
- /*
25
- quotation 액티비티는 한명의 assignee(thread)만 수행하도록 한다. 따라서, output 중에서 샘플 한 개만을 data로 취한다.
26
- 만약, 여러 assignees(threads)가 수행하는 액티비티인 경우에는 output 전체를 data로 처리한다.
27
- */
28
- const assignees = Object.keys(output)
29
- const data = assignees.length > 0 && output[assignees[0]]
30
-
31
- if (activity) {
32
- /*
33
- custom logic goes here.
34
- 주로,
35
- */
36
- } else {
37
- console.error('Quotation Activity not installed.')
38
- }
39
- } else if (state == ActivityInstanceStatus.Aborted) {
40
- }
41
- }
42
-
43
- export const ActivityQuotation = {
44
- name: 'Quotation',
45
- description: 'An activity that issues a quotation',
46
- release: '1.0.0',
47
- provider: 'hatiolab.com',
48
- category: '',
49
- activityType: 'user',
50
- priority: 1,
51
- searchKeys: [
52
- // sample search keys
53
- {
54
- name: 'customer',
55
- description: 'Customer Code',
56
- inputKey: 'customer',
57
- tKey: 'customer'
58
- },
59
- {
60
- name: 'product',
61
- description: 'Product Code',
62
- inputKey: 'product',
63
- tKey: 'product'
64
- }
65
- ],
66
- /*
67
- startable 설정된 액티비티는 수동으로 업무를 시작하여, 할당할 수 있음을 의미한다.
68
- issuer로 정의된 역할을 갖는 사용자가 시작할 수 있으며, issuer가 정의되지 않았다면 모든 사용자가 시작할 수 있다.
69
- 업무를 시작하는 과정에서 assignees와 approval-line은 액티비티의 설정을 디폴트로 하지만 수동으로 조정할 수 있다.
70
- */
71
- startable: true,
72
- /* (미구현 속성)
73
- startingType 설정된 액티비티는 'issue' 또는 'post' 이 될 수 있다. 'post' 타입은 혼자서 start, assign, end 까지 한번에 다하는 특성을 갖는다. 이 액티비티를 수행하는 사용자는 draft(초안)과 post(완료)단계만 인식하게 된다.
74
- 이 경우의 모델은 모두 'in' 또는 'inout'의 속성을 갖는 것이 좋다. 'out' 속성의 데이타는 입력될 기회를 갖지 못한다.
75
- 이 경우의 assignees 설정은 의미가 없다.
76
- 이 경우에도 approval-line이 설정되어 있다면, 승인 프로세스에 의해서 처리된다.
77
- 'issue' 타입인 경우에는 모델의 'in' 또는 'inout' 속성을 채워서 assignee에게 할당하는 방식이므로 assignee가 설정되어야 한다.
78
- */
79
- startingType: 'post',
80
- /* (미구현 속성)
81
- multiple 속성은 'parallel', 'sequential' 값을 설정할 수 있다. parallel로 설정하면, 다중 인스턴스(여기서는 다중 쓰레드)로 처리하되 병렬처리되며,
82
- sequential로 설정하면 순차적으로 다중 인스턴스가 수행된다.
83
- 설정하지 않으면, single 인스턴스로 수행된다는 의미이며, 이 경우 assignees가 여럿이 설정되어있어도 1명에게만 할당되게 된다.
84
- 이 경우에는 액티비티 인스턴스의 결과 데이타(output)도 단일 쓰레드의 output이 그대로 적용된다.
85
- */
86
- multiple: null,
87
- model: [
88
- {
89
- name: 'customer',
90
- description: 'Customer Code',
91
- tag: 'customer',
92
- hidden: true,
93
- mandatory: true,
94
- inout: 'in',
95
- type: 'string',
96
- options: {},
97
- unit: null,
98
- quantifier: [1],
99
- spec: {}
100
- },
101
- {
102
- name: 'product',
103
- description: 'Product Code',
104
- tag: 'product',
105
- hidden: true,
106
- mandatory: true,
107
- inout: 'in',
108
- type: 'string',
109
- options: {},
110
- unit: null,
111
- quantifier: [1],
112
- spec: {}
113
- }
114
- ],
115
- uiType: 'custom-element',
116
- uiSource: 'activity-quotation-edit',
117
- viewType: 'custom-element',
118
- viewSource: 'activity-quotation-view',
119
- reportType: 'custom-element',
120
- reportSource: 'activity-quotation-report',
121
- thumbnail: '/assets/images/quotation-activity.png',
122
- callback /* Called when there is a change in the lifecycle of a task (activity-instance). */
123
- }
@@ -1,16 +0,0 @@
1
- import { ActivityInstallations } from '@things-factory/worklist'
2
-
3
- /* IMPORT ACTIVITY TEMPLATES */
4
- import { ActivityQuotation } from './activity-quotation'
5
- ;[
6
- /* ACTIVITY TEMPLATES */
7
- ActivityQuotation
8
- ].forEach(template => {
9
- ActivityInstallations.installActivityTemplate(template as any)
10
- })
11
-
12
- /*
13
- Add the following line to server/index.ts so that activities can be registered when loading a module.
14
- --
15
- import './activities'
16
- */
File without changes
package/server/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './migrations'
2
- export * from './middlewares'
3
-
4
- import './routes'
@@ -1,3 +0,0 @@
1
- export function initMiddlewares(app) {
2
- /* can add middlewares into app */
3
- }
@@ -1,9 +0,0 @@
1
- const glob = require('glob')
2
- const path = require('path')
3
-
4
- export var migrations = []
5
-
6
- glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
7
- if (file.indexOf('index.js') !== -1) return
8
- migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
9
- })
package/server/routes.ts DELETED
@@ -1,26 +0,0 @@
1
- process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
2
- /*
3
- * can add global public routes to application (auth not required, tenancy not required)
4
- *
5
- * ex) routes.get('/path', async(context, next) => {})
6
- * ex) routes.post('/path', async(context, next) => {})
7
- */
8
- })
9
-
10
- process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
11
- /*
12
- * can add global private routes to application (auth required, tenancy not required)
13
- */
14
- })
15
-
16
- process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
17
- /*
18
- * can add domain public routes to application (auth not required, tenancy required)
19
- */
20
- })
21
-
22
- process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
23
- /*
24
- * can add domain private routes to application (auth required, tenancy required)
25
- */
26
- })
@@ -1,22 +0,0 @@
1
- /* EXPORT ENTITY TYPES */
2
- export * from './quotation/quotation'
3
-
4
- /* IMPORT ENTITIES AND RESOLVERS */
5
- import { entities as QuotationEntities, resolvers as QuotationResolvers, subscribers as QuotationSubscribers } from './quotation'
6
-
7
- export const entities = [
8
- /* ENTITIES */
9
- ...QuotationEntities,
10
- ]
11
-
12
- export const subscribers = [
13
- /* SUBSCRIBERS */
14
- ...QuotationSubscribers,
15
- ]
16
-
17
- export const schema = {
18
- resolverClasses: [
19
- /* RESOLVER CLASSES */
20
- ...QuotationResolvers,
21
- ]
22
- }
@@ -1,17 +0,0 @@
1
- import { EventSubscriber } from 'typeorm'
2
-
3
- import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
-
5
- import { Quotation } from './quotation'
6
- import { QuotationHistory } from './quotation-history'
7
-
8
- @EventSubscriber()
9
- export class QuotationHistoryEntitySubscriber extends HistoryEntitySubscriber<Quotation, QuotationHistory> {
10
- public get entity() {
11
- return Quotation
12
- }
13
-
14
- public get historyEntity() {
15
- return QuotationHistory
16
- }
17
- }
@@ -1,9 +0,0 @@
1
- import { Quotation } from './quotation'
2
- import { QuotationHistory } from './quotation-history'
3
- import { QuotationQuery } from './quotation-query'
4
- import { QuotationMutation } from './quotation-mutation'
5
- import { QuotationHistoryEntitySubscriber } from './event-subscriber'
6
-
7
- export const entities = [Quotation, QuotationHistory]
8
- export const resolvers = [QuotationQuery, QuotationMutation]
9
- export const subscribers = [QuotationHistoryEntitySubscriber]
@@ -1,120 +0,0 @@
1
- import { Field, ID, ObjectType } from 'type-graphql'
2
- import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
3
-
4
- import {
5
- HistoryActionColumn,
6
- HistoryActionType,
7
- HistoryEntityInterface,
8
- HistoryOriginalIdColumn
9
- } from '@operato/typeorm-history'
10
- import { Role, User } from '@things-factory/auth-base'
11
- import { config } from '@things-factory/env'
12
- import { Domain } from '@things-factory/shell'
13
-
14
- import { Quotation, QuotationStatus } from './quotation'
15
-
16
- const ORMCONFIG = config.get('ormconfig', {})
17
- const DATABASE_TYPE = ORMCONFIG.type
18
-
19
- @Entity()
20
- @Index(
21
- 'ix_quotation_history_0',
22
- (quotationHistory: QuotationHistory) => [quotationHistory.originalId, quotationHistory.version],
23
- { unique: true }
24
- )
25
- @Index(
26
- 'ix_quotation_history_1',
27
- (quotationHistory: QuotationHistory) => [
28
- quotationHistory.domain,
29
- quotationHistory.originalId,
30
- quotationHistory.version
31
- ],
32
- { unique: true }
33
- )
34
- @ObjectType({ description: 'History Entity of Quotation' })
35
- export class QuotationHistory implements HistoryEntityInterface<Quotation> {
36
- @PrimaryGeneratedColumn('uuid')
37
- @Field(type => ID)
38
- readonly id: string
39
-
40
- @Column({ nullable: true, default: 1 })
41
- @Field({ nullable: true })
42
- version?: number = 1
43
-
44
- @ManyToOne(type => Domain)
45
- @Field(type => Domain)
46
- domain?: Domain
47
-
48
- @RelationId((quotation: Quotation) => quotation.domain)
49
- domainId?: string
50
-
51
- @Column()
52
- @Field()
53
- name: string
54
-
55
- @Column({ nullable: true })
56
- @Field({ nullable: true })
57
- description?: string
58
-
59
- @Column({ nullable: true })
60
- @Field({ nullable: true })
61
- active?: boolean
62
-
63
- @Column({ nullable: true })
64
- @Field({ nullable: true })
65
- state?: QuotationStatus
66
-
67
- @Column({ nullable: true })
68
- @Field({ nullable: true })
69
- params?: string
70
-
71
- @Column({ nullable: true })
72
- @Field({ nullable: true })
73
- createdAt?: Date
74
-
75
- @Column({ nullable: true })
76
- @Field({ nullable: true })
77
- updatedAt?: Date
78
-
79
- @Column({ nullable: true })
80
- @Field({ nullable: true })
81
- deletedAt?: Date
82
-
83
- @ManyToOne(type => User, { nullable: true })
84
- @Field(type => User, { nullable: true })
85
- creator?: User
86
-
87
- @RelationId((quotation: Quotation) => quotation.creator)
88
- creatorId?: string
89
-
90
- @ManyToOne(type => User, { nullable: true })
91
- @Field(type => User, { nullable: true })
92
- updater?: User
93
-
94
- @RelationId((quotation: Quotation) => quotation.updater)
95
- updaterId?: string
96
-
97
- @Field(type => String, { nullable: true })
98
- thumbnail?: string
99
-
100
- @HistoryOriginalIdColumn()
101
- public originalId!: string
102
-
103
- @HistoryActionColumn({
104
- nullable: false,
105
- type:
106
- DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
107
- ? 'enum'
108
- : DATABASE_TYPE == 'oracle'
109
- ? 'varchar2'
110
- : DATABASE_TYPE == 'mssql'
111
- ? 'nvarchar'
112
- : 'varchar',
113
- enum:
114
- DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
115
- ? HistoryActionType
116
- : undefined,
117
- length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
118
- })
119
- public action!: HistoryActionType
120
- }
@@ -1,198 +0,0 @@
1
- import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'
5
-
6
- import { Quotation } from './quotation'
7
- import { NewQuotation, QuotationPatch } from './quotation-type'
8
-
9
- @Resolver(Quotation)
10
- export class QuotationMutation {
11
- @Directive('@transaction')
12
- @Mutation(returns => Quotation, { description: 'To create new Quotation' })
13
- async createQuotation(@Arg('quotation') quotation: NewQuotation, @Ctx() context: ResolverContext): Promise<Quotation> {
14
- const { domain, user, tx } = context.state
15
-
16
- const result = await tx.getRepository(Quotation).save({
17
- ...quotation,
18
- domain,
19
- creator: user,
20
- updater: user
21
- })
22
-
23
- if (quotation.thumbnail) {
24
- await createAttachment(
25
- null,
26
- {
27
- attachment: {
28
- file: quotation.thumbnail,
29
- refType: Quotation.name,
30
- refBy: result.id
31
- }
32
- },
33
- context
34
- )
35
- }
36
-
37
- return result
38
- }
39
-
40
- @Directive('@transaction')
41
- @Mutation(returns => Quotation, { description: 'To modify Quotation information' })
42
- async updateQuotation(
43
- @Arg('id') id: string,
44
- @Arg('patch') patch: QuotationPatch,
45
- @Ctx() context: ResolverContext
46
- ): Promise<Quotation> {
47
- const { domain, user, tx } = context.state
48
-
49
- const repository = tx.getRepository(Quotation)
50
- const quotation = await repository.findOne({
51
- where: { domain: { id: domain.id }, id }
52
- })
53
-
54
- const result = await repository.save({
55
- ...quotation,
56
- ...patch,
57
- updater: user
58
- })
59
-
60
- if (patch.thumbnail) {
61
- await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
62
- await createAttachment(
63
- null,
64
- {
65
- attachment: {
66
- file: patch.thumbnail,
67
- refType: Quotation.name,
68
- refBy: result.id
69
- }
70
- },
71
- context
72
- )
73
- }
74
-
75
- return result
76
- }
77
-
78
- @Directive('@transaction')
79
- @Mutation(returns => [Quotation], { description: "To modify multiple Quotations' information" })
80
- async updateMultipleQuotation(
81
- @Arg('patches', type => [QuotationPatch]) patches: QuotationPatch[],
82
- @Ctx() context: ResolverContext
83
- ): Promise<Quotation[]> {
84
- const { domain, user, tx } = context.state
85
-
86
- let results = []
87
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
88
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
89
- const quotationRepo = tx.getRepository(Quotation)
90
-
91
- if (_createRecords.length > 0) {
92
- for (let i = 0; i < _createRecords.length; i++) {
93
- const newRecord = _createRecords[i]
94
-
95
- const result = await quotationRepo.save({
96
- ...newRecord,
97
- domain,
98
- creator: user,
99
- updater: user
100
- })
101
-
102
- if (newRecord.thumbnail) {
103
- await createAttachment(
104
- null,
105
- {
106
- attachment: {
107
- file: newRecord.thumbnail,
108
- refType: Quotation.name,
109
- refBy: result.id
110
- }
111
- },
112
- context
113
- )
114
- }
115
-
116
- results.push({ ...result, cuFlag: '+' })
117
- }
118
- }
119
-
120
- if (_updateRecords.length > 0) {
121
- for (let i = 0; i < _updateRecords.length; i++) {
122
- const updateRecord = _updateRecords[i]
123
- const quotation = await quotationRepo.findOneBy({ id: updateRecord.id })
124
-
125
- const result = await quotationRepo.save({
126
- ...quotation,
127
- ...updateRecord,
128
- updater: user
129
- })
130
-
131
- if (updateRecord.thumbnail) {
132
- await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
133
- await createAttachment(
134
- null,
135
- {
136
- attachment: {
137
- file: updateRecord.thumbnail,
138
- refType: Quotation.name,
139
- refBy: result.id
140
- }
141
- },
142
- context
143
- )
144
- }
145
-
146
- results.push({ ...result, cuFlag: 'M' })
147
- }
148
- }
149
-
150
- return results
151
- }
152
-
153
- @Directive('@transaction')
154
- @Mutation(returns => Boolean, { description: 'To delete Quotation' })
155
- async deleteQuotation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
156
- const { domain, tx } = context.state
157
-
158
- await tx.getRepository(Quotation).delete({ domain: { id: domain.id }, id })
159
- await deleteAttachmentsByRef(null, { refBys: [id] }, context)
160
-
161
- return true
162
- }
163
-
164
- @Directive('@transaction')
165
- @Mutation(returns => Boolean, { description: 'To delete multiple Quotations' })
166
- async deleteQuotations(
167
- @Arg('ids', type => [String]) ids: string[],
168
- @Ctx() context: ResolverContext
169
- ): Promise<boolean> {
170
- const { domain, tx } = context.state
171
-
172
- await tx.getRepository(Quotation).delete({
173
- domain: { id: domain.id },
174
- id: In(ids)
175
- })
176
-
177
- await deleteAttachmentsByRef(null, { refBys: ids }, context)
178
-
179
- return true
180
- }
181
-
182
- @Directive('@transaction')
183
- @Mutation(returns => Boolean, { description: 'To import multiple Quotations' })
184
- async importQuotations(
185
- @Arg('quotations', type => [QuotationPatch]) quotations: QuotationPatch[],
186
- @Ctx() context: ResolverContext
187
- ): Promise<boolean> {
188
- const { domain, tx } = context.state
189
-
190
- await Promise.all(
191
- quotations.map(async (quotation: QuotationPatch) => {
192
- const createdQuotation: Quotation = await tx.getRepository(Quotation).save({ domain, ...quotation })
193
- })
194
- )
195
-
196
- return true
197
- }
198
- }
@@ -1,65 +0,0 @@
1
- import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
- import { Attachment } from '@things-factory/attachment-base'
3
- import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
4
- import { User } from '@things-factory/auth-base'
5
- import { Quotation } from './quotation'
6
- import { QuotationList } from './quotation-type'
7
-
8
- @Resolver(Quotation)
9
- export class QuotationQuery {
10
- @Query(returns => Quotation!, { nullable: true, description: 'To fetch a Quotation' })
11
- async quotation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Quotation> {
12
- const { domain } = context.state
13
-
14
- return await getRepository(Quotation).findOne({
15
- where: { domain: { id: domain.id }, id }
16
- })
17
- }
18
-
19
- @Query(returns => QuotationList, { description: 'To fetch multiple Quotations' })
20
- async quotations(
21
- @Args(type => ListParam) params: ListParam,
22
- @Ctx() context: ResolverContext
23
- ): Promise<QuotationList> {
24
- const { domain } = context.state
25
-
26
- const queryBuilder = getQueryBuilderFromListParams({
27
- domain,
28
- params,
29
- repository: await getRepository(Quotation),
30
- searchables: ['name', 'description']
31
- })
32
-
33
- const [items, total] = await queryBuilder.getManyAndCount()
34
-
35
- return { items, total }
36
- }
37
-
38
- @FieldResolver(type => String)
39
- async thumbnail(@Root() quotation: Quotation): Promise<string | undefined> {
40
- const attachment: Attachment = await getRepository(Attachment).findOne({
41
- where: {
42
- domain: { id: quotation.domainId },
43
- refType: Quotation.name,
44
- refBy: quotation.id
45
- }
46
- })
47
-
48
- return attachment?.fullpath
49
- }
50
-
51
- @FieldResolver(type => Domain)
52
- async domain(@Root() quotation: Quotation): Promise<Domain> {
53
- return await getRepository(Domain).findOneBy({ id: quotation.domainId })
54
- }
55
-
56
- @FieldResolver(type => User)
57
- async updater(@Root() quotation: Quotation): Promise<User> {
58
- return await getRepository(User).findOneBy({ id: quotation.updaterId })
59
- }
60
-
61
- @FieldResolver(type => User)
62
- async creator(@Root() quotation: Quotation): Promise<User> {
63
- return await getRepository(User).findOneBy({ id: quotation.creatorId })
64
- }
65
- }
@@ -1,61 +0,0 @@
1
- import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
2
- import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
3
- import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
4
-
5
- import { ObjectRef, ScalarObject } from '@things-factory/shell'
6
-
7
- import { Quotation, QuotationStatus } from './quotation'
8
-
9
- @InputType()
10
- export class NewQuotation {
11
- @Field()
12
- name: string
13
-
14
- @Field({ nullable: true })
15
- description?: string
16
-
17
- @Field(type => QuotationStatus, { nullable: true })
18
- state?: QuotationStatus
19
-
20
- @Field({ nullable: true })
21
- active?: boolean
22
-
23
- @Field({ nullable: true })
24
- params?: string
25
-
26
- @Field(type => GraphQLUpload, { nullable: true })
27
- thumbnail?: FileUpload
28
- }
29
-
30
- @InputType()
31
- export class QuotationPatch {
32
- @Field(type => ID, { nullable: true })
33
- id?: string
34
-
35
- @Field({ nullable: true })
36
- name?: string
37
-
38
- @Field({ nullable: true })
39
- description?: string
40
-
41
- @Field(type => QuotationStatus, { nullable: true })
42
- state?: QuotationStatus
43
-
44
- @Field({ nullable: true })
45
- active?: boolean
46
-
47
- @Field(type => GraphQLUpload, { nullable: true })
48
- thumbnail?: FileUpload
49
-
50
- @Field({ nullable: true })
51
- cuFlag?: string
52
- }
53
-
54
- @ObjectType()
55
- export class QuotationList {
56
- @Field(type => [Quotation])
57
- items: Quotation[]
58
-
59
- @Field(type => Int)
60
- total: number
61
- }