diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index 08c5491..5e07c96 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -38,6 +38,11 @@ export class CargoBikeAPI extends DataSource { }; } + /** + * Creates or Updates CargoBike + * Will create bike, if no id given, else it will update bike with given id. + * @param param0 cargoBike to be updated or created + */ async updateCargoBike ({ cargoBike }:{ cargoBike: any }) { if (cargoBike.id) { // update bike with given id @@ -51,21 +56,30 @@ export class CargoBikeAPI extends DataSource { await this.connection .createQueryBuilder() .update(CargoBike) - .set({ name: bike.name }) + .set({ ...cargoBike }) .where('id = :id', { id: bike.id }) .execute(); - return bike; + return await this.connection + .createQueryBuilder() + .select('cargoBike') + .from(CargoBike, 'cargoBike') + .where('cargoBike.id = :id', { id: bike.id }) + .getOne(); } else { return new GraphQLError('ID not in database'); } } else { // create new bike - await this.connection.manager.createQueryBuilder() + const inserts = await this.connection.manager + .createQueryBuilder() .insert() .into(CargoBike) .values([cargoBike]) + .returning('*') .execute(); - return cargoBike; + const newbike = inserts.generatedMaps[0]; + newbike.id = inserts.identifiers[0].id; + return newbike; } } } diff --git a/src/model/InsuranceData.ts b/src/model/InsuranceData.ts index 43dff06..16f575f 100644 --- a/src/model/InsuranceData.ts +++ b/src/model/InsuranceData.ts @@ -7,6 +7,9 @@ export class InsuranceData { @Column() benefactor: string; + @Column() + billing: string; + @Column() noPnP: string; diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index 1b37197..61bc88a 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -27,7 +27,7 @@ type CargoBike { """ Does not refere to an extra table in the database. """ - dimensionsAndLoad: DimensionsAndLoad + dimensionsAndLoad: DimensionsAndLoad! events: [BikeEvent] equipment: [Equipment] "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" @@ -327,23 +327,18 @@ type LendingStation { loanPeriods: [LoanPeriod]! } -"(dt. Ausleihzeiten)" +""" +(dt. Ausleihzeiten) +""" type LoanTimes { - notes: String - mof: String - mot: String - tuf: String - tut: String - wef: String - wet: String - thf: String - tht: String - frf: String - frt: String - saf: String - sat: String - suf: String - sut: String + generalRemark: String + "notes for each day of the week, starting on Monday" + notes: [String] + """ + Loan times from and until for each day of the week. + Starting with Monday from, Monday to, Tuesday from, ..., Sunday to + """ + times: [String] } "(dt. Zeitscheibe)"