diff --git a/src/datasources/db/cargobikeAPI.ts b/src/datasources/db/cargobikeAPI.ts index f23571c..bd47771 100644 --- a/src/datasources/db/cargobikeAPI.ts +++ b/src/datasources/db/cargobikeAPI.ts @@ -14,22 +14,22 @@ export class CargoBikeAPI extends DataSource { /** * Finds cargo bike by id */ - async findCargoBikeById ({ id, token }:{id: any, token:string}) { + async findCargoBikeById ({ id }:{id: any}) { return { id, - name: token + name: 'token' }; } - async updateBike ({ id, token, name }:{id:any, token: string, name: string }) { + async updateBike ({ id, name }:{id:any, name: string }) { const bike = new CargoBike(); bike.id = id; - bike.description = token; + bike.description = 'text'; bike.name = name; await this.connection.manager.save(bike); return { success: true, - message: token, + message: 'bla', bike: { id, name diff --git a/src/model/BikeEvent.ts b/src/model/BikeEvent.ts new file mode 100644 index 0000000..1a59a01 --- /dev/null +++ b/src/model/BikeEvent.ts @@ -0,0 +1,30 @@ +/* eslint no-unused-vars: "off" */ +import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; + +export enum BikeEventType { + KAUF = 'Kauf', + INBETRIEBNAHME = 'Inbetriebnahme', + AUSFALL = 'Ausfall', + WARTUNG = 'Wartung' +} + +@Entity() +export class BikeEvent { + @PrimaryGeneratedColumn() + id: number; + + @Column() + note: string; + + @Column('simple-array') + documents: string[]; + + @Column({ + type: 'enum', + enum: BikeEventType + }) + type: BikeEventType + + @Column() + otherEquipment: string; +} diff --git a/src/model/BikeFeatures.ts b/src/model/BikeFeatures.ts new file mode 100644 index 0000000..d912fe5 --- /dev/null +++ b/src/model/BikeFeatures.ts @@ -0,0 +1,71 @@ +import { Column } from 'typeorm'; + +export abstract class Bike { + @Column() + description: string; + + @Column() + modelName: string; + + @Column() + numerOfWheels: number; + + @Column() + forCargo: boolean; + + @Column() + forChildren: boolean; + + @Column() + numberOfChildren: number; + + // technical Information + @Column() + bicycleShift: string; + + @Column() + isEBike: boolean; + + @Column() + hasLightSystem: boolean; + + @Column() + specialFeatures: string; + + // dimensions and load + @Column() + hasCoverBox: boolean; + + @Column() + lockable:boolean; + + @Column() + boxLength: number; + + @Column() + boxWidth: number; + + @Column() + boxHeight: number; + + @Column() + maxWeightBox: number; + + @Column() + maxWeightLuggageRack: number; + + @Column() + maxWeightTotal: number; + + @Column() + bikeLength: number; + + @Column() + bikeWidth: number; + + @Column() + bikeHeight: number; + + @Column() + bikeWeight: number; +} diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 46de65c..019c192 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -1,13 +1,67 @@ -import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; +/* eslint no-unused-vars: "off" */ +import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; +import { Bike } from './BikeFeatures'; +import { ChainSwap } from './ChainSwap'; + +export enum Group { + KL, + LI, + SP, + FK, + MH, + SZ, + TS, + TK +} + +export enum StickerBikeNameState { + OK, + IMPROVE, + PRODUCED, + NONEED, + MISSING, + UNKNOWN +} @Entity() -export class CargoBike { +export class CargoBike extends Bike { @PrimaryGeneratedColumn() id: number; + @Column() + group: Group; + @Column() name: string; @Column() - description: string; + serialNo: string; + + @OneToMany(type => ChainSwap, chainSwap => chainSwap.cargoBike) + chainSwaps: ChainSwap[] + + // Security information + @Column() + frameNumber: string; + + @Column() + keyNoFrameLock: string; + + @Column() + keyNoAXAChain: string; + + @Column() + policeCodeing: string; + + @Column() + adfsCoding: string; + + @Column({ + type: 'enum', + enum: StickerBikeNameState + }) + stickerBikeNameState: StickerBikeNameState; + + @Column() + note: string; } diff --git a/src/model/ChainSwap.ts b/src/model/ChainSwap.ts new file mode 100644 index 0000000..dbab23b --- /dev/null +++ b/src/model/ChainSwap.ts @@ -0,0 +1,22 @@ +import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm'; +import { CargoBike } from './CargoBike'; + +@Entity() +export class ChainSwap { + @PrimaryGeneratedColumn() + id: number; + + @Column() + mechanic: string; + + @Column({ + type: 'date' + }) + time: Date; + + @Column() + kexNoOldAXAChain: string; + + @ManyToOne(type => CargoBike, cargoBike => cargoBike.chainSwaps) + cargoBike: CargoBike; +} diff --git a/src/model/ContactInformation.ts b/src/model/ContactInformation.ts new file mode 100644 index 0000000..766beb6 --- /dev/null +++ b/src/model/ContactInformation.ts @@ -0,0 +1,56 @@ +import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from 'typeorm'; +import { Provider } from './Provider'; + +@Entity() +export class ContactInformation { + @PrimaryGeneratedColumn() + id: number; + + @Column() + name: string; + + @Column() + firstName: string; + + @Column({ + type: 'date', + nullable: true + }) + retiredAt: Date; + + @Column({ + nullable: true + }) + phoneExtern: string; + + @Column({ + nullable: true + }) + phone2Extern: string; + + @Column({ + nullable: true + }) + phoneIntern: string; + + @Column({ + nullable: true + }) + phone2Intern: string; + + @Column({ + nullable: true + }) + emailExtern: string; + + @Column({ + nullable: true + }) + emailIntern: string; + + @Column() + note: string; + + @ManyToOne(type => Provider, provider => provider.contactInformation) + provider: Provider; +} diff --git a/src/model/Participant.ts b/src/model/Participant.ts new file mode 100644 index 0000000..869a1ce --- /dev/null +++ b/src/model/Participant.ts @@ -0,0 +1,69 @@ +import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from 'typeorm'; +import { ContactInformation } from './ContactInformation'; + +@Entity() +export class Participant { + @PrimaryGeneratedColumn() + id: number; + + @Column({ + type: 'date' + }) + start: Date; + + @Column({ + type: 'date' + }) + end: Date; + + @OneToOne(type => ContactInformation) + @JoinColumn() + contactInformation: ContactInformation; + + @Column() + usernameflotte: string; + + @Column() + usernameSlack: string; + + @Column() + memberADFC: boolean; + + @Column({ + type: 'simple-array' + }) + locationZIPs: string[]; + + @Column() + roleCoreTeam: boolean; + + @Column() + roleCoordinator: boolean; + + @Column() + roleEmployeADFC: boolean; + + @Column() + roleMentor: boolean; + + @Column() + roleAmbulance: boolean; + + @Column() + roleBringer: boolean; + + @Column({ + type: 'date' + }) + workshopMentor: Date; + + @Column({ + type: 'date' + }) + workshopAmbulance: Date; + + @Column({ + nullable: true + }) + reserve: string; +} diff --git a/src/model/Provider.ts b/src/model/Provider.ts new file mode 100644 index 0000000..5680631 --- /dev/null +++ b/src/model/Provider.ts @@ -0,0 +1,34 @@ +/* eslint no-unused-vars: "off" */ + +import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from 'typeorm'; +import { ContactInformation } from './ContactInformation'; + +@Entity() +export class Provider { + @PrimaryGeneratedColumn() + id: number; + + @Column() + name: string; + + @Column() + formularName: String; + + @Column() + street: string; + + @Column() + number: string; + + @Column() + zip: string; + + @Column() + registerdAt: string; + + @Column() + registerNo: string; + + @OneToMany(type => ContactInformation, contactInformation => contactInformation.provider) + contactInformation: ContactInformation[]; +} diff --git a/src/resolvers/cargobikeResolver.ts b/src/resolvers/cargobikeResolver.ts index 89d05df..1d23d5f 100644 --- a/src/resolvers/cargobikeResolver.ts +++ b/src/resolvers/cargobikeResolver.ts @@ -3,18 +3,18 @@ import { GraphQLError } from 'graphql'; export default { Query: { - CargobikeById: (_: any, { id, token }:{id: any, token: string}, { dataSources, req }:{dataSources: any, req: any }) => { + CargobikeById: (_: any, { id }:{id: any}, { dataSources, req }:{dataSources: any, req: any }) => { if (req.permissions.includes(Permission.ReadBike)) { - return dataSources.cargoBikeAPI.findCargoBikeById({ id, token }); + return dataSources.cargoBikeAPI.findCargoBikeById({ id }); } else { throw new GraphQLError('Insufficient Permissions'); } } }, Mutation: { - addBike: (_: any, { id, token, name }:{id: any, token: string, name:string}, { dataSources, req }:{dataSources: any, req: any }) => { + addBike: (_: any, { id, name }:{id: any, name:string}, { dataSources, req }:{dataSources: any, req: any }) => { if (req.permissions.includes(Permission.WriteBike)) { - return dataSources.cargoBikeAPI.updateBike({ id, token, name }); + return dataSources.cargoBikeAPI.updateBike({ id, name }); } else { throw new GraphQLError('Insufficient Permissions'); } diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index a86a338..4766aa5 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -15,7 +15,7 @@ type CargoBike { forCargo: Boolean forChildren: Boolean numberOfChildren: Int - serialno: String + serialNo: String """ Safety is a custom type, that stores information about security features. TODO: Should this be calles Security? @@ -38,9 +38,11 @@ type CargoBike { stickerBikeNameState: StickerBikeNameState note: String provider: Provider - coordinator: Coordinator + coordinator: Participants insuranceData: InsuranceData loantimes: [LoanTimes] + "null if not locked by other user" + lockedBy: ID } type InsuranceData { @@ -50,12 +52,6 @@ type InsuranceData { name: String } -type Coordinator { - id:ID! - contactInformation: ContactInformation! - note: String - corgoBikes: [CargoBike]! -} enum Group{ KL @@ -80,7 +76,7 @@ type BikeModel { technicalEquipment: TechnicalEquipment! } -type ActiveMentor { +type Participants { id: ID! start: Date! end: Date! @@ -96,7 +92,7 @@ type ActiveMentor { Wahr, wenn die Person Pate ist. """ roleMentor: Boolean! - roleAmbulanz: Boolean! + roleAmbulance: Boolean! roleBringer: Boolean! "Date of workshop to become Mentor dt. Pate" workshopMentor: Date @@ -296,13 +292,13 @@ type Address { } type Query { - CargobikeById(token:String!,id:ID!): CargoBike + CargobikeById(id:ID!): CargoBike Cargobikes(token:String!): [CargoBike]! CargobikesByProvider(token:String!,providerId:ID!): [CargoBike]! ProviderById(token:String!,id:ID!): Provider Providers(token:String!): [Provider]! - ActiveMentorById(token:String!,id:ID!): ActiveMentor - ActiveMentors(token:String!): [ActiveMentor]! + ParticipantsById(token:String!,id:ID!): Participants + Participantss(token:String!): [ Participants]! lendingStationById(token:String!, id:ID!): LendingStation lendingStations(token:String!): [LendingStation]! contactInformation(token:String!): [ContactInformation]! @@ -345,14 +341,13 @@ input CargoBikeInput { stickerBikeNameState: String note: String provider: String - coordinator: String insuranceData: String } type Mutation { "for testing" - addBike(id: ID!, token: String!, name: String): UpdateBikeResponse! + addBike(id: ID!, name: String): UpdateBikeResponse! "if id: null, then new bike will be created, else old bike will be updated" - cargoBike(token:String!,cargoBike: CargoBikeInput): UpdateBikeResponse! + cargoBike(cargoBike: CargoBikeInput): UpdateBikeResponse! } `;