@things-factory/notification 8.0.0-beta.9 → 8.0.0
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/client/actions/notification-fcm.ts +148 -0
- package/client/bootstrap.ts +135 -0
- package/client/index.ts +6 -0
- package/client/pages/notification/notification-list-page.ts +258 -0
- package/client/pages/notification-rule/notification-rule-importer.ts +87 -0
- package/client/pages/notification-rule/notification-rule-list-page.ts +386 -0
- package/client/reducers/notification.ts +27 -0
- package/client/route.ts +10 -0
- package/client/tsconfig.json +13 -0
- package/client/viewparts/notification-badge.ts +54 -0
- package/client/viewparts/notification-item.ts +246 -0
- package/client/viewparts/notification-list.ts +160 -0
- package/client/viewparts/notification-sender.ts +142 -0
- package/client/viewparts/notification-setting-let.ts +222 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/docs/images/config-app-1.png +0 -0
- package/docs/images/config-app-2.png +0 -0
- package/docs/images/config-server-key.png +0 -0
- package/docs/images/config-service-account.png +0 -0
- package/docs/images/config-vapidkey-1.png +0 -0
- package/docs/images/config-vapidkey-2-get-public-key.png +0 -0
- package/docs/images/config-vapidkey-3-get-private-key.png +0 -0
- package/docs/images/element-notification-badge.png +0 -0
- package/docs/images/element-notification-list.png +0 -0
- package/docs/images/element-notification-setting-let.png +0 -0
- package/docs/images/push-test-on-chrome-1.png +0 -0
- package/docs/images/push-test-on-chrome-2.png +0 -0
- package/docs/images/push-test-on-firebase-1.png +0 -0
- package/docs/images/push-test-on-firebase-2.png +0 -0
- package/docs/images/push-test-on-firebase-3.png +0 -0
- package/docs/images/push-test-on-firebase-4.png +0 -0
- package/package.json +9 -9
- package/server/controllers/fcm.ts +214 -0
- package/server/controllers/index.ts +1 -0
- package/server/index.ts +5 -0
- package/server/middlewares/index.ts +5 -0
- package/server/middlewares/notification-middleware.ts +73 -0
- package/server/routers/notification-router.ts +67 -0
- package/server/routes.ts +11 -0
- package/server/service/index.ts +42 -0
- package/server/service/notification/directive-notification.ts +71 -0
- package/server/service/notification/index.ts +14 -0
- package/server/service/notification/notification-mutation.ts +119 -0
- package/server/service/notification/notification-query.ts +76 -0
- package/server/service/notification/notification-subscription.ts +44 -0
- package/server/service/notification/notification-type.ts +55 -0
- package/server/service/notification/notification.ts +105 -0
- package/server/service/notification-rule/event-subscriber.ts +20 -0
- package/server/service/notification-rule/index.ts +9 -0
- package/server/service/notification-rule/notification-rule-history.ts +136 -0
- package/server/service/notification-rule/notification-rule-mutation.ts +203 -0
- package/server/service/notification-rule/notification-rule-query.ts +65 -0
- package/server/service/notification-rule/notification-rule-type.ts +71 -0
- package/server/service/notification-rule/notification-rule.ts +125 -0
- package/server/tsconfig.json +9 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Notification } from './notification'
|
|
5
|
+
import { NewNotification, NotificationPatch } from './notification-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Notification)
|
|
8
|
+
export class NotificationMutation {
|
|
9
|
+
@Directive('@transaction')
|
|
10
|
+
@Mutation(returns => Notification, { description: 'To create new Notification' })
|
|
11
|
+
async createNotification(
|
|
12
|
+
@Arg('notification') notification: NewNotification,
|
|
13
|
+
@Ctx() context: ResolverContext
|
|
14
|
+
): Promise<Notification> {
|
|
15
|
+
const { domain, user, tx } = context.state
|
|
16
|
+
|
|
17
|
+
return await tx.getRepository(Notification).save({
|
|
18
|
+
...notification,
|
|
19
|
+
domain,
|
|
20
|
+
creator: user,
|
|
21
|
+
updater: user
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Directive('@transaction')
|
|
26
|
+
@Mutation(returns => Notification, { description: 'To modify Notification information' })
|
|
27
|
+
async updateNotification(
|
|
28
|
+
@Arg('id') id: string,
|
|
29
|
+
@Arg('patch') patch: NotificationPatch,
|
|
30
|
+
@Ctx() context: ResolverContext
|
|
31
|
+
): Promise<Notification> {
|
|
32
|
+
const { domain, user, tx } = context.state
|
|
33
|
+
|
|
34
|
+
const repository = tx.getRepository(Notification)
|
|
35
|
+
const notification = await repository.findOne({
|
|
36
|
+
where: { domain: { id: domain.id }, id }
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const result = await repository.save({
|
|
40
|
+
...notification,
|
|
41
|
+
...patch,
|
|
42
|
+
updater: user
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return result
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Directive('@transaction')
|
|
49
|
+
@Mutation(returns => [Notification], { description: "To modify multiple Notificationes' information" })
|
|
50
|
+
async updateMultipleNotification(
|
|
51
|
+
@Arg('patches', type => [NotificationPatch]) patches: NotificationPatch[],
|
|
52
|
+
@Ctx() context: ResolverContext
|
|
53
|
+
): Promise<Notification[]> {
|
|
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 notificationRepo = tx.getRepository(Notification)
|
|
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 notificationRepo.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 updateRecord = _updateRecords[i]
|
|
79
|
+
const notification = await notificationRepo.findOneBy({ id: updateRecord.id })
|
|
80
|
+
|
|
81
|
+
const result = await notificationRepo.save({
|
|
82
|
+
...notification,
|
|
83
|
+
...updateRecord,
|
|
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 Notification' })
|
|
96
|
+
async deleteNotification(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
97
|
+
const { domain, tx } = context.state
|
|
98
|
+
|
|
99
|
+
await tx.getRepository(Notification).delete({ domain: { id: domain.id }, id })
|
|
100
|
+
|
|
101
|
+
return true
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Directive('@transaction')
|
|
105
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple Notificationes' })
|
|
106
|
+
async deleteNotificationes(
|
|
107
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
108
|
+
@Ctx() context: ResolverContext
|
|
109
|
+
): Promise<boolean> {
|
|
110
|
+
const { domain, tx } = context.state
|
|
111
|
+
|
|
112
|
+
await tx.getRepository(Notification).delete({
|
|
113
|
+
domain: { id: domain.id },
|
|
114
|
+
id: In(ids)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
return true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam, ScalarDate } from '@things-factory/shell'
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Notification } from './notification'
|
|
5
|
+
import { NotificationList } from './notification-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Notification)
|
|
8
|
+
export class NotificationQuery {
|
|
9
|
+
@Query(returns => Notification!, { nullable: true, description: 'To fetch a Notification' })
|
|
10
|
+
async notification(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Notification> {
|
|
11
|
+
const { domain } = context.state
|
|
12
|
+
|
|
13
|
+
return await getRepository(Notification).findOne({
|
|
14
|
+
where: { domain: { id: domain.id }, id }
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Query(returns => NotificationList, { description: 'To fetch multiple Notificationes' })
|
|
19
|
+
async notificationes(
|
|
20
|
+
@Args(type => ListParam) params: ListParam,
|
|
21
|
+
@Ctx() context: ResolverContext
|
|
22
|
+
): Promise<NotificationList> {
|
|
23
|
+
const { domain } = context.state
|
|
24
|
+
|
|
25
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
26
|
+
domain,
|
|
27
|
+
params,
|
|
28
|
+
repository: await getRepository(Notification),
|
|
29
|
+
searchables: ['title', 'body']
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
33
|
+
|
|
34
|
+
return { items, total }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Query(returns => NotificationList, { description: 'To fetch my notifications' })
|
|
38
|
+
async myNotifications(
|
|
39
|
+
@Args(type => ListParam) params: ListParam,
|
|
40
|
+
@Ctx() context: ResolverContext
|
|
41
|
+
): Promise<NotificationList> {
|
|
42
|
+
const { domain, user } = context.state
|
|
43
|
+
|
|
44
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
45
|
+
domain,
|
|
46
|
+
params,
|
|
47
|
+
alias: 'nb',
|
|
48
|
+
repository: await getRepository(Notification),
|
|
49
|
+
searchables: ['title', 'body']
|
|
50
|
+
}).andWhere('nb.owner = :user', { user: user.id })
|
|
51
|
+
|
|
52
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
53
|
+
|
|
54
|
+
return { items, total }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@FieldResolver(type => User)
|
|
58
|
+
async owner(@Root() notification: Notification): Promise<User> {
|
|
59
|
+
return notification.ownerId && (await getRepository(User).findOneBy({ id: notification.ownerId }))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@FieldResolver(type => Domain)
|
|
63
|
+
async domain(@Root() notification: Notification): Promise<Domain> {
|
|
64
|
+
return notification.domainId && (await getRepository(Domain).findOneBy({ id: notification.domainId }))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@FieldResolver(type => User)
|
|
68
|
+
async updater(@Root() notification: Notification): Promise<User> {
|
|
69
|
+
return notification.updaterId && (await getRepository(User).findOneBy({ id: notification.updaterId }))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@FieldResolver(type => User)
|
|
73
|
+
async creator(@Root() notification: Notification): Promise<User> {
|
|
74
|
+
return notification.creatorId && (await getRepository(User).findOneBy({ id: notification.creatorId }))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { filter, pipe } from 'graphql-yoga'
|
|
2
|
+
import { Arg, Resolver, FieldResolver, Root, Subscription } from 'type-graphql'
|
|
3
|
+
|
|
4
|
+
import { pubsub, ScalarDate } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { Notification } from './notification'
|
|
7
|
+
|
|
8
|
+
@Resolver(Notification)
|
|
9
|
+
export class NotificationSubscription {
|
|
10
|
+
@Subscription({
|
|
11
|
+
subscribe: ({ args, context, info }) => {
|
|
12
|
+
const { subjects = [] } = args
|
|
13
|
+
|
|
14
|
+
return pipe(
|
|
15
|
+
pubsub.subscribe('notification'),
|
|
16
|
+
filter(async (payload: { notification: Notification }) => {
|
|
17
|
+
/* normally, subscription context doesn't have domain */
|
|
18
|
+
const { domain, user } = context.state
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
notification: { subject, domain: pdomain }
|
|
22
|
+
} = payload
|
|
23
|
+
|
|
24
|
+
const subdomain = pdomain?.subdomain
|
|
25
|
+
|
|
26
|
+
if (subdomain) {
|
|
27
|
+
if (domain?.subdomain) {
|
|
28
|
+
if (subdomain !== domain.subdomain) {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
} else if (!user.domains.find(d => d.subdomain === subdomain)) {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return !subject || subjects.indexOf(subject) !== -1
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
notification(@Root() payload: { notification: Notification }, @Arg('subjects', type => [String], { nullable: true }) subjects: string[]): Notification {
|
|
42
|
+
return payload.notification
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ObjectType, Field, InputType, Int, ID } from 'type-graphql'
|
|
2
|
+
import { ScalarObject } from '@things-factory/shell'
|
|
3
|
+
|
|
4
|
+
import { Notification, NotificationStatus } from './notification'
|
|
5
|
+
|
|
6
|
+
@InputType()
|
|
7
|
+
export class NewNotification {
|
|
8
|
+
@Field({ nullable: true })
|
|
9
|
+
ownerId?: string
|
|
10
|
+
|
|
11
|
+
@Field({ nullable: true })
|
|
12
|
+
type?: string
|
|
13
|
+
|
|
14
|
+
@Field({ nullable: true })
|
|
15
|
+
subject?: string
|
|
16
|
+
|
|
17
|
+
@Field({ nullable: true })
|
|
18
|
+
title?: string
|
|
19
|
+
|
|
20
|
+
@Field({ nullable: true })
|
|
21
|
+
body?: string
|
|
22
|
+
|
|
23
|
+
@Field({ nullable: true })
|
|
24
|
+
url?: string
|
|
25
|
+
|
|
26
|
+
@Field({ nullable: true })
|
|
27
|
+
image?: string
|
|
28
|
+
|
|
29
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
30
|
+
property?: any
|
|
31
|
+
|
|
32
|
+
@Field({ nullable: true })
|
|
33
|
+
timestamp?: Date
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@InputType()
|
|
37
|
+
export class NotificationPatch {
|
|
38
|
+
@Field(type => ID, { nullable: true })
|
|
39
|
+
id?: string
|
|
40
|
+
|
|
41
|
+
@Field(type => NotificationStatus, { nullable: true })
|
|
42
|
+
state?: NotificationStatus
|
|
43
|
+
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
cuFlag?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ObjectType()
|
|
49
|
+
export class NotificationList {
|
|
50
|
+
@Field(type => [Notification])
|
|
51
|
+
items: Notification[]
|
|
52
|
+
|
|
53
|
+
@Field(type => Int)
|
|
54
|
+
total: number
|
|
55
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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, registerEnumType } from 'type-graphql'
|
|
12
|
+
|
|
13
|
+
import { Domain, ScalarObject, ScalarDate } from '@things-factory/shell'
|
|
14
|
+
import { User } from '@things-factory/auth-base'
|
|
15
|
+
|
|
16
|
+
export enum NotificationStatus {
|
|
17
|
+
NOTREAD = 'UNREAD',
|
|
18
|
+
READ = 'READ'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
registerEnumType(NotificationStatus, {
|
|
22
|
+
name: 'NotificationStatus',
|
|
23
|
+
description: 'state enumeration of a notification'
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
@Entity()
|
|
27
|
+
@Index('ix_notification_0', (notification: Notification) => [notification.domain, notification.type], { unique: false })
|
|
28
|
+
@ObjectType({ description: 'Entity for Notification' })
|
|
29
|
+
export class Notification {
|
|
30
|
+
@PrimaryGeneratedColumn('uuid')
|
|
31
|
+
@Field(type => ID)
|
|
32
|
+
readonly id: string
|
|
33
|
+
|
|
34
|
+
@ManyToOne(type => Domain)
|
|
35
|
+
@Field(type => Domain)
|
|
36
|
+
domain?: Domain
|
|
37
|
+
|
|
38
|
+
@RelationId((notification: Notification) => notification.domain)
|
|
39
|
+
domainId?: string
|
|
40
|
+
|
|
41
|
+
@ManyToOne(type => User, { nullable: true })
|
|
42
|
+
@Field(type => User, { nullable: true })
|
|
43
|
+
owner?: User
|
|
44
|
+
|
|
45
|
+
@RelationId((notification: Notification) => notification.owner)
|
|
46
|
+
ownerId?: string
|
|
47
|
+
|
|
48
|
+
@Column({ nullable: true })
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
type?: string
|
|
51
|
+
|
|
52
|
+
@Column({ nullable: true })
|
|
53
|
+
@Field({ nullable: true })
|
|
54
|
+
subject?: string
|
|
55
|
+
|
|
56
|
+
@Column({ nullable: true })
|
|
57
|
+
@Field({ nullable: true })
|
|
58
|
+
title?: string
|
|
59
|
+
|
|
60
|
+
@Column({ nullable: true })
|
|
61
|
+
@Field({ nullable: true })
|
|
62
|
+
body?: string
|
|
63
|
+
|
|
64
|
+
@Column({ nullable: true })
|
|
65
|
+
@Field({ nullable: true })
|
|
66
|
+
url?: string
|
|
67
|
+
|
|
68
|
+
@Column({ nullable: true })
|
|
69
|
+
@Field({ nullable: true })
|
|
70
|
+
image?: string
|
|
71
|
+
|
|
72
|
+
@Column({ nullable: true })
|
|
73
|
+
@Field({ nullable: true })
|
|
74
|
+
state?: NotificationStatus
|
|
75
|
+
|
|
76
|
+
@Column('simple-json', { nullable: true })
|
|
77
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
78
|
+
property?: any
|
|
79
|
+
|
|
80
|
+
@Column('date', { nullable: true })
|
|
81
|
+
@Field(type => ScalarDate, { nullable: true })
|
|
82
|
+
timestamp?: Date
|
|
83
|
+
|
|
84
|
+
@CreateDateColumn()
|
|
85
|
+
@Field({ nullable: true })
|
|
86
|
+
createdAt?: Date
|
|
87
|
+
|
|
88
|
+
@UpdateDateColumn()
|
|
89
|
+
@Field({ nullable: true })
|
|
90
|
+
updatedAt?: Date
|
|
91
|
+
|
|
92
|
+
@ManyToOne(type => User, { nullable: true })
|
|
93
|
+
@Field(type => User, { nullable: true })
|
|
94
|
+
creator?: User
|
|
95
|
+
|
|
96
|
+
@RelationId((notification: Notification) => notification.creator)
|
|
97
|
+
creatorId?: string
|
|
98
|
+
|
|
99
|
+
@ManyToOne(type => User, { nullable: true })
|
|
100
|
+
@Field(type => User, { nullable: true })
|
|
101
|
+
updater?: User
|
|
102
|
+
|
|
103
|
+
@RelationId((notification: Notification) => notification.updater)
|
|
104
|
+
updaterId?: string
|
|
105
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EventSubscriber } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { HistoryEntitySubscriber } from '@operato/typeorm-history'
|
|
4
|
+
|
|
5
|
+
import { NotificationRule } from './notification-rule'
|
|
6
|
+
import { NotificationRuleHistory } from './notification-rule-history'
|
|
7
|
+
|
|
8
|
+
@EventSubscriber()
|
|
9
|
+
export class NotificationRuleHistoryEntitySubscriber extends HistoryEntitySubscriber<
|
|
10
|
+
NotificationRule,
|
|
11
|
+
NotificationRuleHistory
|
|
12
|
+
> {
|
|
13
|
+
public get entity() {
|
|
14
|
+
return NotificationRule
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public get historyEntity() {
|
|
18
|
+
return NotificationRuleHistory
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NotificationRule } from './notification-rule'
|
|
2
|
+
import { NotificationRuleHistory } from './notification-rule-history'
|
|
3
|
+
import { NotificationRuleQuery } from './notification-rule-query'
|
|
4
|
+
import { NotificationRuleMutation } from './notification-rule-mutation'
|
|
5
|
+
import { NotificationRuleHistoryEntitySubscriber } from './event-subscriber'
|
|
6
|
+
|
|
7
|
+
export const entities = [NotificationRule, NotificationRuleHistory]
|
|
8
|
+
export const resolvers = [NotificationRuleQuery, NotificationRuleMutation]
|
|
9
|
+
export const subscribers = [NotificationRuleHistoryEntitySubscriber]
|
|
@@ -0,0 +1,136 @@
|
|
|
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 { NotificationRule, NotificationRuleStatus, RecipientItem } from './notification-rule'
|
|
15
|
+
|
|
16
|
+
const ORMCONFIG = config.get('ormconfig', {})
|
|
17
|
+
const DATABASE_TYPE = ORMCONFIG.type
|
|
18
|
+
|
|
19
|
+
@Entity()
|
|
20
|
+
@Index(
|
|
21
|
+
'ix_notification-rule_history_0',
|
|
22
|
+
(notificationRuleHistory: NotificationRuleHistory) => [
|
|
23
|
+
notificationRuleHistory.originalId,
|
|
24
|
+
notificationRuleHistory.version
|
|
25
|
+
],
|
|
26
|
+
{ unique: true }
|
|
27
|
+
)
|
|
28
|
+
@Index(
|
|
29
|
+
'ix_notification-rule_history_1',
|
|
30
|
+
(notificationRuleHistory: NotificationRuleHistory) => [
|
|
31
|
+
notificationRuleHistory.domain,
|
|
32
|
+
notificationRuleHistory.originalId,
|
|
33
|
+
notificationRuleHistory.version
|
|
34
|
+
],
|
|
35
|
+
{ unique: true }
|
|
36
|
+
)
|
|
37
|
+
@ObjectType({ description: 'History Entity of NotificationRule' })
|
|
38
|
+
export class NotificationRuleHistory implements HistoryEntityInterface<NotificationRule> {
|
|
39
|
+
@PrimaryGeneratedColumn('uuid')
|
|
40
|
+
@Field(type => ID)
|
|
41
|
+
readonly id: string
|
|
42
|
+
|
|
43
|
+
@Column({ nullable: true, default: 1 })
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
version?: number = 1
|
|
46
|
+
|
|
47
|
+
@ManyToOne(type => Domain)
|
|
48
|
+
@Field(type => Domain)
|
|
49
|
+
domain?: Domain
|
|
50
|
+
|
|
51
|
+
@RelationId((notificationRule: NotificationRule) => notificationRule.domain)
|
|
52
|
+
domainId?: string
|
|
53
|
+
|
|
54
|
+
@Column()
|
|
55
|
+
@Field()
|
|
56
|
+
name: string
|
|
57
|
+
|
|
58
|
+
@Column({ nullable: true })
|
|
59
|
+
@Field({ nullable: true })
|
|
60
|
+
description?: string
|
|
61
|
+
|
|
62
|
+
@Column({ nullable: true })
|
|
63
|
+
@Field({ nullable: true })
|
|
64
|
+
state?: NotificationRuleStatus
|
|
65
|
+
|
|
66
|
+
@Column({ nullable: true })
|
|
67
|
+
@Field({ nullable: true })
|
|
68
|
+
title: string
|
|
69
|
+
|
|
70
|
+
@Column({ nullable: true })
|
|
71
|
+
@Field({ nullable: true })
|
|
72
|
+
body: string
|
|
73
|
+
|
|
74
|
+
@Column({ nullable: true })
|
|
75
|
+
@Field({ nullable: true })
|
|
76
|
+
url: string
|
|
77
|
+
|
|
78
|
+
@Column({ nullable: true })
|
|
79
|
+
@Field({ nullable: true })
|
|
80
|
+
thumbnail: string
|
|
81
|
+
|
|
82
|
+
@Column({ nullable: true })
|
|
83
|
+
@Field({ nullable: true })
|
|
84
|
+
channels: string
|
|
85
|
+
|
|
86
|
+
@Column('simple-json', { nullable: true })
|
|
87
|
+
@Field(type => [RecipientItem], { nullable: true, description: 'notification recipients.' })
|
|
88
|
+
recipients: string
|
|
89
|
+
|
|
90
|
+
@Column({ nullable: true })
|
|
91
|
+
@Field({ nullable: true })
|
|
92
|
+
createdAt?: Date
|
|
93
|
+
|
|
94
|
+
@Column({ nullable: true })
|
|
95
|
+
@Field({ nullable: true })
|
|
96
|
+
updatedAt?: Date
|
|
97
|
+
|
|
98
|
+
@Column({ nullable: true })
|
|
99
|
+
@Field({ nullable: true })
|
|
100
|
+
deletedAt?: Date
|
|
101
|
+
|
|
102
|
+
@ManyToOne(type => User, { nullable: true })
|
|
103
|
+
@Field(type => User, { nullable: true })
|
|
104
|
+
creator?: User
|
|
105
|
+
|
|
106
|
+
@RelationId((notificationRule: NotificationRule) => notificationRule.creator)
|
|
107
|
+
creatorId?: string
|
|
108
|
+
|
|
109
|
+
@ManyToOne(type => User, { nullable: true })
|
|
110
|
+
@Field(type => User, { nullable: true })
|
|
111
|
+
updater?: User
|
|
112
|
+
|
|
113
|
+
@RelationId((notificationRule: NotificationRule) => notificationRule.updater)
|
|
114
|
+
updaterId?: string
|
|
115
|
+
|
|
116
|
+
@HistoryOriginalIdColumn()
|
|
117
|
+
public originalId!: string
|
|
118
|
+
|
|
119
|
+
@HistoryActionColumn({
|
|
120
|
+
nullable: false,
|
|
121
|
+
type:
|
|
122
|
+
DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
123
|
+
? 'enum'
|
|
124
|
+
: DATABASE_TYPE == 'oracle'
|
|
125
|
+
? 'varchar2'
|
|
126
|
+
: DATABASE_TYPE == 'mssql'
|
|
127
|
+
? 'nvarchar'
|
|
128
|
+
: 'varchar',
|
|
129
|
+
enum:
|
|
130
|
+
DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
131
|
+
? HistoryActionType
|
|
132
|
+
: undefined,
|
|
133
|
+
length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
|
|
134
|
+
})
|
|
135
|
+
public action!: HistoryActionType
|
|
136
|
+
}
|