diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index 0a1c804..8f1616f 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -237,12 +237,13 @@ export class CargoBikeAPI extends DataSource { } async createBikeEvent ({ bikeEvent }: { bikeEvent: any }) { - return (await this.connection.getRepository(BikeEvent) + const inserts = await this.connection.getRepository(BikeEvent) .createQueryBuilder('be') .insert() .values([bikeEvent]) .returning('*') - .execute()).generatedMaps[0]; + .execute(); + return await this.bikeEventById(inserts.identifiers[0].id); } async updateBikeEvent (bikeEvent: any, userId: number) { @@ -310,7 +311,7 @@ export class CargoBikeAPI extends DataSource { return (await this.connection.getRepository(BikeEventType) .createQueryBuilder('bet') .insert() - .values([{ name: bikeEventType }]) + .values([bikeEventType]) .returning('*') .execute())?.generatedMaps[0]; } diff --git a/src/datasources/db/workshopAPI.ts b/src/datasources/db/workshopAPI.ts index 9c0e510..b171010 100644 --- a/src/datasources/db/workshopAPI.ts +++ b/src/datasources/db/workshopAPI.ts @@ -134,6 +134,14 @@ export class WorkshopAPI extends DataSource { .getOne(); } + async workshopTypeByWorkshopId (id: number) { + return await this.connection.getRepository(Workshop) + .createQueryBuilder('w') + .relation(Workshop, 'workshopTypeId') + .of(id) + .loadOne(); + } + async workshopTypes (offset?: number, limit?: number) { return DBUtils.getAllEntity(this.connection, WorkshopType, 'wt', offset, limit); } diff --git a/src/resolvers/cargoBikeResolver.ts b/src/resolvers/cargoBikeResolver.ts index da64451..bbbc1e5 100644 --- a/src/resolvers/cargoBikeResolver.ts +++ b/src/resolvers/cargoBikeResolver.ts @@ -215,11 +215,14 @@ export default { }, related (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) { if (req.permissions.includes(Permission.ReadParticipant)) { - return dataSources.cargoBikeAPI.relatedByBikeEventId(parent.id); + return dataSources.cargoBikeAPI.relatedByBikeEventId(parent.workshopTypeId); } else { throw new PermissionError(); } }, + documents: (parent: any) => { + return (parent.documents) ? parent.documents : []; + }, isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }), isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req }) }, @@ -368,9 +371,9 @@ export default { throw new PermissionError(); } }, - createBikeEventType: (_: any, { name }: { name: any }, { dataSources, req }: { dataSources: any, req: any }) => { + createBikeEventType: (_: any, { bikeEventType }: { bikeEventType: any }, { dataSources, req }: { dataSources: any, req: any }) => { if (req.permissions.includes(Permission.WriteEventType)) { - return dataSources.cargoBikeAPI.createBikeEventType(name); + return dataSources.cargoBikeAPI.createBikeEventType(bikeEventType); } else { throw new PermissionError(); } diff --git a/src/resolvers/workshopResolvers.ts b/src/resolvers/workshopResolvers.ts index 82fbd33..c148251 100644 --- a/src/resolvers/workshopResolvers.ts +++ b/src/resolvers/workshopResolvers.ts @@ -75,6 +75,13 @@ export default { throw new PermissionError(); } }, + workshopType (parent: any, _: any, { dataSources, req }: { dataSources: any; req: any }) { + if (req.permissions.includes(Permission.ReadWorkshop)) { + return dataSources.workshopAPI.workshopTypeByWorkshopId(parent.id); + } else { + throw new PermissionError(); + } + }, 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 02f6f0d..46a4678 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -723,6 +723,10 @@ export default gql` keepLock: Boolean } + input BikeEventTypeCreateInput { + name: String! + } + "(dt. Anbieter) bezieht sich auf die Beziehung einer Person oder Organisation zum Lastenrad" type Provider { id: ID! @@ -1126,7 +1130,7 @@ export default gql` """ BIKEEVENT """ - createBikeEventType(name: String!): BikeEventType! + createBikeEventType(bikeEventType: BikeEventTypeCreateInput!): BikeEventType! lockBikeEventType(id: ID!): BikeEventType! unlockBikeEventType(id:ID!): BikeEventType! updateBikeEventType(bikeEventType: BikeEventTypeUpdateInput!): BikeEventType!