@things-factory/calendar 6.0.45
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/CHANGELOG.md +8 -0
- package/assets/images/hatiolab-logo.png +0 -0
- package/client/bootstrap.ts +1 -0
- package/client/index.ts +0 -0
- package/client/pages/attendee/attendee-importer.ts +97 -0
- package/client/pages/attendee/attendee-list-page.ts +348 -0
- package/client/pages/calendar/calendar-importer.ts +97 -0
- package/client/pages/calendar/calendar-list-page.ts +348 -0
- package/client/pages/calendar/calendar-page.ts +128 -0
- package/client/pages/event/event-importer.ts +97 -0
- package/client/pages/event/event-list-page.ts +348 -0
- package/client/route.ts +19 -0
- package/client/themes/calendar-theme.css +54 -0
- package/client/tsconfig.json +11 -0
- package/concept.md +31 -0
- package/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +2 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/index.d.ts +0 -0
- package/dist-client/index.js +2 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/pages/attendee/attendee-importer.d.ts +22 -0
- package/dist-client/pages/attendee/attendee-importer.js +100 -0
- package/dist-client/pages/attendee/attendee-importer.js.map +1 -0
- package/dist-client/pages/attendee/attendee-list-page.d.ts +62 -0
- package/dist-client/pages/attendee/attendee-list-page.js +326 -0
- package/dist-client/pages/attendee/attendee-list-page.js.map +1 -0
- package/dist-client/pages/calendar/calendar-importer.d.ts +22 -0
- package/dist-client/pages/calendar/calendar-importer.js +100 -0
- package/dist-client/pages/calendar/calendar-importer.js.map +1 -0
- package/dist-client/pages/calendar/calendar-list-page.d.ts +62 -0
- package/dist-client/pages/calendar/calendar-list-page.js +326 -0
- package/dist-client/pages/calendar/calendar-list-page.js.map +1 -0
- package/dist-client/pages/calendar/calendar-page.d.ts +26 -0
- package/dist-client/pages/calendar/calendar-page.js +128 -0
- package/dist-client/pages/calendar/calendar-page.js.map +1 -0
- package/dist-client/pages/event/event-importer.d.ts +22 -0
- package/dist-client/pages/event/event-importer.js +100 -0
- package/dist-client/pages/event/event-importer.js.map +1 -0
- package/dist-client/pages/event/event-list-page.d.ts +62 -0
- package/dist-client/pages/event/event-list-page.js +326 -0
- package/dist-client/pages/event/event-list-page.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +17 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/controllers/index.js +1 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/index.js +7 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/middlewares/index.js +8 -0
- package/dist-server/middlewares/index.js.map +1 -0
- package/dist-server/migrations/index.js +12 -0
- package/dist-server/migrations/index.js.map +1 -0
- package/dist-server/routes.js +25 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/attendee/attendee-mutation.js +124 -0
- package/dist-server/service/attendee/attendee-mutation.js.map +1 -0
- package/dist-server/service/attendee/attendee-query.js +47 -0
- package/dist-server/service/attendee/attendee-query.js.map +1 -0
- package/dist-server/service/attendee/attendee-type.js +65 -0
- package/dist-server/service/attendee/attendee-type.js.map +1 -0
- package/dist-server/service/attendee/attendee.js +46 -0
- package/dist-server/service/attendee/attendee.js.map +1 -0
- package/dist-server/service/attendee/index.js +10 -0
- package/dist-server/service/attendee/index.js.map +1 -0
- package/dist-server/service/calendar/calendar-mutation.js +168 -0
- package/dist-server/service/calendar/calendar-mutation.js.map +1 -0
- package/dist-server/service/calendar/calendar-query.js +97 -0
- package/dist-server/service/calendar/calendar-query.js.map +1 -0
- package/dist-server/service/calendar/calendar-type.js +86 -0
- package/dist-server/service/calendar/calendar-type.js.map +1 -0
- package/dist-server/service/calendar/calendar.js +93 -0
- package/dist-server/service/calendar/calendar.js.map +1 -0
- package/dist-server/service/calendar/index.js +10 -0
- package/dist-server/service/calendar/index.js.map +1 -0
- package/dist-server/service/event/event-mutation.js +124 -0
- package/dist-server/service/event/event-mutation.js.map +1 -0
- package/dist-server/service/event/event-query.js +66 -0
- package/dist-server/service/event/event-query.js.map +1 -0
- package/dist-server/service/event/event-type.js +86 -0
- package/dist-server/service/event/event-type.js.map +1 -0
- package/dist-server/service/event/event.js +94 -0
- package/dist-server/service/event/event.js.map +1 -0
- package/dist-server/service/event/index.js +10 -0
- package/dist-server/service/event/index.js.map +1 -0
- package/dist-server/service/index.js +33 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/helps/calendar/attendee.md +160 -0
- package/helps/calendar/calendar.md +160 -0
- package/helps/calendar/event.md +160 -0
- package/package.json +36 -0
- package/server/controllers/index.ts +0 -0
- package/server/index.ts +4 -0
- package/server/middlewares/index.ts +3 -0
- package/server/migrations/index.ts +9 -0
- package/server/routes.ts +28 -0
- package/server/service/attendee/attendee-mutation.ts +122 -0
- package/server/service/attendee/attendee-query.ts +31 -0
- package/server/service/attendee/attendee-type.ts +44 -0
- package/server/service/attendee/attendee.ts +36 -0
- package/server/service/attendee/index.ts +7 -0
- package/server/service/calendar/calendar-mutation.ts +198 -0
- package/server/service/calendar/calendar-query.ts +62 -0
- package/server/service/calendar/calendar-type.ts +61 -0
- package/server/service/calendar/calendar.ts +82 -0
- package/server/service/calendar/index.ts +7 -0
- package/server/service/event/event-mutation.ts +125 -0
- package/server/service/event/event-query.ts +38 -0
- package/server/service/event/event-type.ts +61 -0
- package/server/service/event/event.ts +85 -0
- package/server/service/event/index.ts +7 -0
- package/server/service/index.ts +32 -0
- package/server/tsconfig.json +10 -0
- package/things-factory.config.js +25 -0
- package/translations/en.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Attendee } from './attendee'
|
|
5
|
+
import { AttendeeList } from './attendee-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Attendee)
|
|
8
|
+
export class AttendeeQuery {
|
|
9
|
+
@Query(returns => Attendee!, { nullable: true, description: 'To fetch a Attendee' })
|
|
10
|
+
async attendee(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Attendee> {
|
|
11
|
+
return await getRepository(Attendee).findOne({
|
|
12
|
+
where: { id }
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Query(returns => AttendeeList, { description: 'To fetch multiple Attendees' })
|
|
17
|
+
async attendees(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<AttendeeList> {
|
|
18
|
+
const { domain } = context.state
|
|
19
|
+
|
|
20
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
21
|
+
domain,
|
|
22
|
+
params,
|
|
23
|
+
repository: await getRepository(Attendee),
|
|
24
|
+
searchables: ['name', 'description']
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
28
|
+
|
|
29
|
+
return { items, total }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { ObjectRef, ScalarObject } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { Attendee, AttendeeStatus } from './attendee'
|
|
6
|
+
|
|
7
|
+
@InputType()
|
|
8
|
+
export class NewAttendee {
|
|
9
|
+
@Field()
|
|
10
|
+
name: string
|
|
11
|
+
|
|
12
|
+
@Field({ nullable: true })
|
|
13
|
+
description?: string
|
|
14
|
+
|
|
15
|
+
@Field(type => AttendeeStatus, { nullable: true })
|
|
16
|
+
state?: AttendeeStatus
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@InputType()
|
|
20
|
+
export class AttendeePatch {
|
|
21
|
+
@Field(type => ID, { nullable: true })
|
|
22
|
+
id?: string
|
|
23
|
+
|
|
24
|
+
@Field({ nullable: true })
|
|
25
|
+
name?: string
|
|
26
|
+
|
|
27
|
+
@Field({ nullable: true })
|
|
28
|
+
description?: string
|
|
29
|
+
|
|
30
|
+
@Field(type => AttendeeStatus, { nullable: true })
|
|
31
|
+
state?: AttendeeStatus
|
|
32
|
+
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
cuFlag?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@ObjectType()
|
|
38
|
+
export class AttendeeList {
|
|
39
|
+
@Field(type => [Attendee])
|
|
40
|
+
items: Attendee[]
|
|
41
|
+
|
|
42
|
+
@Field(type => Int)
|
|
43
|
+
total: number
|
|
44
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Entity, Index, Column, ManyToMany, JoinTable, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
+
import { ObjectType, Field, Int, ID, registerEnumType } from 'type-graphql'
|
|
3
|
+
|
|
4
|
+
import { Event } from '../event/event'
|
|
5
|
+
|
|
6
|
+
export enum AttendeeStatus {
|
|
7
|
+
STATUS_A = 'STATUS_A',
|
|
8
|
+
STATUS_B = 'STATUS_B'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
registerEnumType(AttendeeStatus, {
|
|
12
|
+
name: 'AttendeeStatus',
|
|
13
|
+
description: 'state enumeration of a attendee'
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
@Entity()
|
|
17
|
+
@Index('ix_attendee_0', (attendee: Attendee) => [attendee.email], { unique: false })
|
|
18
|
+
@ObjectType({ description: 'Entity for Attendee' })
|
|
19
|
+
export class Attendee {
|
|
20
|
+
@PrimaryGeneratedColumn('uuid')
|
|
21
|
+
@Field(type => ID)
|
|
22
|
+
readonly id: string
|
|
23
|
+
|
|
24
|
+
@Column()
|
|
25
|
+
@Field({ nullable: true })
|
|
26
|
+
name?: string
|
|
27
|
+
|
|
28
|
+
@Column()
|
|
29
|
+
@Field({ nullable: true })
|
|
30
|
+
email: string
|
|
31
|
+
|
|
32
|
+
@ManyToMany(() => Event)
|
|
33
|
+
@JoinTable()
|
|
34
|
+
@Field({ nullable: true })
|
|
35
|
+
events: Event[]
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Attendee } from './attendee'
|
|
2
|
+
import { AttendeeQuery } from './attendee-query'
|
|
3
|
+
import { AttendeeMutation } from './attendee-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [Attendee]
|
|
6
|
+
export const resolvers = [AttendeeQuery, AttendeeMutation]
|
|
7
|
+
export const subscribers = []
|
|
@@ -0,0 +1,198 @@
|
|
|
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 { Calendar } from './calendar'
|
|
7
|
+
import { NewCalendar, CalendarPatch } from './calendar-type'
|
|
8
|
+
|
|
9
|
+
@Resolver(Calendar)
|
|
10
|
+
export class CalendarMutation {
|
|
11
|
+
@Directive('@transaction')
|
|
12
|
+
@Mutation(returns => Calendar, { description: 'To create new Calendar' })
|
|
13
|
+
async createCalendar(@Arg('calendar') calendar: NewCalendar, @Ctx() context: ResolverContext): Promise<Calendar> {
|
|
14
|
+
const { domain, user, tx } = context.state
|
|
15
|
+
|
|
16
|
+
const result = await tx.getRepository(Calendar).save({
|
|
17
|
+
...calendar,
|
|
18
|
+
domain,
|
|
19
|
+
creator: user,
|
|
20
|
+
updater: user
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
if (calendar.thumbnail) {
|
|
24
|
+
await createAttachment(
|
|
25
|
+
null,
|
|
26
|
+
{
|
|
27
|
+
attachment: {
|
|
28
|
+
file: calendar.thumbnail,
|
|
29
|
+
refType: Calendar.name,
|
|
30
|
+
refBy: result.id
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
context
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Directive('@transaction')
|
|
41
|
+
@Mutation(returns => Calendar, { description: 'To modify Calendar information' })
|
|
42
|
+
async updateCalendar(
|
|
43
|
+
@Arg('id') id: string,
|
|
44
|
+
@Arg('patch') patch: CalendarPatch,
|
|
45
|
+
@Ctx() context: ResolverContext
|
|
46
|
+
): Promise<Calendar> {
|
|
47
|
+
const { domain, user, tx } = context.state
|
|
48
|
+
|
|
49
|
+
const repository = tx.getRepository(Calendar)
|
|
50
|
+
const calendar = await repository.findOne({
|
|
51
|
+
where: { domain: { id: domain.id }, id }
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const result = await repository.save({
|
|
55
|
+
...calendar,
|
|
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: Calendar.name,
|
|
68
|
+
refBy: result.id
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
context
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return result
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Directive('@transaction')
|
|
79
|
+
@Mutation(returns => [Calendar], { description: "To modify multiple Calendars' information" })
|
|
80
|
+
async updateMultipleCalendar(
|
|
81
|
+
@Arg('patches', type => [CalendarPatch]) patches: CalendarPatch[],
|
|
82
|
+
@Ctx() context: ResolverContext
|
|
83
|
+
): Promise<Calendar[]> {
|
|
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 calendarRepo = tx.getRepository(Calendar)
|
|
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 calendarRepo.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: Calendar.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 calendar = await calendarRepo.findOneBy({ id: updateRecord.id })
|
|
124
|
+
|
|
125
|
+
const result = await calendarRepo.save({
|
|
126
|
+
...calendar,
|
|
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: Calendar.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 Calendar' })
|
|
155
|
+
async deleteCalendar(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
156
|
+
const { domain, tx } = context.state
|
|
157
|
+
|
|
158
|
+
await tx.getRepository(Calendar).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 Calendars' })
|
|
166
|
+
async deleteCalendars(
|
|
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(Calendar).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 Calendars' })
|
|
184
|
+
async importCalendars(
|
|
185
|
+
@Arg('calendars', type => [CalendarPatch]) calendars: CalendarPatch[],
|
|
186
|
+
@Ctx() context: ResolverContext
|
|
187
|
+
): Promise<boolean> {
|
|
188
|
+
const { domain, tx } = context.state
|
|
189
|
+
|
|
190
|
+
await Promise.all(
|
|
191
|
+
calendars.map(async (calendar: CalendarPatch) => {
|
|
192
|
+
const createdCalendar: Calendar = await tx.getRepository(Calendar).save({ domain, ...calendar })
|
|
193
|
+
})
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
return true
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { Calendar } from './calendar'
|
|
6
|
+
import { CalendarList } from './calendar-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(Calendar)
|
|
9
|
+
export class CalendarQuery {
|
|
10
|
+
@Query(returns => Calendar!, { nullable: true, description: 'To fetch a Calendar' })
|
|
11
|
+
async calendar(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Calendar> {
|
|
12
|
+
const { domain } = context.state
|
|
13
|
+
|
|
14
|
+
return await getRepository(Calendar).findOne({
|
|
15
|
+
where: { domain: { id: domain.id }, id }
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Query(returns => CalendarList, { description: 'To fetch multiple Calendars' })
|
|
20
|
+
async calendars(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<CalendarList> {
|
|
21
|
+
const { domain } = context.state
|
|
22
|
+
|
|
23
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
24
|
+
domain,
|
|
25
|
+
params,
|
|
26
|
+
repository: await getRepository(Calendar),
|
|
27
|
+
searchables: ['name', 'description']
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
31
|
+
|
|
32
|
+
return { items, total }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@FieldResolver(type => String)
|
|
36
|
+
async thumbnail(@Root() calendar: Calendar): Promise<string | undefined> {
|
|
37
|
+
const attachment: Attachment = await getRepository(Attachment).findOne({
|
|
38
|
+
where: {
|
|
39
|
+
domain: { id: calendar.domainId },
|
|
40
|
+
refType: Calendar.name,
|
|
41
|
+
refBy: calendar.id
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return attachment?.fullpath
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@FieldResolver(type => Domain)
|
|
49
|
+
async domain(@Root() calendar: Calendar): Promise<Domain> {
|
|
50
|
+
return await getRepository(Domain).findOneBy({ id: calendar.domainId })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@FieldResolver(type => User)
|
|
54
|
+
async updater(@Root() calendar: Calendar): Promise<User> {
|
|
55
|
+
return await getRepository(User).findOneBy({ id: calendar.updaterId })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@FieldResolver(type => User)
|
|
59
|
+
async creator(@Root() calendar: Calendar): Promise<User> {
|
|
60
|
+
return await getRepository(User).findOneBy({ id: calendar.creatorId })
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { Calendar, CalendarStatus } from './calendar'
|
|
8
|
+
|
|
9
|
+
@InputType()
|
|
10
|
+
export class NewCalendar {
|
|
11
|
+
@Field()
|
|
12
|
+
name: string
|
|
13
|
+
|
|
14
|
+
@Field({ nullable: true })
|
|
15
|
+
description?: string
|
|
16
|
+
|
|
17
|
+
@Field(type => CalendarStatus, { nullable: true })
|
|
18
|
+
state?: CalendarStatus
|
|
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 CalendarPatch {
|
|
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 => CalendarStatus, { nullable: true })
|
|
42
|
+
state?: CalendarStatus
|
|
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 CalendarList {
|
|
56
|
+
@Field(type => [Calendar])
|
|
57
|
+
items: Calendar[]
|
|
58
|
+
|
|
59
|
+
@Field(type => Int)
|
|
60
|
+
total: number
|
|
61
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 } from '@things-factory/shell'
|
|
14
|
+
import { User } from '@things-factory/auth-base'
|
|
15
|
+
|
|
16
|
+
export enum CalendarStatus {
|
|
17
|
+
STATUS_A = 'STATUS_A',
|
|
18
|
+
STATUS_B = 'STATUS_B'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
registerEnumType(CalendarStatus, {
|
|
22
|
+
name: 'CalendarStatus',
|
|
23
|
+
description: 'state enumeration of a calendar'
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
@Entity()
|
|
27
|
+
@Index('ix_calendar_0', (calendar: Calendar) => [calendar.domain, calendar.name], { unique: true })
|
|
28
|
+
@ObjectType({ description: 'Entity for Calendar' })
|
|
29
|
+
export class Calendar {
|
|
30
|
+
@PrimaryGeneratedColumn('uuid')
|
|
31
|
+
@Field(type => ID)
|
|
32
|
+
readonly id: string
|
|
33
|
+
|
|
34
|
+
@ManyToOne(type => Domain)
|
|
35
|
+
@Field({ nullable: true })
|
|
36
|
+
domain?: Domain
|
|
37
|
+
|
|
38
|
+
@RelationId((calendar: Calendar) => calendar.domain)
|
|
39
|
+
domainId?: string
|
|
40
|
+
|
|
41
|
+
@Column()
|
|
42
|
+
@Field({ nullable: true })
|
|
43
|
+
name?: string
|
|
44
|
+
|
|
45
|
+
@Column({ nullable: true })
|
|
46
|
+
@Field({ nullable: true })
|
|
47
|
+
description?: string
|
|
48
|
+
|
|
49
|
+
@Column({ nullable: true })
|
|
50
|
+
@Field({ nullable: true })
|
|
51
|
+
active?: boolean
|
|
52
|
+
|
|
53
|
+
@Column({ nullable: true })
|
|
54
|
+
@Field({ nullable: true })
|
|
55
|
+
state?: CalendarStatus
|
|
56
|
+
|
|
57
|
+
@Column({ nullable: true })
|
|
58
|
+
@Field({ nullable: true })
|
|
59
|
+
params?: string
|
|
60
|
+
|
|
61
|
+
@CreateDateColumn()
|
|
62
|
+
@Field({ nullable: true })
|
|
63
|
+
createdAt?: Date
|
|
64
|
+
|
|
65
|
+
@UpdateDateColumn()
|
|
66
|
+
@Field({ nullable: true })
|
|
67
|
+
updatedAt?: Date
|
|
68
|
+
|
|
69
|
+
@ManyToOne(type => User, { nullable: true })
|
|
70
|
+
@Field(type => User, { nullable: true })
|
|
71
|
+
creator?: User
|
|
72
|
+
|
|
73
|
+
@RelationId((calendar: Calendar) => calendar.creator)
|
|
74
|
+
creatorId?: string
|
|
75
|
+
|
|
76
|
+
@ManyToOne(type => User, { nullable: true })
|
|
77
|
+
@Field(type => User, { nullable: true })
|
|
78
|
+
updater?: User
|
|
79
|
+
|
|
80
|
+
@RelationId((calendar: Calendar) => calendar.updater)
|
|
81
|
+
updaterId?: string
|
|
82
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Calendar } from './calendar'
|
|
2
|
+
import { CalendarQuery } from './calendar-query'
|
|
3
|
+
import { CalendarMutation } from './calendar-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [Calendar]
|
|
6
|
+
export const resolvers = [CalendarQuery, CalendarMutation]
|
|
7
|
+
export const subscribers = []
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Event } from './event'
|
|
5
|
+
import { NewEvent, EventPatch } from './event-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Event)
|
|
8
|
+
export class EventMutation {
|
|
9
|
+
@Directive('@transaction')
|
|
10
|
+
@Mutation(returns => Event, { description: 'To create new Event' })
|
|
11
|
+
async createEvent(@Arg('event') event: NewEvent, @Ctx() context: ResolverContext): Promise<Event> {
|
|
12
|
+
const { user, tx } = context.state
|
|
13
|
+
|
|
14
|
+
return await tx.getRepository(Event).save({
|
|
15
|
+
...event,
|
|
16
|
+
creator: user,
|
|
17
|
+
updater: user
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Directive('@transaction')
|
|
22
|
+
@Mutation(returns => Event, { description: 'To modify Event information' })
|
|
23
|
+
async updateEvent(
|
|
24
|
+
@Arg('id') id: string,
|
|
25
|
+
@Arg('patch') patch: EventPatch,
|
|
26
|
+
@Ctx() context: ResolverContext
|
|
27
|
+
): Promise<Event> {
|
|
28
|
+
const { user, tx } = context.state
|
|
29
|
+
|
|
30
|
+
const repository = tx.getRepository(Event)
|
|
31
|
+
const event = await repository.findOne({
|
|
32
|
+
where: { id }
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return await repository.save({
|
|
36
|
+
...event,
|
|
37
|
+
...patch,
|
|
38
|
+
updater: user
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Directive('@transaction')
|
|
43
|
+
@Mutation(returns => [Event], { description: "To modify multiple Events' information" })
|
|
44
|
+
async updateMultipleEvent(
|
|
45
|
+
@Arg('patches', type => [EventPatch]) patches: EventPatch[],
|
|
46
|
+
@Ctx() context: ResolverContext
|
|
47
|
+
): Promise<Event[]> {
|
|
48
|
+
const { user, tx } = context.state
|
|
49
|
+
|
|
50
|
+
let results = []
|
|
51
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
52
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
53
|
+
const eventRepo = tx.getRepository(Event)
|
|
54
|
+
|
|
55
|
+
if (_createRecords.length > 0) {
|
|
56
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
57
|
+
const newRecord = _createRecords[i]
|
|
58
|
+
|
|
59
|
+
const result = await eventRepo.save({
|
|
60
|
+
...newRecord,
|
|
61
|
+
creator: user,
|
|
62
|
+
updater: user
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
results.push({ ...result, cuFlag: '+' })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (_updateRecords.length > 0) {
|
|
70
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
71
|
+
const updateRecord = _updateRecords[i]
|
|
72
|
+
const event = await eventRepo.findOneBy({ id: updateRecord.id })
|
|
73
|
+
|
|
74
|
+
const result = await eventRepo.save({
|
|
75
|
+
...event,
|
|
76
|
+
...updateRecord,
|
|
77
|
+
updater: user
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return results
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Directive('@transaction')
|
|
88
|
+
@Mutation(returns => Boolean, { description: 'To delete Event' })
|
|
89
|
+
async deleteEvent(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
90
|
+
const { tx } = context.state
|
|
91
|
+
|
|
92
|
+
await tx.getRepository(Event).delete({ id })
|
|
93
|
+
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Directive('@transaction')
|
|
98
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple Events' })
|
|
99
|
+
async deleteEvents(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
|
|
100
|
+
const { tx } = context.state
|
|
101
|
+
|
|
102
|
+
await tx.getRepository(Event).delete({
|
|
103
|
+
id: In(ids)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
return true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Directive('@transaction')
|
|
110
|
+
@Mutation(returns => Boolean, { description: 'To import multiple Events' })
|
|
111
|
+
async importEvents(
|
|
112
|
+
@Arg('events', type => [EventPatch]) events: EventPatch[],
|
|
113
|
+
@Ctx() context: ResolverContext
|
|
114
|
+
): Promise<boolean> {
|
|
115
|
+
const { tx } = context.state
|
|
116
|
+
|
|
117
|
+
await Promise.all(
|
|
118
|
+
events.map(async (event: EventPatch) => {
|
|
119
|
+
const createdEvent: Event = await tx.getRepository(Event).save({ ...event })
|
|
120
|
+
})
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
return true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Event } from './event'
|
|
5
|
+
import { EventList } from './event-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Event)
|
|
8
|
+
export class EventQuery {
|
|
9
|
+
@Query(returns => Event!, { nullable: true, description: 'To fetch a Event' })
|
|
10
|
+
async event(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Event> {
|
|
11
|
+
return await getRepository(Event).findOne({
|
|
12
|
+
where: { id }
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Query(returns => EventList, { description: 'To fetch multiple Events' })
|
|
17
|
+
async events(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<EventList> {
|
|
18
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
19
|
+
params,
|
|
20
|
+
repository: await getRepository(Event),
|
|
21
|
+
searchables: ['name', 'description']
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
25
|
+
|
|
26
|
+
return { items, total }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@FieldResolver(type => User)
|
|
30
|
+
async updater(@Root() event: Event): Promise<User> {
|
|
31
|
+
return await getRepository(User).findOneBy({ id: event.updaterId })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@FieldResolver(type => User)
|
|
35
|
+
async creator(@Root() event: Event): Promise<User> {
|
|
36
|
+
return await getRepository(User).findOneBy({ id: event.creatorId })
|
|
37
|
+
}
|
|
38
|
+
}
|