From 4e33ec2095bfd7db6dfff5aa25d04bc0be3b61d6 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Mon, 30 Nov 2020 14:23:38 +0100 Subject: [PATCH 1/2] src/schema/*: remove mandatory for fields --- src/model/CargoBike.ts | 31 ++++++++++++++++++++++--------- src/schema/type-defs.ts | 20 ++++++++++---------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 965651a..ccf214c 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -65,7 +65,9 @@ export interface Lockable { } export class Security { - @Column() + @Column({ + nullable: true + }) frameNumber: string; @Column({ @@ -190,9 +192,6 @@ export class CargoBike implements Lockable { @PrimaryGeneratedColumn() id: number; - @DeleteDateColumn() - deleteDate: Date; - @Column({ type: 'enum', enum: Group @@ -268,19 +267,32 @@ export class CargoBike implements Lockable { }) description: string; - @Column() + @Column({ + nullable: true + }) modelName: string; - @Column() + @Column({ + nullable: true + }) numberOfWheels: number; - @Column() + @Column({ + type: 'boolean', + nullable: true + }) forCargo: boolean; - @Column() + @Column({ + type: 'boolean', + nullable: true + }) forChildren: boolean; - @Column() + @Column({ + type: 'int', + nullable: true + }) numberOfChildren: number; @Column(type => TechnicalEquipment) @@ -290,6 +302,7 @@ export class CargoBike implements Lockable { dimensionsAndLoad: DimensionsAndLoad; @Column({ + type: 'int', nullable: true }) lockedBy: number; diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index af19618..afc7d7f 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -45,12 +45,12 @@ export default gql` numberOfWheels: Int forCargo: Boolean forChildren: Boolean - numberOfChildren: Int! + numberOfChildren: Int """ Safety is a custom type, that stores information about security features. TODO: Should this be called Security? """ - security: Security! + security: Security """ Does not refer to an extra table in the database. """ @@ -102,15 +102,15 @@ export default gql` group: Group! name: String! state: BikeState - modelName: String! - numberOfWheels: Int! - forCargo: Boolean! - forChildren: Boolean! - numberOfChildren: Int! + modelName: String + numberOfWheels: Int + forCargo: Boolean + forChildren: Boolean + numberOfChildren: Int """ Safety is a custom type, that stores information about security features. """ - security: SecurityCreateInput! + security: SecurityCreateInput """ Does not refer to an extra table in the database. """ @@ -360,7 +360,7 @@ export default gql` So no id needed for mutation. One Mutation for the CargoBike will be enough. """ type Security { - frameNumber: String! + frameNumber: String keyNumberFrameLock: String keyNumberAXAChain: String policeCoding: String @@ -368,7 +368,7 @@ export default gql` } input SecurityCreateInput { - frameNumber: String! + frameNumber: String keyNumberFrameLock: String keyNumberAXAChain: String policeCoding: String From 5e6e796fe8005c53527cb0c9ba15e295cfbfb62c Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Mon, 30 Nov 2020 14:44:29 +0100 Subject: [PATCH 2/2] src/schema/*: use dateRange for engagement --- src/datasources/db/participantAPI.ts | 6 +++--- src/resolvers/participantResolvers.ts | 7 ------- src/schema/type-defs.ts | 11 +++-------- 3 files changed, 6 insertions(+), 18 deletions(-) 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