From cfa0e14f8e2c207a4c91fc80d114280bfb5a4005 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Thu, 17 Sep 2020 12:42:44 +0200 Subject: [PATCH] src/model/*: added Workshop and Engagement. --- src/datasources/db/lendingstationAPI.ts | 14 ++ src/index.ts | 6 +- src/model/CargoBike.ts | 4 + src/model/Engagement.ts | 26 ++++ src/model/Participant.ts | 12 +- src/model/Workshop.ts | 21 +++ src/resolvers/cargobikeResolver.ts | 6 +- src/resolvers/lendingstationResolvers.ts | 17 +++ src/schema/type-defs.ts | 155 +++++++++++++++-------- 9 files changed, 205 insertions(+), 56 deletions(-) create mode 100644 src/datasources/db/lendingstationAPI.ts create mode 100644 src/model/Engagement.ts create mode 100644 src/model/Workshop.ts create mode 100644 src/resolvers/lendingstationResolvers.ts diff --git a/src/datasources/db/lendingstationAPI.ts b/src/datasources/db/lendingstationAPI.ts new file mode 100644 index 0000000..475b912 --- /dev/null +++ b/src/datasources/db/lendingstationAPI.ts @@ -0,0 +1,14 @@ +import { DataSource } from 'apollo-datasource'; +import { Connection, getConnection } from 'typeorm'; + +export class LendingStationAPI extends DataSource { + connection : Connection + constructor () { + super(); + this.connection = getConnection(); + } + + async updateLendingStation ({ lendingStation }:{ lendingStation: any }) { + return lendingStation; + } +} diff --git a/src/index.ts b/src/index.ts index 1989ba2..93d7e86 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,8 @@ import { LoanPeriod } from './model/LoanPeriod'; import { Participant } from './model/Participant'; import { Organization } from './model/Organization'; import { Provider } from './model/Provider'; +import { Engagement } from './model/Engagement'; +import { Workshop } from './model/Workshop'; require('dotenv').config(); @@ -62,7 +64,9 @@ createConnection({ LoanPeriod, Organization, Participant, - Provider + Provider, + Engagement, + Workshop ], synchronize: true, logging: false diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 8dfcfd8..6818578 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -9,6 +9,7 @@ import { LoanPeriod } from './LoanPeriod'; import { LendingStation } from './LendingStation'; import { Taxes } from './Taxes'; import { Equipment } from './Equipment'; +import { Engagement } from './Engagement'; export enum Group { KL = 'KL', @@ -125,6 +126,9 @@ export class CargoBike extends Bike { }) lendingStation: LendingStation; + @OneToMany(type => Engagement, engagement => engagement.cargoBike) + engagement: Engagement[]; + @Column(type => Taxes) taxes: Taxes; diff --git a/src/model/Engagement.ts b/src/model/Engagement.ts new file mode 100644 index 0000000..fbfb29b --- /dev/null +++ b/src/model/Engagement.ts @@ -0,0 +1,26 @@ +import { Entity, PrimaryGeneratedColumn, ManyToOne, Column } from 'typeorm'; +import { Participant } from './Participant'; +import { CargoBike } from './CargoBike'; + +@Entity() +export class Engagement { + @PrimaryGeneratedColumn() + id: number; + + @ManyToOne(type => Participant, participant => participant.engagement) + participant: Participant; + + @ManyToOne(type => CargoBike, cargoBike => cargoBike.engagement) + cargoBike: CargoBike; + + @Column({ + type: 'date' + }) + from: Date; + + @Column({ + type: 'date', + nullable: true + }) + to: Date; +} diff --git a/src/model/Participant.ts b/src/model/Participant.ts index 5319f20..a3245c8 100644 --- a/src/model/Participant.ts +++ b/src/model/Participant.ts @@ -1,6 +1,8 @@ -import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn, OneToMany } from 'typeorm'; +import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn, OneToMany, ManyToMany } from 'typeorm'; import { ContactInformation } from './ContactInformation'; import { CargoBike } from './CargoBike'; +import { Engagement } from './Engagement'; +import { Workshop } from './Workshop'; @Entity() export class Participant { @@ -38,6 +40,14 @@ export class Participant { @OneToMany(type => CargoBike, cargoBike => cargoBike.coordinator) cargoBikes: CargoBike[]; + @OneToMany(type => Engagement, engagement => engagement.participant) + engagement: Engagement[]; + + @ManyToMany(type => Workshop, workshop => workshop.participants, { + nullable: true + }) + workshops: Workshop[]; + @Column() roleCoreTeam: boolean; diff --git a/src/model/Workshop.ts b/src/model/Workshop.ts new file mode 100644 index 0000000..d4b6655 --- /dev/null +++ b/src/model/Workshop.ts @@ -0,0 +1,21 @@ +import { Entity, PrimaryGeneratedColumn, Column, ManyToMany } from 'typeorm'; +import { Participant } from './Participant'; + +@Entity() +export class Workshop { + @PrimaryGeneratedColumn() + id: number; + + @Column() + name: string; + + @Column({ + type: 'date' + }) + date: Date; + + @ManyToMany(type => Participant, participant => participant.workshops, { + nullable: true + }) + participants: Participant[]; +} diff --git a/src/resolvers/cargobikeResolver.ts b/src/resolvers/cargobikeResolver.ts index a27d9a9..bac8517 100644 --- a/src/resolvers/cargobikeResolver.ts +++ b/src/resolvers/cargobikeResolver.ts @@ -7,7 +7,7 @@ export default { if (req.permissions.includes(Permission.ReadBike)) { return dataSources.cargoBikeAPI.findCargoBikeById({ id }); } else { - throw new GraphQLError('Insufficient Permissions'); + return new GraphQLError('Insufficient Permissions'); } } }, @@ -16,14 +16,14 @@ export default { if (req.permissions.includes(Permission.WriteBike)) { return dataSources.cargoBikeAPI.updateBike({ id, name }); } else { - throw new GraphQLError('Insufficient Permissions'); + return new GraphQLError('Insufficient Permissions'); } }, cargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }:{dataSources: any, req: any }) => { if (req.permissions.includes(Permission.WriteBike)) { return dataSources.cargoBikeAPI.updateCargoBike({ cargoBike }); } else { - throw new GraphQLError('Insufficient Permissions'); + return new GraphQLError('Insufficient Permissions'); } } } diff --git a/src/resolvers/lendingstationResolvers.ts b/src/resolvers/lendingstationResolvers.ts new file mode 100644 index 0000000..3508edc --- /dev/null +++ b/src/resolvers/lendingstationResolvers.ts @@ -0,0 +1,17 @@ +import { Permission } from '../datasources/userserver/permission'; +import { GraphQLError } from 'graphql'; +import { LendingStation } from '../model/LendingStation'; + +export default { + Query: { + }, + Mutation: { + lendingStation: (_: any, { lendingStation }:{ lendingStation: LendingStation }, { dataSources, req }:{dataSources: any, req: any }) => { + if (req.permissions.includes(Permission.WriteBike)) { + return new GraphQLError('Not implemented'); + } else { + return new GraphQLError('Insufficient Permissions'); + } + } + } +}; diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index 61bc88a..7329234 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -46,6 +46,41 @@ type CargoBike { lockedUntil: Date } +input CargoBikeInput { + "if null, then new bike will be created, else old bike will be updated." + id: ID + "see column A in info tabelle" + group: Group! + name: String! + modelName: String! + numberOfWheels: Int! + forCargo: Boolean! + forChildren: Boolean! + numberOfChildren: Int! + """ + Safety is a custom type, that stores information about security features. + TODO: Should this be calles Security? + """ + security: SecurityInput! + """ + Does not refere to an extra table in the database. + """ + technicalEquipment: TechnicalEquipmentInput! + """ + Does not refere to an extra table in the database. + """ + 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: InsuranceDataInput! + taxes: TaxesInput +} + type InsuranceData { """ Eventuelly, this field will become an enum or a seperate data table and user can choose from a pool of insurance companies. @@ -267,6 +302,14 @@ type Security { adfcCoding: String } +input SecurityInput { + frameNumber: String! + keyNumberFrameLock: String + keyNumberAXAChain: String + policeCoding: String + adfcCoding: String +} + enum StickerBikeNameState { OK IMPROVE @@ -300,12 +343,24 @@ type ContactInformation { phone2Intern: String emailExtern: String emailIntern: String - note: String +} +input ContactInformationInput { + id: ID + name: String + firstName: String + retiredAt: Date + phoneExtern: String + phone2Extern: String + phoneIntern: String + phone2Intern: String + emailExtern: String + emailIntern: String + note: String } -type Organisation{ +type Organisation { id: ID! "(dt. Ausleihstation)" lendingStations: [LendingStation] @@ -322,11 +377,20 @@ type LendingStation { id: ID! name: String! contactInformation: [ContactInformation]! - address: Address + address: Address! loanTimes: LoanTimes loanPeriods: [LoanPeriod]! } +input LendingStationInput { + id: ID + name: String + contactInformation: [ContactInformationInput] + address: AddressInput + loanTimes: LoanTimesInput + loanPeriods: [LoanPeriodInput] +} + """ (dt. Ausleihzeiten) """ @@ -341,8 +405,23 @@ type LoanTimes { times: [String] } +""" +(dt. Ausleihzeiten) +""" +input LoanTimesInput { + 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)" -type LoanPeriod{ +type LoanPeriod { id: ID! from: Date! to: Date @@ -351,14 +430,30 @@ type LoanPeriod{ cargobike: CargoBike! } +input LoanPeriodInput { + id: ID + from: Date + to: Date + note: String + lendingstationID: Int! + cargobikeID: Int! +} + type Address { - street: String - number: String - zip: String + street: String! + number: String! + zip: String! +} + +input AddressInput { + street: String! + number: String! + zip: String! } type Query { cargobikeById(id:ID!): CargoBike + "!!!!" cargobikes: [CargoBike]! cargobikesByProvider(providerId:ID!): [CargoBike]! providerById(id:ID!): Provider @@ -370,55 +465,13 @@ type Query { contactInformation: [ContactInformation]! } -input CargoBikeInput { - "if null, then new bike will be created, else old bike will be updated." - id: ID - "see column A in info tabelle" - group: Group! - name: String! - modelName: String! - numberOfWheels: Int! - forCargo: Boolean! - forChildren: Boolean! - numberOfChildren: Int! - """ - Safety is a custom type, that stores information about security features. - TODO: Should this be calles Security? - """ - security: SecurityInput! - """ - Does not refere to an extra table in the database. - """ - technicalEquipment: TechnicalEquipmentInput! - """ - Does not refere to an extra table in the database. - """ - 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: InsuranceDataInput! - taxes: TaxesInput - -} - -input SecurityInput { - frameNumber: String! - keyNumberFrameLock: String - keyNumberAXAChain: String - policeCoding: String - adfcCoding: String -} - type Mutation { "for testing" addBike(id: ID!, name: String): CargoBike! "if id: null, then new bike will be created, else old bike will be updated" cargoBike(cargoBike: CargoBikeInput!): CargoBike! + "if id: null, then new lending station will be created, else existing one will be updated" + lendingStation(lendingStation: LendingStationInput): LendingStation! } `;