diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index c4c191d..08c5491 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -1,6 +1,7 @@ import { DataSource } from 'apollo-datasource'; import { getConnection, Connection } from 'typeorm'; import { CargoBike } from '../../model/CargoBike'; +import { GraphQLError } from 'graphql'; /** * extended datasource to feed resolvers with data about cargoBikes */ @@ -53,32 +54,18 @@ export class CargoBikeAPI extends DataSource { .set({ name: bike.name }) .where('id = :id', { id: bike.id }) .execute(); - return { - success: true - }; + return bike; } else { - return { - success: false, - message: 'no bike with given id ' + cargoBike.id + ' found.' - }; + return new GraphQLError('ID not in database'); } } else { // create new bike await this.connection.manager.createQueryBuilder() .insert() .into(CargoBike) - .values([{ - modelName: cargoBike.modelName, - numberOfWheels: cargoBike.numberOfWheels, - forCargo: cargoBike.forCargo, - forChildren: cargoBike.forChildren - } - ]) + .values([cargoBike]) .execute(); - return { - success: true, - message: 'new entry' - }; + return cargoBike; } } } diff --git a/src/model/BikeFeatures.ts b/src/model/BikeFeatures.ts index ef68f04..7231d9a 100644 --- a/src/model/BikeFeatures.ts +++ b/src/model/BikeFeatures.ts @@ -1,27 +1,6 @@ import { Column } from 'typeorm'; -export abstract class Bike { - @Column({ - nullable: true - }) - description: string; - - @Column() - modelName: string; - - @Column() - numberOfWheels: number; - - @Column() - forCargo: boolean; - - @Column() - forChildren: boolean; - - @Column() - numberOfChildren: number; - - // technical Information +export class TechnicalEquipment { @Column() bicycleShift: string; @@ -31,49 +10,100 @@ export abstract class Bike { @Column() hasLightSystem: boolean; - @Column() + @Column({ + nullable: true + }) specialFeatures: string; +} - // dimensions and load +export class DimensionsAndLoad { @Column() hasCoverBox: boolean; @Column() lockable:boolean; - @Column() + @Column({ + type: 'decimal' + }) boxLength: number; - @Column() + @Column({ + type: 'decimal' + }) boxWidth: number; - @Column() + @Column({ + type: 'decimal' + }) boxHeight: number; - @Column() + @Column({ + type: 'decimal' + }) maxWeightBox: number; - @Column() + @Column({ + type: 'decimal' + }) maxWeightLuggageRack: number; - @Column() + @Column({ + type: 'decimal' + }) maxWeightTotal: number; - @Column() + @Column({ + type: 'decimal' + }) bikeLength: number; @Column({ - nullable: true + nullable: true, + type: 'decimal' + }) bikeWidth: number; @Column({ - nullable: true + nullable: true, + type: 'decimal' + }) bikeHeight: number; @Column({ - nullable: true + nullable: true, + type: 'decimal' + }) bikeWeight: number; } + +export abstract class Bike { + @Column({ + nullable: true + }) + description: string; + + @Column() + modelName: string; + + @Column() + numberOfWheels: number; + + @Column() + forCargo: boolean; + + @Column() + forChildren: boolean; + + @Column() + numberOfChildren: number; + + @Column(type => TechnicalEquipment) + technicalEquipment: TechnicalEquipment; + + @Column(type => DimensionsAndLoad) + dimensionsAndLoad: DimensionsAndLoad; +} diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 884c7d2..8dfcfd8 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -30,6 +30,31 @@ export enum StickerBikeNameState { UNKNOWN } +export class Security { + @Column() + frameNumber: string; + + @Column({ + nullable: true + }) + keyNoFrameLock: string; + + @Column({ + nullable: true + }) + keyNoAXAChain: string; + + @Column({ + nullable: true + }) + policeCodeing: string; + + @Column({ + nullable: true + }) + adfsCoding: string; +} + @Entity() export class CargoBike extends Bike { @PrimaryGeneratedColumn() @@ -61,36 +86,19 @@ export class CargoBike extends Bike { chainSwaps: ChainSwap[] // Security information - @Column() - frameNumber: string; - - @Column({ - nullable: true - }) - keyNoFrameLock: string; - - @Column({ - nullable: true - }) - keyNoAXAChain: string; + @Column(type => Security) + security: Security; @Column({ + type: 'enum', + enum: StickerBikeNameState, nullable: true }) - policeCodeing: string; + stickerBikeNameState: StickerBikeNameState; @Column({ nullable: true }) - adfsCoding: string; - - @Column({ - type: 'enum', - enum: StickerBikeNameState - }) - stickerBikeNameState: StickerBikeNameState; - - @Column() note: string; @ManyToOne(type => Provider, { diff --git a/src/model/InsuranceData.ts b/src/model/InsuranceData.ts index b5c80c2..43dff06 100644 --- a/src/model/InsuranceData.ts +++ b/src/model/InsuranceData.ts @@ -5,21 +5,21 @@ export class InsuranceData { name: string; @Column() - benefector: string; + benefactor: string; @Column() noPnP: string; @Column() - maintananceResponisble: string; + maintananceResponsible: string; @Column() - maintanceBenfector: string; + maintananceBenefactor: string; @Column({ nullable: true }) - maintanceAgreement: string; + maintananceAgreement: string; @Column({ nullable: true diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index 64f84ca..1b37197 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -14,12 +14,12 @@ type CargoBike { 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 calles Security? """ - security: Security + security: Security! """ Does not refere to an extra table in the database. """ @@ -56,7 +56,26 @@ type InsuranceData { noPnP: String! "eg. Anbieter, flotte, eigenleistung" maintananceResponsible: String! - maintanceBenefector: String! + maintananceBenefactor: String! + maintananceAgreement: String + hasFixedRate: Boolean! + fixedRate: Float + "Projektzuschuss" + projectAllowance: Float + notes: String +} + +input InsuranceDataInput { + """ + Eventuelly, this field will become an enum or a seperate data table and user can choose from a pool of insurance companies. + """ + name: String! + benefactor: String! + billing: String! + noPnP: String! + "eg. Anbieter, flotte, eigenleistung" + maintananceResponsible: String! + maintananceBenefactor: String! maintananceAgreement: String hasFixedRate: Boolean! fixedRate: Float @@ -121,7 +140,12 @@ type Participant { } type Taxes { - costCenter: String + costCenter: String! + organizationArea: OrganizationArea +} + +input TaxesInput { + costCenter: String! organizationArea: OrganizationArea } @@ -184,7 +208,7 @@ enum BikeEventType { type DimensionsAndLoad { hasCoverBox: Boolean! lockable: Boolean! - boxLenght: Float! + boxLength: Float! boxWidth: Float! boxHeight: Float! maxWeightBox: Float! @@ -199,7 +223,7 @@ type DimensionsAndLoad { input DimensionsAndLoadInput { hasCoverBox: Boolean! lockable: Boolean! - boxLenght: Float! + boxLength: Float! boxWidth: Float! boxHeight: Float! maxWeightBox: Float! @@ -217,16 +241,16 @@ This should be 1-1 Relation with the CargoBike. So no id needed for mutation. One Mutation for the CargoBike will be enough. """ type TechnicalEquipment { - bicycleShift: String - isEBike: Boolean - hasLightingSystem: Boolean + bicycleShift: String! + isEBike: Boolean! + hasLightSystem: Boolean! specialFeatures: String } input TechnicalEquipmentInput { - bicycleShift: String - isEBike: Boolean - hasLightingSystem: Boolean + bicycleShift: String! + isEBike: Boolean! + hasLightSystem: Boolean! specialFeatures: String } @@ -351,12 +375,6 @@ type Query { contactInformation: [ContactInformation]! } -type UpdateBikeResponse { - success: Boolean! - message: String - cargoBike: CargoBike -} - input CargoBikeInput { "if null, then new bike will be created, else old bike will be updated." id: ID @@ -372,22 +390,25 @@ input CargoBikeInput { Safety is a custom type, that stores information about security features. TODO: Should this be calles Security? """ - security: SecurityInput + security: SecurityInput! """ Does not refere to an extra table in the database. """ - technicalEquipment: TechnicalEquipmentInput + technicalEquipment: TechnicalEquipmentInput! """ Does not refere to an extra table in the database. """ - dimensionsAndLoad: DimensionsAndLoadInput + dimensionsAndLoad: DimensionsAndLoadInput! "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" otherEquipment: [String] + "Sticker State" stickerBikeNameState: StickerBikeNameState note: String provider: String - insuranceData: String + insuranceData: InsuranceDataInput! + taxes: TaxesInput + } input SecurityInput { @@ -400,9 +421,9 @@ input SecurityInput { type Mutation { "for testing" - addBike(id: ID!, name: String): UpdateBikeResponse! + addBike(id: ID!, name: String): CargoBike! "if id: null, then new bike will be created, else old bike will be updated" - cargoBike(cargoBike: CargoBikeInput!): UpdateBikeResponse! + cargoBike(cargoBike: CargoBikeInput!): CargoBike! } `;