src/model/*: applied changes from flotte

pull/14/head
leonnicolas 4 years ago
parent 14b9d3445a
commit e92d379a53
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -1,8 +1,6 @@
import { DataSource } from 'apollo-datasource'; import { DataSource } from 'apollo-datasource';
import { GraphQLError } from 'graphql';
import { Connection, getConnection } from 'typeorm'; import { Connection, getConnection } from 'typeorm';
import { ContactInformation } from '../../model/ContactInformation'; import { ContactInformation } from '../../model/ContactInformation';
import { ContactPerson } from '../../model/ContactPerson';
import { LendingStation } from '../../model/LendingStation'; import { LendingStation } from '../../model/LendingStation';
export class ContactInformationAPI extends DataSource { export class ContactInformationAPI extends DataSource {
@ -13,11 +11,6 @@ export class ContactInformationAPI extends DataSource {
} }
async contactPersonById (id: number) { async contactPersonById (id: number) {
return await this.connection.getRepository(ContactPerson)
.createQueryBuilder('contactPerson')
.select()
.where('"contactPerson".id = :id', { id: id })
.getOne();
} }
async numContactInformationById (id: number) { async numContactInformationById (id: number) {
@ -45,6 +38,7 @@ export class ContactInformationAPI extends DataSource {
.getOne(); .getOne();
} }
// TODO change to contactinformation
async contactPersonsByLendingStationId (id: number) { async contactPersonsByLendingStationId (id: number) {
return await this.connection return await this.connection
.createQueryBuilder() .createQueryBuilder()
@ -54,14 +48,16 @@ export class ContactInformationAPI extends DataSource {
} }
async contactInformationByContactPersonId (id: number) { async contactInformationByContactPersonId (id: number) {
return (await this.connection.getRepository(ContactPerson) /* return (await this.connection.getRepository(ContactPerson)
.createQueryBuilder('contactPerson') .createQueryBuilder('contactPerson')
.leftJoinAndSelect('contactPerson.contactInformation', 'contactInformation') .leftJoinAndSelect('contactPerson.contactInformation', 'contactInformation')
.where('"contactPerson".id = :id', { id: id }) .where('"contactPerson".id = :id', { id: id })
.getOne())?.contactInformation || new GraphQLError('ContactPerson has no ContactInformtion'); .getOne())?.contactInformation || new GraphQLError('ContactPerson has no ContactInformtion');
*/
} }
async createContactPerson (contactPerson: any) { async createContactPerson (contactPerson: any) {
/*
if (await this.contactInformationById(contactPerson.contactInformationId)) { if (await this.contactInformationById(contactPerson.contactInformationId)) {
let inserts: any; let inserts: any;
try { try {
@ -83,9 +79,11 @@ export class ContactInformationAPI extends DataSource {
} else { } else {
return null; return null;
} }
*/
} }
async updateContactPerson (contactPerson: any) { async updateContactPerson (contactPerson: any) {
/*
if (await this.contactPersonById(contactPerson.id)) { if (await this.contactPersonById(contactPerson.id)) {
const contactInformationId = contactPerson.contactInformationId; const contactInformationId = contactPerson.contactInformationId;
delete contactPerson.contactInformationId; delete contactPerson.contactInformationId;
@ -120,5 +118,7 @@ export class ContactInformationAPI extends DataSource {
// updated bike not found // updated bike not found
return null; return null;
} }
*/
} }
} }

@ -7,7 +7,13 @@ export class LockUtils {
} }
/** /**
* locks any entity that implements Lockable * Locks any Entity, that
* @param connection
* @param target
* @param alias
* @param id
* @param req
* @param dataSources
*/ */
static async lockEntity (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, req: any, dataSources: any) { static async lockEntity (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, req: any, dataSources: any) {
const token = this.getToken(req); const token = this.getToken(req);
@ -42,6 +48,15 @@ export class LockUtils {
} }
} }
/**
* Unlocks any entity that implements Lockable.
* @param connection
* @param target
* @param alias
* @param id
* @param req
* @param dataSources
*/
static async unlockEntity (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, req: any, dataSources: any) { static async unlockEntity (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, req: any, dataSources: any) {
const token = this.getToken(req); const token = this.getToken(req);
const userId = await dataSources.userAPI.getUserId(token); const userId = await dataSources.userAPI.getUserId(token);
@ -78,6 +93,15 @@ export class LockUtils {
} }
} }
/**
* Returns true if Entity is locked by another user.
* @param connection
* @param target
* @param alias
* @param id
* @param req
* @param dataSources
*/
static async isLocked (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, req: any, dataSources: any) { static async isLocked (connection: Connection, target: ObjectType<Lockable>, alias: string, id: number, req: any, dataSources: any) {
const token = this.getToken(req); const token = this.getToken(req);
const userId = await dataSources.userAPI.getUserId(token); const userId = await dataSources.userAPI.getUserId(token);

@ -23,11 +23,15 @@ import { LendingStationAPI } from './datasources/db/lendingstationAPI';
import lendingstationResolvers from './resolvers/lendingstationResolvers'; import lendingstationResolvers from './resolvers/lendingstationResolvers';
import { ParticipantAPI } from './datasources/db/participantAPI'; import { ParticipantAPI } from './datasources/db/participantAPI';
import participantResolvers from './resolvers/participantResolvers'; import participantResolvers from './resolvers/participantResolvers';
import { ContactPerson } from './model/ContactPerson';
import { ContactInformationAPI } from './datasources/db/contactinformationAPI'; import { ContactInformationAPI } from './datasources/db/contactinformationAPI';
import providerResolvers from './resolvers/providerResolvers'; import providerResolvers from './resolvers/providerResolvers';
import { ProviderAPI } from './datasources/db/providerAPI'; import { ProviderAPI } from './datasources/db/providerAPI';
import contactinformationResolvers from './resolvers/contactinformationResolvers'; import contactinformationResolvers from './resolvers/contactinformationResolvers';
import { Person } from './model/Person';
import { WorkshopType } from './model/WorkshopType';
import { EngagementType } from './model/EngagementType';
import { EquipmentType } from './model/EquipmentType';
import { BikeEventType } from './model/BikeEventType';
require('dotenv').config(); require('dotenv').config();
@ -64,17 +68,21 @@ createConnection({
entities: [ entities: [
CargoBike, CargoBike,
BikeEvent, BikeEvent,
BikeEventType,
BikeModel, BikeModel,
ContactInformation, ContactInformation,
Equipment, Equipment,
EquipmentType,
LendingStation, LendingStation,
TimeFrame, TimeFrame,
Organisation, Organisation,
Participant, Participant,
Provider, Provider,
Engagement, Engagement,
EngagementType,
Workshop, Workshop,
ContactPerson Person,
WorkshopType
], ],
synchronize: true, synchronize: true,
logging: false logging: false

@ -1,54 +1,47 @@
/* eslint no-unused-vars: "off" */ /* eslint no-unused-vars: "off" */
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, TreeLevelColumn } from 'typeorm'; import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, TreeLevelColumn } from 'typeorm';
import { CargoBike } from './CargoBike'; import { CargoBike } from './CargoBike';
import { BikeEventType } from './BikeEventType';
export enum BikeEventType { import { Participant } from './Participant';
KAUF = 'KAUF', import { type } from 'os';
INBETRIEBNAHME = 'INBETRIEBNAHME',
AUSFALL = 'AUSFALL',
WARTUNG = 'WARTUNG',
KETTENWECHSEL = 'KETTENWECHSEL',
ANDERE = 'ANDERE'
}
@Entity() @Entity()
export class BikeEvent { export class BikeEvent {
public setValues ({ id, remark, date, documents, cargoBike, eventType }: { id: number, remark: string, date: Date, documents: string[], cargoBike: CargoBike, eventType: BikeEventType}): void { public setValues ({ id, remark, date, documents, cargoBike }: { id: number, remark: string, date: Date, documents: string[], cargoBike: CargoBike}): void {
this.id = id; this.id = id;
this.remark = remark; this.remark = remark;
this.date = date; this.date = date;
this.documents = documents; this.documents = documents;
this.cargoBike = cargoBike; this.cargoBike = cargoBike;
this.eventType = eventType;
} }
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;
@Column({ @Column({
nullable: true type: 'text',
nullable: false,
default: ''
}) })
name: string; description: string;
@Column({ @Column({
nullable: true nullable: false,
default: ''
}) })
remark: string; remark: string;
@Column({ @Column({
type: 'date' type: 'date',
default: () => 'CURRENT_DATE'
}) })
date: Date; date: Date;
@Column({ @ManyToOne(type => Participant)
nullable: true responsible: Participant;
})
mechanic: string;
@Column({ @ManyToOne(type => Participant)
nullable: true related: Participant;
})
kexNoOldAXAChain: string;
@Column('simple-array', { @Column('simple-array', {
nullable: true nullable: true
@ -61,9 +54,6 @@ export class BikeEvent {
@JoinColumn({ name: 'cargoBikeId' }) @JoinColumn({ name: 'cargoBikeId' })
cargoBike: CargoBike; cargoBike: CargoBike;
@Column({ @ManyToOne(type => BikeEventType)
type: 'enum', bikeEventType: BikeEventType;
enum: BikeEventType
})
eventType: BikeEventType
} }

@ -0,0 +1,22 @@
import { Lockable } from './CargoBike';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class BikeEventType implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column({
nullable: true,
type: 'timestamp'
})
lockedUntil: Date;
@Column({
nullable: true
})
lockedBy: number;
}

@ -1,5 +1,5 @@
/* eslint no-unused-vars: "off" */ /* eslint no-unused-vars: "off" */
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, JoinColumn } from 'typeorm'; import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, JoinColumn, ManyToMany } from 'typeorm';
import { Bike } from './BikeFeatures'; import { Bike } from './BikeFeatures';
import { Provider } from './Provider'; import { Provider } from './Provider';
import { Participant } from './Participant'; import { Participant } from './Participant';
@ -9,6 +9,7 @@ import { Taxes } from './Taxes';
import { Equipment } from './Equipment'; import { Equipment } from './Equipment';
import { Engagement } from './Engagement'; import { Engagement } from './Engagement';
import { BikeEvent } from './BikeEvent'; import { BikeEvent } from './BikeEvent';
import { EquipmentType } from './EquipmentType';
export enum Group { export enum Group {
KL = 'KL', KL = 'KL',
@ -81,11 +82,9 @@ export class CargoBike extends Bike implements Lockable {
}) })
equipment: Equipment[]; equipment: Equipment[];
@Column({ // Equipment that is not unique and is supposed to be selected out of a list e.g. drop down
type: 'simple-array', @ManyToMany(type => EquipmentType, equipmentType => equipmentType.cargoBikes)
nullable: true miscellaneousEquipment: EquipmentType[];
})
miscellaneousEquipment: string[];
// Security information // Security information
@Column(type => Security) @Column(type => Security)

@ -1,54 +1,60 @@
import { PrimaryGeneratedColumn, Column, Entity } from 'typeorm'; import { PrimaryGeneratedColumn, Column, Entity, ManyToOne, OneToOne } from 'typeorm';
import { Lockable } from './CargoBike';
import { Person } from './Person';
import { Address } from './Provider';
import { Participant } from './Participant';
@Entity() @Entity()
export class ContactInformation { export class ContactInformation implements Lockable {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;
@Column() @ManyToOne(type => Person, person => person.contactInformation)
name: string; person: Person;
@Column() @OneToOne(type => Participant, participant => participant.contactInformation, {
firstName: string;
@Column({
type: 'date',
nullable: true nullable: true
}) })
retiredAt: Date; participant: Participant;
@Column(type => {
return Address;
})
address: Address;
@Column({ @Column({
nullable: true nullable: true
}) })
phoneExtern: string; phone: string;
@Column({ @Column({
nullable: true nullable: true
}) })
phone2Extern: string; phone2: string;
@Column({ @Column({
nullable: true nullable: true
}) })
phoneIntern: string; email: string;
@Column({ @Column({
nullable: true nullable: true
}) })
phone2Intern: string; email2: string;
@Column({ @Column({
nullable: true nullable: true
}) })
emailExtern: string; note: string;
@Column({ @Column({
nullable: true nullable: true,
type: 'timestamp'
}) })
emailIntern: string; lockedUntil: Date;
@Column({ @Column({
nullable: true nullable: true
}) })
note: string; lockedBy: number;
} }

@ -1,28 +0,0 @@
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
})
lendingStations: LendingStation[];
@ManyToOne(type => Provider, provider => provider.contactPersons, {
nullable: true
})
provider: Provider[];
@Column({
type: 'boolean'
})
intern: boolean;
}

@ -1,6 +1,7 @@
import { Entity, PrimaryGeneratedColumn, ManyToOne, Column, JoinColumn } from 'typeorm'; import { Entity, PrimaryGeneratedColumn, ManyToOne, Column, JoinColumn } from 'typeorm';
import { Participant } from './Participant'; import { Participant } from './Participant';
import { CargoBike } from './CargoBike'; import { CargoBike } from './CargoBike';
import { EngagementType } from './EngagementType';
@Entity() @Entity()
export class Engagement { export class Engagement {
@ -17,6 +18,9 @@ export class Engagement {
@ManyToOne(type => CargoBike, cargoBike => cargoBike.engagement) @ManyToOne(type => CargoBike, cargoBike => cargoBike.engagement)
cargoBike: CargoBike; cargoBike: CargoBike;
@ManyToOne(type => EngagementType, engagementType => engagementType.engagementIds)
engagementTypeId: number;
@Column({ @Column({
type: 'date' type: 'date'
}) })
@ -31,9 +35,6 @@ export class Engagement {
@Column() @Column()
roleCoordinator: boolean; roleCoordinator: boolean;
@Column()
roleEmployeeADFC: boolean;
@Column() @Column()
roleMentor: boolean; roleMentor: boolean;

@ -0,0 +1,32 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Lockable } from './CargoBike';
import { Engagement } from './Engagement';
@Entity()
export class EngagementType implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column({
type: 'text',
nullable: true
})
description: string;
@OneToMany(type => Engagement, engagement => engagement.engagementTypeId)
engagementIds: number[];
@Column({
nullable: true,
type: 'timestamp'
})
lockedUntil: Date;
@Column({
nullable: true
})
lockedBy: number;
}

@ -0,0 +1,31 @@
import { Column, Entity, ManyToMany, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { CargoBike, Lockable } from './CargoBike';
@Entity()
export class EquipmentType implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column({
type: 'text',
default: ''
})
description: string;
@ManyToMany(type => CargoBike, cargoBike => cargoBike.miscellaneousEquipment)
cargoBikes: CargoBike[];
@Column({
nullable: true,
type: 'timestamp'
})
lockedUntil: Date;
@Column({
nullable: true
})
lockedBy: number;
}

@ -1,8 +1,8 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, OneToMany, ManyToOne } from 'typeorm'; import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from 'typeorm';
import { TimeFrame } from './TimeFrame'; import { TimeFrame } from './TimeFrame';
import { Organisation } from './Organisation'; import { Organisation } from './Organisation';
import { Address } from './Provider'; import { Address } from './Provider';
import { ContactPerson } from './ContactPerson'; import { ContactInformation } from './ContactInformation';
@Entity() @Entity()
export class LendingStation { export class LendingStation {
@ -12,9 +12,11 @@ export class LendingStation {
@Column() @Column()
name: string; name: string;
@ManyToMany(type => ContactPerson) @ManyToOne(type => ContactInformation)
@JoinTable() contactInformationIntern: ContactInformation;
contactPersons: ContactPerson[];
@ManyToOne(type => ContactInformation)
contactInformationExtern: ContactInformation;
@Column(type => Address) @Column(type => Address)
address: Address; address: Address;

@ -20,7 +20,7 @@ export class Participant {
}) })
end: Date; end: Date;
@OneToOne(type => ContactInformation, { @OneToOne(type => ContactInformation, contactInformation => contactInformation.participant, {
nullable: true nullable: true
}) })
@JoinColumn() @JoinColumn()
@ -36,14 +36,12 @@ export class Participant {
}) })
usernameSlack: string; usernameSlack: string;
@Column()
memberADFC: boolean;
@Column({ @Column({
type: 'simple-array' type: 'simple-array'
}) })
locationZIPs: string[]; locationZIPs: string[];
// this should go, we dont need it
@OneToMany(type => CargoBike, cargoBike => cargoBike.coordinator) @OneToMany(type => CargoBike, cargoBike => cargoBike.coordinator)
cargoBikes: CargoBike[]; cargoBikes: CargoBike[];
@ -55,23 +53,18 @@ export class Participant {
}) })
workshops: Workshop[]; workshops: Workshop[];
@Column()
memberCoreTeam: boolean;
@Column({ @Column({
type: 'date', nullable: false,
nullable: true default: false
}) })
workshopMentor: Date; memberCoreTeam: boolean;
@Column({ @Column({
type: 'date', nullable: false,
nullable: true default: false
}) })
workshopAmbulance: Date; employeeADFC: boolean;
@Column({ @Column()
nullable: true memberADFC: boolean;
})
reserve: string;
} }

@ -0,0 +1,28 @@
import { Lockable } from './CargoBike';
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { ContactInformation } from './ContactInformation';
@Entity()
export class Person implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@Column()
firstName: string;
@Column()
name: string;
@OneToMany(type => ContactInformation, contactInformation => contactInformation.person)
contactInformation: ContactInformation;
@Column({
nullable: true
})
lockedUntil: Date;
@Column({
nullable: true
})
lockedBy: number;
}

@ -1,30 +1,34 @@
/* eslint no-unused-vars: "off" */ /* eslint no-unused-vars: "off" */
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, OneToOne, ChildEntity } from 'typeorm'; import { PrimaryGeneratedColumn, Column, OneToMany, Entity, OneToOne, ChildEntity, ManyToOne, JoinColumn } from 'typeorm';
import { CargoBike } from './CargoBike'; import { CargoBike, Lockable } from './CargoBike';
import { ContactInformation } from './ContactInformation'; import { ContactInformation } from './ContactInformation';
import { ContactPerson } from './ContactPerson';
import { LendingStation } from './LendingStation';
import { Organisation } from './Organisation'; import { Organisation } from './Organisation';
export class Address { export class Address {
@Column() @Column({
default: ''
})
street: string; street: string;
@Column() @Column({
default: ''
})
number: string; number: string;
@Column() @Column({
default: ''
})
zip: string; zip: string;
@Column({ @Column({
nullable: true default: ''
}) })
city: string; city: string;
} }
@Entity() @Entity()
export class Provider { export class Provider implements Lockable {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;
@ -33,19 +37,31 @@ export class Provider {
}) })
formName: String; formName: String;
@OneToMany(type => ContactPerson, contactPerson => contactPerson.provider, { // is null when Provider is an organisation
@OneToOne(type => ContactInformation, {
nullable: true nullable: true
}) })
contactPersons: ContactPerson[]; @JoinColumn()
contactInformationId: number;
// is null when Provider is a private Person
@OneToOne(type => Organisation, organization => organization.provider, {
nullable: true
})
@JoinColumn()
organization: Organisation;
@OneToMany(type => CargoBike, cargoBike => cargoBike.provider) @OneToMany(type => CargoBike, cargoBike => cargoBike.provider)
cargoBikes: CargoBike[]; cargoBikes: CargoBike[];
@Column() @Column({
isPrivatePerson: boolean; nullable: true,
type: 'timestamp'
})
lockedUntil: Date;
@OneToOne(type => Organisation, organization => organization.provider, { @Column({
nullable: true nullable: true
}) })
organization: Organisation; lockedBy: number;
} }

@ -1,13 +1,15 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany } from 'typeorm'; import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, ManyToOne } from 'typeorm';
import { Participant } from './Participant'; import { Participant } from './Participant';
import { WorkshopType } from './WorkshopType';
import { Lockable } from './CargoBike';
@Entity() @Entity()
export class Workshop { export class Workshop implements Lockable {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;
@Column() @ManyToOne(type => WorkshopType, workshopType => workshopType.workshopIds)
type: string; workshopTypeId: number;
@Column() @Column()
title: string; title: string;
@ -24,4 +26,25 @@ export class Workshop {
nullable: true nullable: true
}) })
participants: Participant[]; participants: Participant[];
@ManyToOne(type => Participant, {
nullable: false
})
trainer1Id: number;
@ManyToOne(type => Participant, {
nullable: true
})
trainer2: Participant;
@Column({
nullable: true,
type: 'timestamp'
})
lockedUntil: Date;
@Column({
nullable: true
})
lockedBy: number;
} }

@ -0,0 +1,26 @@
import { Lockable } from './CargoBike';
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Workshop } from './Workshop';
@Entity()
export class WorkshopType implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@OneToMany(type => Workshop, workshop => workshop.workshopTypeId)
workshopIds: number[];
@Column({
nullable: true,
type: 'timestamp'
})
lockedUntil: Date;
@Column({
nullable: true
})
lockedBy: number;
}
Loading…
Cancel
Save