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

@ -23,11 +23,15 @@ 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';
import { ContactInformationAPI } from './datasources/db/contactinformationAPI';
import providerResolvers from './resolvers/providerResolvers';
import { ProviderAPI } from './datasources/db/providerAPI';
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();
@ -64,17 +68,21 @@ createConnection({
entities: [
CargoBike,
BikeEvent,
BikeEventType,
BikeModel,
ContactInformation,
Equipment,
EquipmentType,
LendingStation,
TimeFrame,
Organisation,
Participant,
Provider,
Engagement,
EngagementType,
Workshop,
ContactPerson
Person,
WorkshopType
],
synchronize: true,
logging: false

@ -1,54 +1,47 @@
/* eslint no-unused-vars: "off" */
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, TreeLevelColumn } from 'typeorm';
import { CargoBike } from './CargoBike';
export enum BikeEventType {
KAUF = 'KAUF',
INBETRIEBNAHME = 'INBETRIEBNAHME',
AUSFALL = 'AUSFALL',
WARTUNG = 'WARTUNG',
KETTENWECHSEL = 'KETTENWECHSEL',
ANDERE = 'ANDERE'
}
import { BikeEventType } from './BikeEventType';
import { Participant } from './Participant';
import { type } from 'os';
@Entity()
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.remark = remark;
this.date = date;
this.documents = documents;
this.cargoBike = cargoBike;
this.eventType = eventType;
}
@PrimaryGeneratedColumn()
id: number;
@Column({
nullable: true
type: 'text',
nullable: false,
default: ''
})
name: string;
description: string;
@Column({
nullable: true
nullable: false,
default: ''
})
remark: string;
@Column({
type: 'date'
type: 'date',
default: () => 'CURRENT_DATE'
})
date: Date;
@Column({
nullable: true
})
mechanic: string;
@ManyToOne(type => Participant)
responsible: Participant;
@Column({
nullable: true
})
kexNoOldAXAChain: string;
@ManyToOne(type => Participant)
related: Participant;
@Column('simple-array', {
nullable: true
@ -61,9 +54,6 @@ export class BikeEvent {
@JoinColumn({ name: 'cargoBikeId' })
cargoBike: CargoBike;
@Column({
type: 'enum',
enum: BikeEventType
})
eventType: BikeEventType
@ManyToOne(type => BikeEventType)
bikeEventType: 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" */
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, JoinColumn, ManyToMany } from 'typeorm';
import { Bike } from './BikeFeatures';
import { Provider } from './Provider';
import { Participant } from './Participant';
@ -9,6 +9,7 @@ import { Taxes } from './Taxes';
import { Equipment } from './Equipment';
import { Engagement } from './Engagement';
import { BikeEvent } from './BikeEvent';
import { EquipmentType } from './EquipmentType';
export enum Group {
KL = 'KL',
@ -81,11 +82,9 @@ export class CargoBike extends Bike implements Lockable {
})
equipment: Equipment[];
@Column({
type: 'simple-array',
nullable: true
})
miscellaneousEquipment: string[];
// Equipment that is not unique and is supposed to be selected out of a list e.g. drop down
@ManyToMany(type => EquipmentType, equipmentType => equipmentType.cargoBikes)
miscellaneousEquipment: EquipmentType[];
// Security information
@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()
export class ContactInformation {
export class ContactInformation implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@ManyToOne(type => Person, person => person.contactInformation)
person: Person;
@Column()
firstName: string;
@Column({
type: 'date',
@OneToOne(type => Participant, participant => participant.contactInformation, {
nullable: true
})
retiredAt: Date;
participant: Participant;
@Column(type => {
return Address;
})
address: Address;
@Column({
nullable: true
})
phoneExtern: string;
phone: string;
@Column({
nullable: true
})
phone2Extern: string;
phone2: string;
@Column({
nullable: true
})
phoneIntern: string;
email: string;
@Column({
nullable: true
})
phone2Intern: string;
email2: string;
@Column({
nullable: true
})
emailExtern: string;
note: string;
@Column({
nullable: true
nullable: true,
type: 'timestamp'
})
emailIntern: string;
lockedUntil: Date;
@Column({
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 { Participant } from './Participant';
import { CargoBike } from './CargoBike';
import { EngagementType } from './EngagementType';
@Entity()
export class Engagement {
@ -17,6 +18,9 @@ export class Engagement {
@ManyToOne(type => CargoBike, cargoBike => cargoBike.engagement)
cargoBike: CargoBike;
@ManyToOne(type => EngagementType, engagementType => engagementType.engagementIds)
engagementTypeId: number;
@Column({
type: 'date'
})
@ -31,9 +35,6 @@ export class Engagement {
@Column()
roleCoordinator: boolean;
@Column()
roleEmployeeADFC: boolean;
@Column()
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 { Organisation } from './Organisation';
import { Address } from './Provider';
import { ContactPerson } from './ContactPerson';
import { ContactInformation } from './ContactInformation';
@Entity()
export class LendingStation {
@ -12,9 +12,11 @@ export class LendingStation {
@Column()
name: string;
@ManyToMany(type => ContactPerson)
@JoinTable()
contactPersons: ContactPerson[];
@ManyToOne(type => ContactInformation)
contactInformationIntern: ContactInformation;
@ManyToOne(type => ContactInformation)
contactInformationExtern: ContactInformation;
@Column(type => Address)
address: Address;

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

@ -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" */
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, OneToOne, ChildEntity } from 'typeorm';
import { CargoBike } from './CargoBike';
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, OneToOne, ChildEntity, ManyToOne, JoinColumn } from 'typeorm';
import { CargoBike, Lockable } from './CargoBike';
import { ContactInformation } from './ContactInformation';
import { ContactPerson } from './ContactPerson';
import { LendingStation } from './LendingStation';
import { Organisation } from './Organisation';
export class Address {
@Column()
@Column({
default: ''
})
street: string;
@Column()
@Column({
default: ''
})
number: string;
@Column()
@Column({
default: ''
})
zip: string;
@Column({
nullable: true
default: ''
})
city: string;
}
@Entity()
export class Provider {
export class Provider implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@ -33,19 +37,31 @@ export class Provider {
})
formName: String;
@OneToMany(type => ContactPerson, contactPerson => contactPerson.provider, {
// is null when Provider is an organisation
@OneToOne(type => ContactInformation, {
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)
cargoBikes: CargoBike[];
@Column()
isPrivatePerson: boolean;
@Column({
nullable: true,
type: 'timestamp'
})
lockedUntil: Date;
@OneToOne(type => Organisation, organization => organization.provider, {
@Column({
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 { WorkshopType } from './WorkshopType';
import { Lockable } from './CargoBike';
@Entity()
export class Workshop {
export class Workshop implements Lockable {
@PrimaryGeneratedColumn()
id: number;
@Column()
type: string;
@ManyToOne(type => WorkshopType, workshopType => workshopType.workshopIds)
workshopTypeId: number;
@Column()
title: string;
@ -24,4 +26,25 @@ export class Workshop {
nullable: true
})
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