diff --git a/src/datasources/db/participantAPI.ts b/src/datasources/db/participantAPI.ts index d480f9e..311ba26 100644 --- a/src/datasources/db/participantAPI.ts +++ b/src/datasources/db/participantAPI.ts @@ -179,7 +179,7 @@ export class ParticipantAPI extends DataSource { .values([participant]) .returning('*') .execute(); - await entityManager.getRepository(Participant) + participant.workshopIds && await entityManager.getRepository(Participant) .createQueryBuilder('w') .relation(Participant, 'workshopIds') .of(participant.id) @@ -211,8 +211,8 @@ export class ParticipantAPI extends DataSource { .update() .set({ ...participant }) .where('id = :id', { id: participant.id }) - .execute().then(value => { if (value.affected !== 1) { throw new GraphQLError('ID not found'); } }); - await entityManager.getRepository(Participant) + .execute().then(value => { if (value.affected !== 1) { throw new UserInputError('ID not found'); } }); + workshops && await entityManager.getRepository(Participant) .createQueryBuilder('w') .relation(Participant, 'workshopIds') .of(participant.id) diff --git a/src/resolvers/participantResolvers.ts b/src/resolvers/participantResolvers.ts index ed058e1..89deb3e 100644 --- a/src/resolvers/participantResolvers.ts +++ b/src/resolvers/participantResolvers.ts @@ -113,13 +113,6 @@ export default { return new GraphQLError('Insufficient Permissions'); } }, - from (parent: any) { - return (parent.dateRange as string).split(',')[0].replace('[', ''); - }, - to (parent: any) { - const str = (parent.dateRange as string).split(',')[1].replace(')', ''); - return (str.length > 0) ? str : null; - }, isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }), isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req }) }, diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index afc7d7f..e72012c 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -550,8 +550,7 @@ export default gql` type Engagement { id: ID! engagementType: EngagementType! - from: Date! - to: Date + dateRange: DateRange! participant: Participant! cargoBike: CargoBike! isLocked: Boolean! @@ -563,18 +562,14 @@ export default gql` input EngagementCreateInput { engagementTypeId: ID! - "will use CURRENT_DATE if not set" - from: Date - "will use infinit if not set" - to: Date + dateRange: DateRangeInput participantId: ID! cargoBikeId: ID! } input EngagementUpdateInput { id: ID! engagementTypeId: ID - from: Date - to: Date + dateRange: DateRangeInput participantId: ID cargoBikeId: ID keepLock: Boolean