@things-factory/worklist 6.0.21 → 6.0.24

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/worklist",
3
- "version": "6.0.21",
3
+ "version": "6.0.24",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -27,11 +27,11 @@
27
27
  "dependencies": {
28
28
  "@operato/graphql": "^1.0.0",
29
29
  "@operato/grist-editor": "^1.0.0",
30
- "@things-factory/attachment-base": "^6.0.21",
31
- "@things-factory/auth-base": "^6.0.21",
32
- "@things-factory/board-service": "^6.0.21",
33
- "@things-factory/organization": "^6.0.21",
34
- "@things-factory/shell": "^6.0.21"
30
+ "@things-factory/attachment-base": "^6.0.24",
31
+ "@things-factory/auth-base": "^6.0.24",
32
+ "@things-factory/board-service": "^6.0.24",
33
+ "@things-factory/organization": "^6.0.24",
34
+ "@things-factory/shell": "^6.0.24"
35
35
  },
36
- "gitHead": "074a4f460d08fed4bc7e9882aa57f4c120cf0f11"
36
+ "gitHead": "27c1a4c3bcf4f293e7e676caa1f2daa3bb6ded11"
37
37
  }
@@ -0,0 +1,52 @@
1
+ import { In } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+
5
+ import { ActivityInstance, ActivityInstanceStatus } from '../../service/activity-instance/activity-instance'
6
+ import { ActivityInstancePost } from '../../service/activity-instance/activity-instance-type'
7
+ import { createActivityThreadsForAllRoleUsers, createActivityThreadsForUsers } from '../common'
8
+
9
+ export async function bid(activityInstance: ActivityInstancePost, context: ResolverContext): Promise<ActivityInstance> {
10
+ const { domain, user, tx } = context.state
11
+ const { id, assignees } = activityInstance
12
+
13
+ var origin = id
14
+ ? await tx.getRepository(ActivityInstance).findOne({
15
+ where: { domain: { id: domain.id }, id },
16
+ relations: [
17
+ 'domain',
18
+ 'activity',
19
+ 'assigneeRole',
20
+ 'supervisoryRole',
21
+ 'updater',
22
+ 'creator',
23
+ 'starter',
24
+ 'terminator'
25
+ ]
26
+ })
27
+ : null
28
+
29
+ const bid = await tx.getRepository(ActivityInstance).save({
30
+ ...origin,
31
+ ...activityInstance,
32
+ transaction: 'bid',
33
+ state: ActivityInstanceStatus.Posted,
34
+ domain,
35
+ creator: user,
36
+ updater: user
37
+ })
38
+
39
+ const assignedUsers = await tx.getRepository(User).findBy({
40
+ email: In(assignees || [])
41
+ })
42
+
43
+ if (bid.threadsMin === 0 && bid.assigneeRoleId) {
44
+ await createActivityThreadsForAllRoleUsers('post', bid, context)
45
+ }
46
+
47
+ if (assignedUsers.length > 0) {
48
+ await createActivityThreadsForUsers('post', bid, assignedUsers, context)
49
+ }
50
+
51
+ return await tx.getRepository(ActivityInstance).findOneBy({ id: bid.id })
52
+ }
@@ -0,0 +1,37 @@
1
+ import { Application } from '@things-factory/auth-base'
2
+ import { Domain, getRepository } from '@things-factory/shell'
3
+
4
+ export async function callWebhook(domain: Domain, tag: string, data: any) {
5
+ /*
6
+ TODO webhook callback의 다양한 subscription 조건을 지원한다.
7
+ - activity의 client에 해당하는 application
8
+ - activityInstance의 starter에 해당하는 application
9
+ - 모든 이벤트를 받고자하는 application
10
+ - 특정 activity들의 이벤트를 받고자하는 application
11
+ */
12
+
13
+ const applications = await getRepository(Application).findBy({ domain: { id: domain.id } })
14
+ const options = {
15
+ method: 'post',
16
+ headers: {
17
+ 'x-things-factory-domain': domain.name,
18
+ 'Content-Type': 'application/json'
19
+ },
20
+ body: {
21
+ tag,
22
+ data
23
+ } as any
24
+ }
25
+
26
+ try {
27
+ applications
28
+ .filter(app => app.webhook)
29
+ .every(app => {
30
+ const webhook = app.webhook
31
+
32
+ fetch(webhook, options)
33
+ })
34
+ } catch (err) {
35
+ console.error(err)
36
+ }
37
+ }
@@ -173,6 +173,13 @@ export class Activity {
173
173
  @Field({ nullable: true })
174
174
  updatedAt?: Date
175
175
 
176
+ @ManyToOne(type => User, { nullable: true })
177
+ @Field(type => User, { nullable: true, description: 'User assigned to the client application' })
178
+ client?: User
179
+
180
+ @RelationId((activity: Activity) => activity.creator)
181
+ clientId?: string
182
+
176
183
  @ManyToOne(type => User, { nullable: true })
177
184
  @Field(type => User, { nullable: true })
178
185
  creator?: User
@@ -3,6 +3,7 @@ import { EventSubscriber, EntitySubscriberInterface, InsertEvent, UpdateEvent }
3
3
  import { pubsub } from '@things-factory/shell'
4
4
 
5
5
  import { ActivityApproval } from './activity-approval'
6
+ import { callWebhook } from '../../controllers/call-webhook'
6
7
 
7
8
  @EventSubscriber()
8
9
  export class ActivityApprovalSubscriber implements EntitySubscriberInterface<ActivityApproval> {
@@ -16,6 +17,8 @@ export class ActivityApprovalSubscriber implements EntitySubscriberInterface<Act
16
17
  pubsub.publish('activity-approval', {
17
18
  activityApproval
18
19
  })
20
+
21
+ callWebhook(activityApproval.domain, 'activity-approval-created', activityApproval)
19
22
  }
20
23
 
21
24
  afterUpdate(event: UpdateEvent<ActivityApproval>): Promise<any> | void {
@@ -24,5 +27,7 @@ export class ActivityApprovalSubscriber implements EntitySubscriberInterface<Act
24
27
  pubsub.publish('activity-approval', {
25
28
  activityApproval
26
29
  })
30
+
31
+ callWebhook(activityApproval.domain, 'activity-approval-updated', activityApproval)
27
32
  }
28
33
  }