@things-factory/calendar 8.0.0-beta.9 → 8.0.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.
- package/client/bootstrap.ts +1 -0
- package/client/index.ts +0 -0
- package/client/pages/attendee/attendee-importer.ts +87 -0
- package/client/pages/attendee/attendee-list-page.ts +324 -0
- package/client/pages/calendar/calendar-importer.ts +87 -0
- package/client/pages/calendar/calendar-list-page.ts +325 -0
- package/client/pages/calendar/calendar-page.ts +128 -0
- package/client/pages/event/event-importer.ts +87 -0
- package/client/pages/event/event-list-page.ts +324 -0
- package/client/route.ts +19 -0
- package/client/tsconfig.json +13 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- 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 +37 -0
- package/server/service/attendee/index.ts +7 -0
- package/server/service/calendar/calendar-mutation.ts +133 -0
- package/server/service/calendar/calendar-query.ts +48 -0
- package/server/service/calendar/calendar-type.ts +55 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/calendar",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
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
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@operato/event-view": "^8.0.0
|
|
31
|
-
"@operato/graphql": "^8.0.0
|
|
32
|
-
"@operato/shell": "^8.0.0
|
|
33
|
-
"@things-factory/auth-base": "^8.0.
|
|
34
|
-
"@things-factory/shell": "^8.0.
|
|
30
|
+
"@operato/event-view": "^8.0.0",
|
|
31
|
+
"@operato/graphql": "^8.0.0",
|
|
32
|
+
"@operato/shell": "^8.0.0",
|
|
33
|
+
"@things-factory/auth-base": "^8.0.2",
|
|
34
|
+
"@things-factory/shell": "^8.0.2"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "39d60f56e142561233ddf6d47b539c637971357c"
|
|
37
37
|
}
|
|
File without changes
|
package/server/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const debug = require('debug')('things-factory:calendar:routes')
|
|
2
|
+
|
|
3
|
+
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
4
|
+
/*
|
|
5
|
+
* can add global public routes to application (auth not required, tenancy not required)
|
|
6
|
+
*
|
|
7
|
+
* ex) routes.get('/path', async(context, next) => {})
|
|
8
|
+
* ex) routes.post('/path', async(context, next) => {})
|
|
9
|
+
*/
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
|
|
13
|
+
/*
|
|
14
|
+
* can add global private routes to application (auth required, tenancy not required)
|
|
15
|
+
*/
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
|
|
19
|
+
/*
|
|
20
|
+
* can add domain public routes to application (auth not required, tenancy required)
|
|
21
|
+
*/
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
25
|
+
/*
|
|
26
|
+
* can add domain private routes to application (auth required, tenancy required)
|
|
27
|
+
*/
|
|
28
|
+
})
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Attendee } from './attendee'
|
|
5
|
+
import { NewAttendee, AttendeePatch } from './attendee-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Attendee)
|
|
8
|
+
export class AttendeeMutation {
|
|
9
|
+
@Directive('@transaction')
|
|
10
|
+
@Mutation(returns => Attendee, { description: 'To create new Attendee' })
|
|
11
|
+
async createAttendee(@Arg('attendee') attendee: NewAttendee, @Ctx() context: ResolverContext): Promise<Attendee> {
|
|
12
|
+
const { tx } = context.state
|
|
13
|
+
|
|
14
|
+
return await tx.getRepository(Attendee).save({
|
|
15
|
+
...attendee
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Directive('@transaction')
|
|
20
|
+
@Mutation(returns => Attendee, { description: 'To modify Attendee information' })
|
|
21
|
+
async updateAttendee(
|
|
22
|
+
@Arg('id') id: string,
|
|
23
|
+
@Arg('patch') patch: AttendeePatch,
|
|
24
|
+
@Ctx() context: ResolverContext
|
|
25
|
+
): Promise<Attendee> {
|
|
26
|
+
const { tx } = context.state
|
|
27
|
+
|
|
28
|
+
const repository = tx.getRepository(Attendee)
|
|
29
|
+
const attendee = await repository.findOne({
|
|
30
|
+
where: { id }
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return await repository.save({
|
|
34
|
+
...attendee,
|
|
35
|
+
...patch
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Directive('@transaction')
|
|
40
|
+
@Mutation(returns => [Attendee], { description: "To modify multiple Attendees' information" })
|
|
41
|
+
async updateMultipleAttendee(
|
|
42
|
+
@Arg('patches', type => [AttendeePatch]) patches: AttendeePatch[],
|
|
43
|
+
@Ctx() context: ResolverContext
|
|
44
|
+
): Promise<Attendee[]> {
|
|
45
|
+
const { user, tx } = context.state
|
|
46
|
+
|
|
47
|
+
let results = []
|
|
48
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
49
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
50
|
+
const attendeeRepo = tx.getRepository(Attendee)
|
|
51
|
+
|
|
52
|
+
if (_createRecords.length > 0) {
|
|
53
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
54
|
+
const newRecord = _createRecords[i]
|
|
55
|
+
|
|
56
|
+
const result = await attendeeRepo.save({
|
|
57
|
+
...newRecord
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
results.push({ ...result, cuFlag: '+' })
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (_updateRecords.length > 0) {
|
|
65
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
66
|
+
const updateRecord = _updateRecords[i]
|
|
67
|
+
const attendee = await attendeeRepo.findOneBy({ id: updateRecord.id })
|
|
68
|
+
|
|
69
|
+
const result = await attendeeRepo.save({
|
|
70
|
+
...attendee,
|
|
71
|
+
...updateRecord
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return results
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Directive('@transaction')
|
|
82
|
+
@Mutation(returns => Boolean, { description: 'To delete Attendee' })
|
|
83
|
+
async deleteAttendee(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
84
|
+
const { tx } = context.state
|
|
85
|
+
|
|
86
|
+
await tx.getRepository(Attendee).delete({ id })
|
|
87
|
+
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Directive('@transaction')
|
|
92
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple Attendees' })
|
|
93
|
+
async deleteAttendees(
|
|
94
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
95
|
+
@Ctx() context: ResolverContext
|
|
96
|
+
): Promise<boolean> {
|
|
97
|
+
const { tx } = context.state
|
|
98
|
+
|
|
99
|
+
await tx.getRepository(Attendee).delete({
|
|
100
|
+
id: In(ids)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Directive('@transaction')
|
|
107
|
+
@Mutation(returns => Boolean, { description: 'To import multiple Attendees' })
|
|
108
|
+
async importAttendees(
|
|
109
|
+
@Arg('attendees', type => [AttendeePatch]) attendees: AttendeePatch[],
|
|
110
|
+
@Ctx() context: ResolverContext
|
|
111
|
+
): Promise<boolean> {
|
|
112
|
+
const { tx } = context.state
|
|
113
|
+
|
|
114
|
+
await Promise.all(
|
|
115
|
+
attendees.map(async (attendee: AttendeePatch) => {
|
|
116
|
+
const createdAttendee: Attendee = await tx.getRepository(Attendee).save({ ...attendee })
|
|
117
|
+
})
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
return true
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -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(type => ListParam) 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,37 @@
|
|
|
1
|
+
import { Entity, Index, Column, ManyToMany, JoinTable, PrimaryGeneratedColumn } from 'typeorm'
|
|
2
|
+
import { ObjectType, Field, Int, ID, registerEnumType } from 'type-graphql'
|
|
3
|
+
import { GraphQLEmailAddress } from 'graphql-scalars'
|
|
4
|
+
|
|
5
|
+
import { Event } from '../event/event'
|
|
6
|
+
|
|
7
|
+
export enum AttendeeStatus {
|
|
8
|
+
STATUS_A = 'STATUS_A',
|
|
9
|
+
STATUS_B = 'STATUS_B'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
registerEnumType(AttendeeStatus, {
|
|
13
|
+
name: 'AttendeeStatus',
|
|
14
|
+
description: 'state enumeration of a attendee'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
@Entity()
|
|
18
|
+
@Index('ix_attendee_0', (attendee: Attendee) => [attendee.email], { unique: false })
|
|
19
|
+
@ObjectType({ description: 'Entity for Attendee' })
|
|
20
|
+
export class Attendee {
|
|
21
|
+
@PrimaryGeneratedColumn('uuid')
|
|
22
|
+
@Field(type => ID)
|
|
23
|
+
readonly id: string
|
|
24
|
+
|
|
25
|
+
@Column()
|
|
26
|
+
@Field({ nullable: true })
|
|
27
|
+
name?: string
|
|
28
|
+
|
|
29
|
+
@Column()
|
|
30
|
+
@Field(type => GraphQLEmailAddress, { nullable: true })
|
|
31
|
+
email: string
|
|
32
|
+
|
|
33
|
+
@ManyToMany(() => Event)
|
|
34
|
+
@JoinTable()
|
|
35
|
+
@Field({ nullable: true })
|
|
36
|
+
events: Event[]
|
|
37
|
+
}
|
|
@@ -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,133 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Calendar } from './calendar'
|
|
5
|
+
import { NewCalendar, CalendarPatch } from './calendar-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Calendar)
|
|
8
|
+
export class CalendarMutation {
|
|
9
|
+
@Directive('@transaction')
|
|
10
|
+
@Mutation(returns => Calendar, { description: 'To create new Calendar' })
|
|
11
|
+
async createCalendar(@Arg('calendar') calendar: NewCalendar, @Ctx() context: ResolverContext): Promise<Calendar> {
|
|
12
|
+
const { domain, user, tx } = context.state
|
|
13
|
+
|
|
14
|
+
const result = await tx.getRepository(Calendar).save({
|
|
15
|
+
...calendar,
|
|
16
|
+
domain,
|
|
17
|
+
creator: user,
|
|
18
|
+
updater: user
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return result
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Directive('@transaction')
|
|
25
|
+
@Mutation(returns => Calendar, { description: 'To modify Calendar information' })
|
|
26
|
+
async updateCalendar(
|
|
27
|
+
@Arg('id') id: string,
|
|
28
|
+
@Arg('patch') patch: CalendarPatch,
|
|
29
|
+
@Ctx() context: ResolverContext
|
|
30
|
+
): Promise<Calendar> {
|
|
31
|
+
const { domain, user, tx } = context.state
|
|
32
|
+
|
|
33
|
+
const repository = tx.getRepository(Calendar)
|
|
34
|
+
const calendar = await repository.findOne({
|
|
35
|
+
where: { domain: { id: domain.id }, id }
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return await repository.save({
|
|
39
|
+
...calendar,
|
|
40
|
+
...patch,
|
|
41
|
+
updater: user
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Directive('@transaction')
|
|
46
|
+
@Mutation(returns => [Calendar], { description: "To modify multiple Calendars' information" })
|
|
47
|
+
async updateMultipleCalendar(
|
|
48
|
+
@Arg('patches', type => [CalendarPatch]) patches: CalendarPatch[],
|
|
49
|
+
@Ctx() context: ResolverContext
|
|
50
|
+
): Promise<Calendar[]> {
|
|
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 calendarRepo = tx.getRepository(Calendar)
|
|
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 calendarRepo.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 updateRecord = _updateRecords[i]
|
|
76
|
+
const calendar = await calendarRepo.findOneBy({ id: updateRecord.id })
|
|
77
|
+
|
|
78
|
+
const result = await calendarRepo.save({
|
|
79
|
+
...calendar,
|
|
80
|
+
...updateRecord,
|
|
81
|
+
updater: user
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return results
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Directive('@transaction')
|
|
92
|
+
@Mutation(returns => Boolean, { description: 'To delete Calendar' })
|
|
93
|
+
async deleteCalendar(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
94
|
+
const { domain, tx } = context.state
|
|
95
|
+
|
|
96
|
+
await tx.getRepository(Calendar).delete({ domain: { id: domain.id }, id })
|
|
97
|
+
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Directive('@transaction')
|
|
102
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple Calendars' })
|
|
103
|
+
async deleteCalendars(
|
|
104
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
105
|
+
@Ctx() context: ResolverContext
|
|
106
|
+
): Promise<boolean> {
|
|
107
|
+
const { domain, tx } = context.state
|
|
108
|
+
|
|
109
|
+
await tx.getRepository(Calendar).delete({
|
|
110
|
+
domain: { id: domain.id },
|
|
111
|
+
id: In(ids)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Directive('@transaction')
|
|
118
|
+
@Mutation(returns => Boolean, { description: 'To import multiple Calendars' })
|
|
119
|
+
async importCalendars(
|
|
120
|
+
@Arg('calendars', type => [CalendarPatch]) calendars: CalendarPatch[],
|
|
121
|
+
@Ctx() context: ResolverContext
|
|
122
|
+
): Promise<boolean> {
|
|
123
|
+
const { domain, tx } = context.state
|
|
124
|
+
|
|
125
|
+
await Promise.all(
|
|
126
|
+
calendars.map(async (calendar: CalendarPatch) => {
|
|
127
|
+
const createdCalendar: Calendar = await tx.getRepository(Calendar).save({ domain, ...calendar })
|
|
128
|
+
})
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
return true
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Calendar } from './calendar'
|
|
5
|
+
import { CalendarList } from './calendar-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(Calendar)
|
|
8
|
+
export class CalendarQuery {
|
|
9
|
+
@Query(returns => Calendar!, { nullable: true, description: 'To fetch a Calendar' })
|
|
10
|
+
async calendar(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Calendar> {
|
|
11
|
+
const { domain } = context.state
|
|
12
|
+
|
|
13
|
+
return await getRepository(Calendar).findOne({
|
|
14
|
+
where: { domain: { id: domain.id }, id }
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Query(returns => CalendarList, { description: 'To fetch multiple Calendars' })
|
|
19
|
+
async calendars(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<CalendarList> {
|
|
20
|
+
const { domain } = context.state
|
|
21
|
+
|
|
22
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
23
|
+
domain,
|
|
24
|
+
params,
|
|
25
|
+
repository: await getRepository(Calendar),
|
|
26
|
+
searchables: ['name', 'description']
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
30
|
+
|
|
31
|
+
return { items, total }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@FieldResolver(type => Domain)
|
|
35
|
+
async domain(@Root() calendar: Calendar): Promise<Domain> {
|
|
36
|
+
return await getRepository(Domain).findOneBy({ id: calendar.domainId })
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@FieldResolver(type => User)
|
|
40
|
+
async updater(@Root() calendar: Calendar): Promise<User> {
|
|
41
|
+
return await getRepository(User).findOneBy({ id: calendar.updaterId })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@FieldResolver(type => User)
|
|
45
|
+
async creator(@Root() calendar: Calendar): Promise<User> {
|
|
46
|
+
return await getRepository(User).findOneBy({ id: calendar.creatorId })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
|
|
27
|
+
@InputType()
|
|
28
|
+
export class CalendarPatch {
|
|
29
|
+
@Field(type => ID, { nullable: true })
|
|
30
|
+
id?: string
|
|
31
|
+
|
|
32
|
+
@Field({ nullable: true })
|
|
33
|
+
name?: string
|
|
34
|
+
|
|
35
|
+
@Field({ nullable: true })
|
|
36
|
+
description?: string
|
|
37
|
+
|
|
38
|
+
@Field(type => CalendarStatus, { nullable: true })
|
|
39
|
+
state?: CalendarStatus
|
|
40
|
+
|
|
41
|
+
@Field({ nullable: true })
|
|
42
|
+
active?: boolean
|
|
43
|
+
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
cuFlag?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ObjectType()
|
|
49
|
+
export class CalendarList {
|
|
50
|
+
@Field(type => [Calendar])
|
|
51
|
+
items: Calendar[]
|
|
52
|
+
|
|
53
|
+
@Field(type => Int)
|
|
54
|
+
total: number
|
|
55
|
+
}
|
|
@@ -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(type => Domain)
|
|
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 = []
|