From 7bcf3c3c4620a1cfc2711c661e25a0f14d12e0a1 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Tue, 15 Sep 2020 15:20:07 +0200 Subject: [PATCH] src/model/*: finished rough design of entities --- Dockerfile | 4 +-- src/model/BikeEvent.ts | 18 +++++++++----- src/model/BikeModel.ts | 11 +++++++++ src/model/CargoBike.ts | 49 ++++++++++++++++++++++++++++++++++--- src/model/Equipment.ts | 16 ++++++++++++ src/model/InsuranceData.ts | 6 +---- src/model/LendingStation.ts | 36 +++++++++++++++++++++++++++ src/model/LoanPeriod.ts | 26 ++++++++++++++++++++ src/model/Organization.ts | 26 ++++++++++++++++++++ src/model/Provider.ts | 20 +++++++++------ src/model/Taxes.ts | 18 ++++++++++++++ src/schema/type-defs.ts | 26 +++++++++++--------- 12 files changed, 221 insertions(+), 35 deletions(-) create mode 100644 src/model/BikeModel.ts create mode 100644 src/model/Equipment.ts create mode 100644 src/model/LendingStation.ts create mode 100644 src/model/LoanPeriod.ts create mode 100644 src/model/Organization.ts create mode 100644 src/model/Taxes.ts diff --git a/Dockerfile b/Dockerfile index 6b03e8e..044fe96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ WORKDIR / COPY ./src /src COPY ./package*.json ./ -COPY ./gulpfile.js ./tsconfig.json ./ +COPY ./gulpfile.js ./ COPY ./ormconfig.json ./ RUN npm install RUN npm install -g gulp @@ -11,5 +11,5 @@ RUN npm install gulp RUN gulp EXPOSE 4000 -EXPOSE 5432 + CMD ["npm", "start"] \ No newline at end of file diff --git a/src/model/BikeEvent.ts b/src/model/BikeEvent.ts index 1a59a01..9c32b32 100644 --- a/src/model/BikeEvent.ts +++ b/src/model/BikeEvent.ts @@ -13,18 +13,24 @@ export class BikeEvent { @PrimaryGeneratedColumn() id: number; - @Column() + @Column({ + nullable: true + }) note: string; - @Column('simple-array') + @Column({ + type: 'date' + }) + date: Date; + + @Column('simple-array', { + nullable: true + }) documents: string[]; @Column({ type: 'enum', enum: BikeEventType }) - type: BikeEventType - - @Column() - otherEquipment: string; + eventType: BikeEventType } diff --git a/src/model/BikeModel.ts b/src/model/BikeModel.ts new file mode 100644 index 0000000..c1efd90 --- /dev/null +++ b/src/model/BikeModel.ts @@ -0,0 +1,11 @@ +import { PrimaryGeneratedColumn, Column, Entity } from 'typeorm'; +import { Bike } from './BikeFeatures'; + +@Entity() +export class BikeModel extends Bike { + @PrimaryGeneratedColumn() + id: number; + + @Column() + name: string; +} diff --git a/src/model/CargoBike.ts b/src/model/CargoBike.ts index 55a2bff..85deab4 100644 --- a/src/model/CargoBike.ts +++ b/src/model/CargoBike.ts @@ -5,6 +5,10 @@ import { ChainSwap } from './ChainSwap'; import { Provider } from './Provider'; import { Participant } from './Participant'; import { InsuranceData } from './InsuranceData'; +import { LoanPeriod } from './LoanPeriod'; +import { LendingStation } from './LendingStation'; +import { Taxes } from './Taxes'; +import { Equipment } from './Equipment'; export enum Group { KL, @@ -40,7 +44,19 @@ export class CargoBike extends Bike { @Column() serialNo: string; - @OneToMany(type => ChainSwap, chainSwap => chainSwap.cargoBike) + @OneToMany(type => Equipment, equipment => equipment.cargoBike, { + nullable: true + }) + equipment: Equipment[]; + + @Column({ + nullable: true + }) + otherEquipment: string; + + @OneToMany(type => ChainSwap, chainSwap => chainSwap.cargoBike, { + nullable: true + }) chainSwaps: ChainSwap[] // Security information @@ -68,12 +84,39 @@ export class CargoBike extends Bike { @Column() note: string; - @ManyToOne(type => Provider) + @ManyToOne(type => Provider, { + nullable: true + }) provider: Provider; @ManyToOne(type => Participant, participant => participant.cargoBikes) coordinator: Participant; - @OneToOne(type => InsuranceData) + @Column(type => InsuranceData) insuranceData: InsuranceData; + + @OneToMany(type => LoanPeriod, loanPeriod => loanPeriod.cargoBike, { + nullable: true + }) + loanPeriods: LoanPeriod[]; + + // This relation is a little redundant because one could also check all LoanPeriods for current station + @ManyToOne(type => LendingStation, lendingStation => lendingStation.cargoBikes, { + nullable: true + }) + lendingStation: LendingStation; + + @Column(type => Taxes) + taxes: Taxes; + + @Column({ + nullable: true + }) + lockedBy: number; + + @Column({ + type: 'date', + nullable: true + }) + lockedUntil: Date; } diff --git a/src/model/Equipment.ts b/src/model/Equipment.ts new file mode 100644 index 0000000..50a261c --- /dev/null +++ b/src/model/Equipment.ts @@ -0,0 +1,16 @@ +import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'; +import { CargoBike } from './CargoBike'; + +@Entity() +export class Equipment { + @PrimaryGeneratedColumn() + id: number; + + @Column() + serialNo: string; + + @OneToMany(type => CargoBike, cargoBike => cargoBike.equipment, { + nullable: true + }) + cargoBike: CargoBike; +} diff --git a/src/model/InsuranceData.ts b/src/model/InsuranceData.ts index 564489e..b5c80c2 100644 --- a/src/model/InsuranceData.ts +++ b/src/model/InsuranceData.ts @@ -1,10 +1,6 @@ -import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'; +import { Column } from 'typeorm'; -@Entity() export class InsuranceData { - @PrimaryGeneratedColumn() - id: number - @Column() name: string; diff --git a/src/model/LendingStation.ts b/src/model/LendingStation.ts new file mode 100644 index 0000000..b7ed521 --- /dev/null +++ b/src/model/LendingStation.ts @@ -0,0 +1,36 @@ +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'; + +@Entity() +export class LendingStation { + @PrimaryGeneratedColumn() + id: number; + + @Column() + name: string; + + @ManyToMany(type => ContactInformation) + @JoinTable() + contactInformation: ContactInformation[]; + + @Column() + addressStreet: string; + + @Column() + addressStreetNo: string; + + @Column() + addressZip: string; + + @OneToMany(type => LoanPeriod, loanPeriod => loanPeriod.lendingStation) + loanPeriods: LoanPeriod[]; + + @OneToMany(type => CargoBike, cargoBike => cargoBike.lendingStation) + cargoBikes: CargoBike[]; + + @ManyToOne(type => Organization, organization => organization.lendingStations) + organization: Organization; +} diff --git a/src/model/LoanPeriod.ts b/src/model/LoanPeriod.ts new file mode 100644 index 0000000..03f6245 --- /dev/null +++ b/src/model/LoanPeriod.ts @@ -0,0 +1,26 @@ +import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm'; +import { LendingStation } from './LendingStation'; +import { CargoBike } from './CargoBike'; + +@Entity() +export class LoanPeriod { + @PrimaryGeneratedColumn() + id: number; + + // I have to find out how typorm will map the datetange data type. + @Column({ + type: 'daterange' + }) + dateRange: Date[]; + + @ManyToOne(type => LendingStation, lendingStation => lendingStation.loanPeriods) + lendingStation: LendingStation; + + @Column({ + nullable: true + }) + note: string; + + @ManyToOne(type => CargoBike, cargoBike => cargoBike.loanPeriods) + cargoBike: CargoBike; +} diff --git a/src/model/Organization.ts b/src/model/Organization.ts new file mode 100644 index 0000000..11dac04 --- /dev/null +++ b/src/model/Organization.ts @@ -0,0 +1,26 @@ +import { PrimaryGeneratedColumn, OneToOne, OneToMany, Column } from 'typeorm'; +import { LendingStation } from './LendingStation'; +import { Provider } from './Provider'; + +export class Organization { + @PrimaryGeneratedColumn() + id: number; + + @OneToMany(type => LendingStation, lendingStation => lendingStation.organization) + lendingStations: LendingStation[]; + + @OneToOne(type => Provider, provider => provider.organization, { + nullable: true + }) + provider: Provider; + + @Column({ + nullable: true + }) + registerdAt: string; + + @Column({ + nullable: true + }) + registerNo: string; +} diff --git a/src/model/Provider.ts b/src/model/Provider.ts index 5680631..c908d8d 100644 --- a/src/model/Provider.ts +++ b/src/model/Provider.ts @@ -1,7 +1,9 @@ /* eslint no-unused-vars: "off" */ -import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from 'typeorm'; +import { PrimaryGeneratedColumn, Column, OneToMany, Entity, OneToOne } from 'typeorm'; import { ContactInformation } from './ContactInformation'; +import { LendingStation } from './LendingStation'; +import { Organization } from './Organization'; @Entity() export class Provider { @@ -11,7 +13,9 @@ export class Provider { @Column() name: string; - @Column() + @Column({ + nullable: false + }) formularName: String; @Column() @@ -23,12 +27,14 @@ export class Provider { @Column() zip: string; - @Column() - registerdAt: string; + @OneToMany(type => ContactInformation, contactInformation => contactInformation.provider) + contactInformation: ContactInformation[]; @Column() - registerNo: string; + isPrivatePerson: boolean; - @OneToMany(type => ContactInformation, contactInformation => contactInformation.provider) - contactInformation: ContactInformation[]; + @OneToOne(type => Organization, organization => organization.provider, { + nullable: true + }) + organization: Organization; } diff --git a/src/model/Taxes.ts b/src/model/Taxes.ts new file mode 100644 index 0000000..bdbb576 --- /dev/null +++ b/src/model/Taxes.ts @@ -0,0 +1,18 @@ +/* eslint no-unused-vars: "off" */ +import { Column } from 'typeorm'; + +export enum OrganizationArea { + IB, + ZB +} +export class Taxes { + @Column() + costCenter: string; + + @Column({ + type: 'enum', + enum: OrganizationArea, + nullable: true + }) + organizationArea: OrganizationArea; +} diff --git a/src/schema/type-defs.ts b/src/schema/type-defs.ts index 704930d..7a825ac 100644 --- a/src/schema/type-defs.ts +++ b/src/schema/type-defs.ts @@ -41,8 +41,10 @@ type CargoBike { coordinator: Participant insuranceData: InsuranceData! lendingstation: LendingStation + taxes: Taxes "null if not locked by other user" lockedBy: ID + lockedUntil: Date } type InsuranceData { @@ -82,7 +84,7 @@ Even bikes of the same model can have different properties. """ type BikeModel { id: ID! - name: String + name: String! dimensionsAndLoad: DimensionsAndLoad! technicalEquipment: TechnicalEquipment! } @@ -147,7 +149,7 @@ type Equipment { id: ID! serialNo: String! """ - TODO unclear what this means + TODO unclear what this means. tomy fragen """ investable: Boolean name: String @@ -156,10 +158,8 @@ type Equipment { "An Event is a point in time, when the state of the bike somehow changed." type BikeEvent { id: ID! - type: BikeEventType - """ - TODO: An Event should have a date field (Leon). - """ + eventType: BikeEventType + date: Date! note: String """ Path to documents @@ -238,9 +238,7 @@ type Provider { name: String! formularName: String address: Address - "If Club, at what court registered" - registeredAt: String - registerNumber: String + providerContactPerson: [ContactInformation] isPrivatePerson: Boolean! organisation: Organisation @@ -266,15 +264,19 @@ type ContactInformation { type Organisation{ id: ID! "(dt. Ausleihstation)" - lendinglocation: [LendingStation] + lendingStations: [LendingStation] "registration number of association" associationNo: String + "If Club, at what court registered" + registeredAt: String + provider: Provider otherdata: String } "(dt. Standort)" type LendingStation { id: ID! + name: String! contactInformation: [ContactInformation]! address: Address loanTimes: LoanTimes @@ -322,8 +324,8 @@ type Query { CargobikesByProvider(token:String!,providerId:ID!): [CargoBike]! ProviderById(token:String!,id:ID!): Provider Providers(token:String!): [Provider]! - ParticipantById(token:String!,id:ID!): Participant - Participants(token:String!): [ Participant]! + ParticipantById(token:String!,id:ID!): Participant + Participants(token:String!): [ Participant]! lendingStationById(token:String!, id:ID!): LendingStation lendingStations(token:String!): [LendingStation]! contactInformation(token:String!): [ContactInformation]!