From 8f5d98c975330ba708094e8d7343abfc1f6642ad Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Mon, 21 Sep 2020 12:18:55 +0200 Subject: [PATCH] sr/model/* included suggested changes from fLotte --- src/datasources/db/lendingstationAPI.ts | 1 - src/datasources/db/participantAPI.ts | 22 ++++++++++++++++ src/index.ts | 12 ++++++--- src/model/BikeEvent.ts | 24 ++++++++++++++--- src/model/CargoBike.ts | 8 +----- src/model/ChainSwap.ts | 22 ---------------- src/model/ContactInformation.ts | 6 +---- src/model/ContactPerson.ts | 28 ++++++++++++++++++++ src/model/Engagement.ts | 15 +++++++++++ src/model/LendingStation.ts | 6 ++--- src/model/Organization.ts | 5 +++- src/model/Participant.ts | 20 +++----------- src/model/Provider.ts | 20 +++++++------- src/model/Workshop.ts | 8 +++++- src/resolvers/participantResolvers.ts | 19 ++++++++++++++ src/schema/type-defs.ts | 35 ++++++++++++++++++++++--- 16 files changed, 173 insertions(+), 78 deletions(-) create mode 100644 src/datasources/db/participantAPI.ts delete mode 100644 src/model/ChainSwap.ts create mode 100644 src/model/ContactPerson.ts create mode 100644 src/resolvers/participantResolvers.ts diff --git a/src/datasources/db/lendingstationAPI.ts b/src/datasources/db/lendingstationAPI.ts index c9b13d5..7658041 100644 --- a/src/datasources/db/lendingstationAPI.ts +++ b/src/datasources/db/lendingstationAPI.ts @@ -1,7 +1,6 @@ import { DataSource } from 'apollo-datasource'; import { GraphQLError } from 'graphql'; import { Connection, getConnection } from 'typeorm'; -import { CargoBike } from '../../model/CargoBike'; import { LendingStation } from '../../model/LendingStation'; export class LendingStationAPI extends DataSource { diff --git a/src/datasources/db/participantAPI.ts b/src/datasources/db/participantAPI.ts new file mode 100644 index 0000000..65a8ae4 --- /dev/null +++ b/src/datasources/db/participantAPI.ts @@ -0,0 +1,22 @@ +import { DataSource } from 'apollo-datasource'; +import { Connection, getConnection } from 'typeorm'; + +export class ParticipantAPI extends DataSource { + connection : Connection + constructor () { + super(); + this.connection = getConnection(); + } + + async getParticipantById (id: number) { + return { + id: 2 + }; + } + + async engagementByParticipantId (id: number) { + return { + id: 3 + }; + } +} diff --git a/src/index.ts b/src/index.ts index 1e2bc45..f541541 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,6 @@ import { requiredPermissions } from './datasources/userserver/permission'; import { CargoBike } from './model/CargoBike'; import { BikeEvent } from './model/BikeEvent'; import { BikeModel } from './model/BikeModel'; -import { ChainSwap } from './model/ChainSwap'; import { ContactInformation } from './model/ContactInformation'; import { Equipment } from './model/Equipment'; import { LendingStation } from './model/LendingStation'; @@ -22,6 +21,9 @@ import { Engagement } from './model/Engagement'; import { Workshop } from './model/Workshop'; import { LendingStationAPI } from './datasources/db/lendingstationAPI'; import lendingstationResolvers from './resolvers/lendingstationResolvers'; +import { ParticipantAPI } from './datasources/db/participantAPI'; +import participantResolvers from './resolvers/participantResolvers'; +import { ContactPerson } from './model/ContactPerson'; require('dotenv').config(); @@ -59,7 +61,6 @@ createConnection({ CargoBike, BikeEvent, BikeModel, - ChainSwap, ContactInformation, Equipment, LendingStation, @@ -68,7 +69,8 @@ createConnection({ Participant, Provider, Engagement, - Workshop + Workshop, + ContactPerson ], synchronize: true, logging: false @@ -81,12 +83,14 @@ const userAPI = new UserServerAPI(process.env.RPC_HOST); const server = new ApolloServer({ resolvers: [ bikeresolver, - lendingstationResolvers + lendingstationResolvers, + participantResolvers ], typeDefs, dataSources: () => ({ cargoBikeAPI: new CargoBikeAPI(), lendingStationAPI: new LendingStationAPI(), + participantAPI: new ParticipantAPI(), userAPI }), context: (req: any) => { diff --git a/src/model/BikeEvent.ts b/src/model/BikeEvent.ts index 5b271db..481e17d 100644 --- a/src/model/BikeEvent.ts +++ b/src/model/BikeEvent.ts @@ -1,5 +1,5 @@ /* eslint no-unused-vars: "off" */ -import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; +import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, TreeLevelColumn } from 'typeorm'; import { CargoBike } from './CargoBike'; export enum BikeEventType { @@ -7,14 +7,15 @@ export enum BikeEventType { INBETRIEBNAHME = 'INBETRIEBNAHME', AUSFALL = 'AUSFALL', WARTUNG = 'WARTUNG', + KETTENWECHSEL = 'KETTENWECHSEL', ANDERE = 'ANDERE' } @Entity() export class BikeEvent { - public setValues ({ id, note, date, documents, cargoBike, eventType }: { id: number, note: string, date: Date, documents: string[], cargoBike: CargoBike, eventType: BikeEventType}): void { + public setValues ({ id, remark, date, documents, cargoBike, eventType }: { id: number, remark: string, date: Date, documents: string[], cargoBike: CargoBike, eventType: BikeEventType}): void { this.id = id; - this.note = note; + this.remark = remark; this.date = date; this.documents = documents; this.cargoBike = cargoBike; @@ -27,13 +28,28 @@ export class BikeEvent { @Column({ nullable: true }) - note: string; + name: string; + + @Column({ + nullable: true + }) + remark: string; @Column({ type: 'date' }) date: Date; + @Column({ + nullable: true + }) + mechanic: string; + + @Column({ + nullable: true + }) + kexNoOldAXAChain: string; + @Column('simple-array', { nullable: true }) diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index e012c9d..baeddc1 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -1,7 +1,6 @@ /* eslint no-unused-vars: "off" */ import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, JoinColumn } from 'typeorm'; import { Bike } from './BikeFeatures'; -import { ChainSwap } from './ChainSwap'; import { Provider } from './Provider'; import { Participant } from './Participant'; import { InsuranceData } from './InsuranceData'; @@ -81,12 +80,7 @@ export class CargoBike extends Bike { type: 'simple-array', nullable: true }) - otherEquipment: string[]; - - @OneToMany(type => ChainSwap, chainSwap => chainSwap.cargoBike, { - nullable: true - }) - chainSwaps: ChainSwap[] + miscellaneousEquipment: string[]; // Security information @Column(type => Security) diff --git a/src/model/ChainSwap.ts b/src/model/ChainSwap.ts deleted file mode 100644 index dbab23b..0000000 --- a/src/model/ChainSwap.ts +++ /dev/null @@ -1,22 +0,0 @@ -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 index 766beb6..d3578fb 100644 --- a/src/model/ContactInformation.ts +++ b/src/model/ContactInformation.ts @@ -1,5 +1,4 @@ -import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from 'typeorm'; -import { Provider } from './Provider'; +import { PrimaryGeneratedColumn, Column, Entity } from 'typeorm'; @Entity() export class ContactInformation { @@ -50,7 +49,4 @@ export class ContactInformation { @Column() note: string; - - @ManyToOne(type => Provider, provider => provider.contactInformation) - provider: Provider; } diff --git a/src/model/ContactPerson.ts b/src/model/ContactPerson.ts new file mode 100644 index 0000000..4e2107b --- /dev/null +++ b/src/model/ContactPerson.ts @@ -0,0 +1,28 @@ +import { Column, Entity, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { ContactInformation } from './ContactInformation'; +import { LendingStation } from './LendingStation'; +import { Provider } from './Provider'; + +@Entity() +export class ContactPerson { + @PrimaryGeneratedColumn() + id: number; + + @ManyToOne(type => ContactInformation) + contactInformation: ContactInformation; + + @ManyToMany(type => LendingStation, lendingStation => lendingStation.contactPersons, { + nullable: true + }) + lendingStation: LendingStation; + + @ManyToMany(type => Provider, provider => provider.contactPersons, { + nullable: true + }) + provider: Provider[]; + + @Column({ + type: 'boolean' + }) + intern: boolean; +} diff --git a/src/model/Engagement.ts b/src/model/Engagement.ts index fbfb29b..236e913 100644 --- a/src/model/Engagement.ts +++ b/src/model/Engagement.ts @@ -23,4 +23,19 @@ export class Engagement { nullable: true }) to: Date; + + @Column() + roleCoordinator: boolean; + + @Column() + roleEmployeADFC: boolean; + + @Column() + roleMentor: boolean; + + @Column() + roleAmbulance: boolean; + + @Column() + roleBringer: boolean; } diff --git a/src/model/LendingStation.ts b/src/model/LendingStation.ts index 21af80d..9186739 100644 --- a/src/model/LendingStation.ts +++ b/src/model/LendingStation.ts @@ -1,9 +1,9 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, OneToMany, ManyToOne } from 'typeorm'; -import { ContactInformation } from './ContactInformation'; import { LoanPeriod } from './LoanPeriod'; import { CargoBike } from './CargoBike'; import { Organization } from './Organization'; import { Address } from './Provider'; +import { ContactPerson } from './ContactPerson'; @Entity() export class LendingStation { @@ -13,9 +13,9 @@ export class LendingStation { @Column() name: string; - @ManyToMany(type => ContactInformation) + @ManyToMany(type => ContactPerson) @JoinTable() - contactInformation: ContactInformation[]; + contactPersons: ContactPerson[]; @Column(type => Address) address: Address; diff --git a/src/model/Organization.ts b/src/model/Organization.ts index 24f018e..d62d5d5 100644 --- a/src/model/Organization.ts +++ b/src/model/Organization.ts @@ -1,6 +1,6 @@ import { PrimaryGeneratedColumn, OneToOne, OneToMany, Column, Entity } from 'typeorm'; import { LendingStation } from './LendingStation'; -import { Provider } from './Provider'; +import { Address, Provider } from './Provider'; @Entity() export class Organization { @@ -25,4 +25,7 @@ export class Organization { nullable: true }) registerNo: string; + + @Column(type => Address) + address: Address; } diff --git a/src/model/Participant.ts b/src/model/Participant.ts index a3245c8..b0b4aca 100644 --- a/src/model/Participant.ts +++ b/src/model/Participant.ts @@ -15,7 +15,8 @@ export class Participant { start: Date; @Column({ - type: 'date' + type: 'date', + nullable: true }) end: Date; @@ -49,22 +50,7 @@ export class Participant { workshops: Workshop[]; @Column() - roleCoreTeam: boolean; - - @Column() - roleCoordinator: boolean; - - @Column() - roleEmployeADFC: boolean; - - @Column() - roleMentor: boolean; - - @Column() - roleAmbulance: boolean; - - @Column() - roleBringer: boolean; + memberCoreTeam: boolean; @Column({ type: 'date' diff --git a/src/model/Provider.ts b/src/model/Provider.ts index 963dbb4..61053a8 100644 --- a/src/model/Provider.ts +++ b/src/model/Provider.ts @@ -1,7 +1,8 @@ /* eslint no-unused-vars: "off" */ -import { PrimaryGeneratedColumn, Column, OneToMany, Entity, OneToOne } from 'typeorm'; +import { PrimaryGeneratedColumn, Column, OneToMany, Entity, OneToOne, ChildEntity } from 'typeorm'; import { ContactInformation } from './ContactInformation'; +import { ContactPerson } from './ContactPerson'; import { LendingStation } from './LendingStation'; import { Organization } from './Organization'; @@ -14,6 +15,11 @@ export class Address { @Column() zip: string; + + @Column({ + nullable: true + }) + city: string; } @Entity() @@ -21,19 +27,15 @@ export class Provider { @PrimaryGeneratedColumn() id: number; - @Column() - name: string; - @Column({ nullable: false }) formularName: String; - @Column(type => Address) - address: Address; - - @OneToMany(type => ContactInformation, contactInformation => contactInformation.provider) - contactInformation: ContactInformation[]; + @OneToMany(type => ContactPerson, contactPerson => contactPerson.provider, { + nullable: true + }) + contactPersons: ContactPerson[]; @Column() isPrivatePerson: boolean; diff --git a/src/model/Workshop.ts b/src/model/Workshop.ts index d4b6655..5c7d81e 100644 --- a/src/model/Workshop.ts +++ b/src/model/Workshop.ts @@ -7,7 +7,13 @@ export class Workshop { id: number; @Column() - name: string; + type: string; + + @Column() + title: string; + + @Column() + description: string; @Column({ type: 'date' diff --git a/src/resolvers/participantResolvers.ts b/src/resolvers/participantResolvers.ts new file mode 100644 index 0000000..083cf9d --- /dev/null +++ b/src/resolvers/participantResolvers.ts @@ -0,0 +1,19 @@ +import { GraphQLError } from 'graphql'; +import { Permission } from '../datasources/userserver/permission'; + +export default { + Query: { + participantById: (_: any, { id }: { id: any }, { dataSources, req }: { dataSources: any, req: any }) => { + if (req.permissions.includes(Permission.ReadBike)) { + return dataSources.participantAPI.getParticipantById(id); + } else { + return new GraphQLError('Insufficient Permissions'); + } + } + }, + Participant: { + engagement (parent: any, _: any, { dataSources, req }: { dataSources: any, req: any }) { + return dataSources.participantAPI.engagementByParticipantId(parent.id); + } + } +}; diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index 1323f8b..5562dd5 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -31,7 +31,7 @@ type CargoBike { bikeEvents: [BikeEvent] equipment: [Equipment] "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" - otherEquipment: [String] + miscellaneousEquipment: [String] chainSwaps: [ChainSwap] "Sticker State" stickerBikeNameState: StickerBikeNameState @@ -69,7 +69,7 @@ input CargoBikeCreateInput { """ dimensionsAndLoad: DimensionsAndLoadCreateInput! "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" - otherEquipment: [String] + miscellaneousEquipment: [String] "Sticker State" stickerBikeNameState: StickerBikeNameState @@ -103,7 +103,7 @@ input CargoBikeUpdateInput { """ dimensionsAndLoad: DimensionsAndLoadUpdateInput "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" - otherEquipment: [String] + miscellaneousEquipment: [String] lendingStationId: ID "Sticker State" stickerBikeNameState: StickerBikeNameState @@ -223,6 +223,13 @@ type Participant { """ distributedActiveBikeParte: Boolean! reserve: String + engagement: Engagement +} + +type Engagement { + id: ID! + participant: Participant + cargobike: CargoBike } type Taxes { @@ -449,7 +456,7 @@ type Provider { id: ID! name: String! formularName: String - address: Address + providerContactPerson: [ContactInformation] isPrivatePerson: Boolean! @@ -498,8 +505,28 @@ input ContactInformationUpdateInput { note: String } +type contactPerson { + id: ID! + intern: Boolean! + contactInformation: ContactInformation! +} + +input contactPersonCreateInput { + intern: Boolean! + contactInformationCreate: ContactInformationCreateInput + contactInformationExisting: ContactInformationUpdateInput +} + +input contactPersonUpdateInput { + id: ID! + intern: Boolean + contactInformationCreate: ContactInformationCreateInput + contactInformationExisting: ContactInformationUpdateInput +} + type Organisation { id: ID! + address: Address "(dt. Ausleihstation)" lendingStations: [LendingStation] "registration number of association"