Merge pull request #11 from flotte-goes-smart/dev

Dev
pull/14/head
leonnicolas 4 years ago committed by GitHub
commit fcb983be58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,7 @@ import { CargoBike } from '../../model/CargoBike';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { BikeEvent } from '../../model/BikeEvent'; import { BikeEvent } from '../../model/BikeEvent';
import { Equipment } from '../../model/Equipment'; import { Equipment } from '../../model/Equipment';
import { Engagement } from '../../model/Engagement';
/** /**
* extended datasource to feed resolvers with data about cargoBikes * extended datasource to feed resolvers with data about cargoBikes
@ -29,8 +30,8 @@ export class CargoBikeAPI extends DataSource {
* Finds cargo bike by id, retuns null if id was not found * Finds cargo bike by id, retuns null if id was not found
* @param param0 id of bike * @param param0 id of bike
*/ */
async findCargoBikeById ({ id }:{id: any}) { async findCargoBikeById (id: number) {
return await this.connection.manager.getRepository(CargoBike).findOne({ id: id }); return (await this.connection.manager.getRepository(CargoBike).findByIds([id], { relations: ['lendingStation'] }))[0];
/* .createQueryBuilder() /* .createQueryBuilder()
.select('cargoBike') .select('cargoBike')
.from(CargoBike, 'cargoBike') .from(CargoBike, 'cargoBike')
@ -38,24 +39,42 @@ export class CargoBikeAPI extends DataSource {
.getOne() || new GraphQLError('ID not found'); */ .getOne() || new GraphQLError('ID not found'); */
} }
async findCargoBikeByEngagementId (id: number) {
return (await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.leftJoinAndSelect('engagement.cargoBike', 'cargoBike')
.where('engagement."cargoBikeId" = "cargoBike".id')
.andWhere('engagement.id = :id', { id: id })
.getOne())?.cargoBike;
}
/** /**
* Updates CargoBike and return updated cargoBike * Updates CargoBike and return updated cargoBike
* @param param0 cargoBike to be updated * @param param0 cargoBike to be updated
*/ */
async updateCargoBike ({ cargoBike }:{ cargoBike: CargoBike }) { async updateCargoBike ({ cargoBike }:{ cargoBike: any }) {
const bike = await this.connection.manager.createQueryBuilder() const bike = await this.connection.manager.createQueryBuilder()
.select('cargoBike') .select('cargoBike')
.from(CargoBike, 'cargoBike') .from(CargoBike, 'cargoBike')
.where('cargoBike.id = :id', { id: cargoBike.id }) .where('cargoBike.id = :id', { id: cargoBike.id })
.getOne(); .getOne();
if (bike) { if (bike) {
const lendingStationId = cargoBike.lendingStationId;
delete cargoBike.lendingStationId;
await this.connection.manager await this.connection.manager
.createQueryBuilder() .createQueryBuilder()
.update(CargoBike) .update(CargoBike)
.set({ ...cargoBike }) .set({ ...cargoBike })
.where('id = :id', { id: bike.id }) .where('id = :id', { id: bike.id })
.execute(); .execute();
return await this.findCargoBikeById({ id: bike.id }); if (lendingStationId || lendingStationId === null) {
await this.connection.getRepository(CargoBike)
.createQueryBuilder()
.relation(CargoBike, 'lendingStation')
.of(cargoBike.id)
.set(lendingStationId);
}
return await this.findCargoBikeById(bike.id);
} else { } else {
return new GraphQLError('ID not in database'); return new GraphQLError('ID not in database');
} }
@ -82,7 +101,7 @@ export class CargoBikeAPI extends DataSource {
async createBikeEvent ({ bikeEvent }: { bikeEvent: any }) { async createBikeEvent ({ bikeEvent }: { bikeEvent: any }) {
const event = new BikeEvent(); const event = new BikeEvent();
event.setValues(bikeEvent); event.setValues(bikeEvent);
event.cargoBike = await this.findCargoBikeById({ id: bikeEvent.cargoBikeId }) as unknown as CargoBike; event.cargoBike = await this.findCargoBikeById(bikeEvent.cargoBikeId) as unknown as CargoBike;
if (event.cargoBike instanceof GraphQLError) { if (event.cargoBike instanceof GraphQLError) {
return event.cargoBike; return event.cargoBike;
} }
@ -109,6 +128,7 @@ export class CargoBikeAPI extends DataSource {
.getOne(); .getOne();
} }
// think this can go
async findEquipmentJoinBikeById (id: number) { async findEquipmentJoinBikeById (id: number) {
return await this.connection.getRepository(Equipment) return await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment') .createQueryBuilder('equipment')
@ -117,6 +137,14 @@ export class CargoBikeAPI extends DataSource {
.getOne(); .getOne();
} }
async equipmentByCargoBikeId (offset: number, limit: number, id: number) {
return await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment')
.select()
.where('equipment."cargoBikeId" = :id', { id: id })
.getMany();
}
async createEquipment ({ equipment }: { equipment: any }) { async createEquipment ({ equipment }: { equipment: any }) {
const inserts = await this.connection.getRepository(Equipment) const inserts = await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment') .createQueryBuilder('equipment')
@ -131,29 +159,34 @@ export class CargoBikeAPI extends DataSource {
.relation(Equipment, 'cargoBike') .relation(Equipment, 'cargoBike')
.of(equipment.id) .of(equipment.id)
.set(equipment.cargoBikeId); .set(equipment.cargoBikeId);
return this.findEquipmentJoinBikeById(inserts.identifiers[0].id); // return this.findEquipmentJoinBikeById(inserts.identifiers[0].id);
} }
return this.findEquipmentById(inserts.identifiers[0].id); return this.findEquipmentById(inserts.identifiers[0].id);
} }
async cargoBikeByEquipmentId (id: number) {
return (await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment')
.leftJoinAndSelect('equipment.cargoBike', 'cargoBike')
.where('equipment.id = :id', { id: id })
.getOne())?.cargoBike;
}
/** /**
* Will update Equipment, crashes when id not in db or cargoBikeId not db. * Will update Equipment, crashes when id not in db or cargoBikeId not db.
* Will return updated Equipment joined with CargoBike only if cargoBike is was set in param0 * Will return updated Equipment joined with CargoBike only if cargoBike is was set in param0
* @param param0 struct with equipment properites * @param param0 struct with equipment properites
*/ */
async updateEquipment ({ equipment }: { equipment: any }) { async updateEquipment ({ equipment }: { equipment: any }) {
console.log(equipment);
const cargoBikeId = equipment.cargoBikeId; const cargoBikeId = equipment.cargoBikeId;
delete equipment.cargoBikeId; delete equipment.cargoBikeId;
console.log(equipment); await this.connection.getRepository(Equipment)
const inserts = await this.connection.getRepository(Equipment)
.createQueryBuilder('equipment') .createQueryBuilder('equipment')
.update() .update()
.set({ ...equipment }) .set({ ...equipment })
.where('id = :id', { id: equipment.id }) .where('id = :id', { id: equipment.id })
.returning('*') .returning('*')
.execute(); .execute();
console.log(inserts.raw[0]);
if (cargoBikeId || cargoBikeId === null) { if (cargoBikeId || cargoBikeId === null) {
await this.connection.getRepository(Equipment) await this.connection.getRepository(Equipment)
.createQueryBuilder() .createQueryBuilder()

@ -24,9 +24,8 @@ export class LendingStationAPI extends DataSource {
*/ */
async getLendingStations () { async getLendingStations () {
return await this.connection.manager return await this.connection.manager
.createQueryBuilder() .createQueryBuilder(LendingStation, 'lendingStation')
.select('lendingStation') .leftJoinAndSelect('CargoBike', 'cargoBike', 'cargoBike.lendingStation = lendingStation.id')// ('lendingStation.cargoBikes', 'cargoBike.lendingStation', 'cargoBike', 'cargoBike.lendingStationId = lendingStation.id')
.from(LendingStation, 'lendingStation')
.getMany() || new GraphQLError('Internal Server Error: could not query data from table lendingStation'); .getMany() || new GraphQLError('Internal Server Error: could not query data from table lendingStation');
} }
@ -35,7 +34,6 @@ export class LendingStationAPI extends DataSource {
* @param param0 new lendingStation * @param param0 new lendingStation
*/ */
async createLendingStation ({ lendingStation }:{ lendingStation: any }) { async createLendingStation ({ lendingStation }:{ lendingStation: any }) {
console.log(lendingStation);
const inserts = await this.connection.manager const inserts = await this.connection.manager
.createQueryBuilder() .createQueryBuilder()
.insert() .insert()

@ -0,0 +1,181 @@
import { DataSource } from 'apollo-datasource';
import { GraphQLError } from 'graphql';
import { Connection, getConnection } from 'typeorm';
import { CargoBike } from '../../model/CargoBike';
import { ContactInformation } from '../../model/ContactInformation';
import { Engagement } from '../../model/Engagement';
import { Participant } from '../../model/Participant';
export class ParticipantAPI extends DataSource {
connection : Connection
constructor () {
super();
this.connection = getConnection();
}
async getParticipantById (id: number) {
return await this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.select()
.where('participant.id = :id', { id: id })
.getOne();
}
async getParticipants (offset: number, limit: number) {
return await this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.select()
.offset(offset)
.limit(limit)
.getMany();
}
async participantByEngagementId (id: number) {
return (await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.leftJoinAndSelect('engagement.participant', 'participant')
.where('engagement.id = :id', { id: id })
.andWhere('engagement."participantId" = participant.id')
.getOne()).participant;
}
async participantByCargoBikeId (id:number) {
return await this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.leftJoinAndSelect('participant.cargoBike', 'cargoBike')
.where('"cargoBike".id = :id', { id: id })
.andWhere('"cargoBike"."participantId" = participant.id')
.getOne();
}
async engagementByParticipantId (id: number) {
return await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.select()
.where('engagement."participantId" = :id', { id: id })
.getOne();
}
async engagementByCargoBikeId (offset: number, limit: number, id: number) {
return await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.select()
.where('engagement."cargoBikeId" = :id', {
id: id
})
.offset(offset)
.limit(limit)
.orderBy('engagement.from', 'DESC')
.addOrderBy('engagement.to', 'DESC', 'NULLS FIRST')
.getMany();
}
async engagementById (id: number) {
return await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.select()
.where('engagement.id = :id', { id: id })
.getOne();
}
async contactInformationById (id: number) {
return await this.connection.getRepository(ContactInformation)
.createQueryBuilder('contactInformation')
.select()
.where('contactInformation.id = :id', { id: id })
.getOne();
}
async contactInformationByParticipantId (id: number) {
const ret = (await this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.leftJoinAndSelect('participant.contactInformation', 'contactInformation')
.where('participant."contactInformationId" = "contactInformation".id')
.andWhere('participant.id = :id', { id: id })
.printSql()
.getOne());
return (ret) ? ret.contactInformation : null;
}
/**
* creates participant and creates realtion to given contactInformation
* @param participant to be created
*/
async createParticipant (participant: any) {
let count = this.connection.getRepository(ContactInformation)
.createQueryBuilder('contactInformation')
.select()
.where('contactInformation.id = :id', { id: participant.contactInformationId })
.getCount();
if ((await count) !== 1) {
return new GraphQLError('contactInformationId not found.');
}
count = this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.select()
.where('participant."contactInformationId" = :id', {
id: participant.contactInformationId
})
.getCount();
if ((await count) !== 0) {
return new GraphQLError('contactInformationId already used by other participant.');
}
const inserts = await this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.insert()
.into(Participant)
.values([participant])
.returning('*')
.execute();
await this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.relation(Participant, 'contactInformation')
.of(inserts.identifiers[0].id)
.set(participant.contactInformationId);
return this.getParticipantById(inserts.identifiers[0].id);
}
async createContactInformation (contactInformation: any) {
const inserts = await this.connection.getRepository(ContactInformation)
.createQueryBuilder('contactInformation')
.insert()
.into(ContactInformation)
.values([contactInformation])
.returning('*')
.execute();
return this.contactInformationById(inserts.identifiers[0].id);
}
async createEngagement (engagement: any) {
const countB = this.connection.getRepository(CargoBike)
.createQueryBuilder('cargoBike')
.select()
.where('cargoBike.id = :id', { id: engagement.cargoBikeId })
.getCount();
const countP = this.connection.getRepository(Participant)
.createQueryBuilder('participant')
.select()
.where('participant.id = :id', { id: engagement.participantId })
.getCount();
if ((await countB) !== 1) { return new GraphQLError('BikeId not found'); }
if ((await countP) !== 1) { return new GraphQLError('ParticipantId not found'); }
// TODO check whether someone is already engaged with the bike
const inserts = await this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.insert()
.values([engagement])
.returning('*')
.execute();
this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.relation(Engagement, 'cargoBike')
.of(inserts.identifiers[0].id)
.set(engagement.cargoBikeId);
this.connection.getRepository(Engagement)
.createQueryBuilder('engagement')
.relation(Engagement, 'participant')
.of(inserts.identifiers[0].id)
.set(engagement.participantId);
return this.engagementById(inserts.identifiers[0].id);
}
}

@ -10,7 +10,6 @@ import { requiredPermissions } from './datasources/userserver/permission';
import { CargoBike } from './model/CargoBike'; import { CargoBike } from './model/CargoBike';
import { BikeEvent } from './model/BikeEvent'; import { BikeEvent } from './model/BikeEvent';
import { BikeModel } from './model/BikeModel'; import { BikeModel } from './model/BikeModel';
import { ChainSwap } from './model/ChainSwap';
import { ContactInformation } from './model/ContactInformation'; import { ContactInformation } from './model/ContactInformation';
import { Equipment } from './model/Equipment'; import { Equipment } from './model/Equipment';
import { LendingStation } from './model/LendingStation'; import { LendingStation } from './model/LendingStation';
@ -22,6 +21,9 @@ import { Engagement } from './model/Engagement';
import { Workshop } from './model/Workshop'; import { Workshop } from './model/Workshop';
import { LendingStationAPI } from './datasources/db/lendingstationAPI'; import { LendingStationAPI } from './datasources/db/lendingstationAPI';
import lendingstationResolvers from './resolvers/lendingstationResolvers'; import lendingstationResolvers from './resolvers/lendingstationResolvers';
import { ParticipantAPI } from './datasources/db/participantAPI';
import participantResolvers from './resolvers/participantResolvers';
import { ContactPerson } from './model/ContactPerson';
require('dotenv').config(); require('dotenv').config();
@ -59,7 +61,6 @@ createConnection({
CargoBike, CargoBike,
BikeEvent, BikeEvent,
BikeModel, BikeModel,
ChainSwap,
ContactInformation, ContactInformation,
Equipment, Equipment,
LendingStation, LendingStation,
@ -68,7 +69,8 @@ createConnection({
Participant, Participant,
Provider, Provider,
Engagement, Engagement,
Workshop Workshop,
ContactPerson
], ],
synchronize: true, synchronize: true,
logging: false logging: false
@ -81,12 +83,14 @@ const userAPI = new UserServerAPI(process.env.RPC_HOST);
const server = new ApolloServer({ const server = new ApolloServer({
resolvers: [ resolvers: [
bikeresolver, bikeresolver,
lendingstationResolvers lendingstationResolvers,
participantResolvers
], ],
typeDefs, typeDefs,
dataSources: () => ({ dataSources: () => ({
cargoBikeAPI: new CargoBikeAPI(), cargoBikeAPI: new CargoBikeAPI(),
lendingStationAPI: new LendingStationAPI(), lendingStationAPI: new LendingStationAPI(),
participantAPI: new ParticipantAPI(),
userAPI userAPI
}), }),
context: (req: any) => { context: (req: any) => {

@ -1,5 +1,5 @@
/* eslint no-unused-vars: "off" */ /* 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'; import { CargoBike } from './CargoBike';
export enum BikeEventType { export enum BikeEventType {
@ -7,14 +7,15 @@ export enum BikeEventType {
INBETRIEBNAHME = 'INBETRIEBNAHME', INBETRIEBNAHME = 'INBETRIEBNAHME',
AUSFALL = 'AUSFALL', AUSFALL = 'AUSFALL',
WARTUNG = 'WARTUNG', WARTUNG = 'WARTUNG',
KETTENWECHSEL = 'KETTENWECHSEL',
ANDERE = 'ANDERE' ANDERE = 'ANDERE'
} }
@Entity() @Entity()
export class BikeEvent { 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.id = id;
this.note = note; this.remark = remark;
this.date = date; this.date = date;
this.documents = documents; this.documents = documents;
this.cargoBike = cargoBike; this.cargoBike = cargoBike;
@ -27,13 +28,28 @@ export class BikeEvent {
@Column({ @Column({
nullable: true nullable: true
}) })
note: string; name: string;
@Column({
nullable: true
})
remark: string;
@Column({ @Column({
type: 'date' type: 'date'
}) })
date: Date; date: Date;
@Column({
nullable: true
})
mechanic: string;
@Column({
nullable: true
})
kexNoOldAXAChain: string;
@Column('simple-array', { @Column('simple-array', {
nullable: true nullable: true
}) })

@ -1,7 +1,6 @@
/* 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 } from 'typeorm';
import { Bike } from './BikeFeatures'; import { Bike } from './BikeFeatures';
import { ChainSwap } from './ChainSwap';
import { Provider } from './Provider'; import { Provider } from './Provider';
import { Participant } from './Participant'; import { Participant } from './Participant';
import { InsuranceData } from './InsuranceData'; import { InsuranceData } from './InsuranceData';
@ -81,12 +80,7 @@ export class CargoBike extends Bike {
type: 'simple-array', type: 'simple-array',
nullable: true nullable: true
}) })
otherEquipment: string[]; miscellaneousEquipment: string[];
@OneToMany(type => ChainSwap, chainSwap => chainSwap.cargoBike, {
nullable: true
})
chainSwaps: ChainSwap[]
// Security information // Security information
@Column(type => Security) @Column(type => Security)
@ -131,7 +125,8 @@ export class CargoBike extends Bike {
// This relation is a little redundant because one could also check all LoanPeriods for current station // This relation is a little redundant because one could also check all LoanPeriods for current station
@ManyToOne(type => LendingStation, lendingStation => lendingStation.cargoBikes, { @ManyToOne(type => LendingStation, lendingStation => lendingStation.cargoBikes, {
nullable: true nullable: true,
eager: true
}) })
lendingStation: LendingStation; lendingStation: LendingStation;

@ -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;
}

@ -1,5 +1,4 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from 'typeorm'; import { PrimaryGeneratedColumn, Column, Entity } from 'typeorm';
import { Provider } from './Provider';
@Entity() @Entity()
export class ContactInformation { export class ContactInformation {
@ -48,9 +47,8 @@ export class ContactInformation {
}) })
emailIntern: string; emailIntern: string;
@Column() @Column({
nullable: true
})
note: string; note: string;
@ManyToOne(type => Provider, provider => provider.contactInformation)
provider: Provider;
} }

@ -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;
}

@ -1,4 +1,4 @@
import { Entity, PrimaryGeneratedColumn, ManyToOne, Column } 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';
@ -7,7 +7,11 @@ export class Engagement {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;
@ManyToOne(type => Participant, participant => participant.engagement) @ManyToOne(type => Participant, participant => participant.engagement, {
})
@JoinColumn({
name: 'participantId'
})
participant: Participant; participant: Participant;
@ManyToOne(type => CargoBike, cargoBike => cargoBike.engagement) @ManyToOne(type => CargoBike, cargoBike => cargoBike.engagement)
@ -23,4 +27,19 @@ export class Engagement {
nullable: true nullable: true
}) })
to: Date; to: Date;
@Column()
roleCoordinator: boolean;
@Column()
roleEmployeADFC: boolean;
@Column()
roleMentor: boolean;
@Column()
roleAmbulance: boolean;
@Column()
roleBringer: boolean;
} }

@ -1,9 +1,9 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, OneToMany, ManyToOne } from 'typeorm'; import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, OneToMany, ManyToOne } from 'typeorm';
import { ContactInformation } from './ContactInformation';
import { LoanPeriod } from './LoanPeriod'; import { LoanPeriod } from './LoanPeriod';
import { CargoBike } from './CargoBike'; import { CargoBike } from './CargoBike';
import { Organization } from './Organization'; import { Organization } from './Organization';
import { Address } from './Provider'; import { Address } from './Provider';
import { ContactPerson } from './ContactPerson';
@Entity() @Entity()
export class LendingStation { export class LendingStation {
@ -13,9 +13,9 @@ export class LendingStation {
@Column() @Column()
name: string; name: string;
@ManyToMany(type => ContactInformation) @ManyToMany(type => ContactPerson)
@JoinTable() @JoinTable()
contactInformation: ContactInformation[]; contactPersons: ContactPerson[];
@Column(type => Address) @Column(type => Address)
address: Address; address: Address;
@ -23,7 +23,9 @@ export class LendingStation {
@OneToMany(type => LoanPeriod, loanPeriod => loanPeriod.lendingStation) @OneToMany(type => LoanPeriod, loanPeriod => loanPeriod.lendingStation)
loanPeriods: LoanPeriod[]; loanPeriods: LoanPeriod[];
@OneToMany(type => CargoBike, cargoBike => cargoBike.lendingStation) @OneToMany(type => CargoBike, cargoBike => cargoBike.lendingStation, {
eager: false
})
cargoBikes: CargoBike[]; cargoBikes: CargoBike[];
@ManyToOne(type => Organization, organization => organization.lendingStations) @ManyToOne(type => Organization, organization => organization.lendingStations)

@ -1,6 +1,6 @@
import { PrimaryGeneratedColumn, OneToOne, OneToMany, Column, Entity } from 'typeorm'; import { PrimaryGeneratedColumn, OneToOne, OneToMany, Column, Entity } from 'typeorm';
import { LendingStation } from './LendingStation'; import { LendingStation } from './LendingStation';
import { Provider } from './Provider'; import { Address, Provider } from './Provider';
@Entity() @Entity()
export class Organization { export class Organization {
@ -25,4 +25,7 @@ export class Organization {
nullable: true nullable: true
}) })
registerNo: string; registerNo: string;
@Column(type => Address)
address: Address;
} }

@ -15,18 +15,25 @@ export class Participant {
start: Date; start: Date;
@Column({ @Column({
type: 'date' type: 'date',
nullable: true
}) })
end: Date; end: Date;
@OneToOne(type => ContactInformation) @OneToOne(type => ContactInformation, {
nullable: true
})
@JoinColumn() @JoinColumn()
contactInformation: ContactInformation; contactInformation: ContactInformation;
@Column() @Column({
nullable: true
})
usernameflotte: string; usernameflotte: string;
@Column() @Column({
nullable: true
})
usernameSlack: string; usernameSlack: string;
@Column() @Column()
@ -49,30 +56,17 @@ export class Participant {
workshops: Workshop[]; workshops: Workshop[];
@Column() @Column()
roleCoreTeam: boolean; memberCoreTeam: boolean;
@Column()
roleCoordinator: boolean;
@Column()
roleEmployeADFC: boolean;
@Column()
roleMentor: boolean;
@Column()
roleAmbulance: boolean;
@Column()
roleBringer: boolean;
@Column({ @Column({
type: 'date' type: 'date',
nullable: true
}) })
workshopMentor: Date; workshopMentor: Date;
@Column({ @Column({
type: 'date' type: 'date',
nullable: true
}) })
workshopAmbulance: Date; workshopAmbulance: Date;

@ -1,7 +1,8 @@
/* eslint no-unused-vars: "off" */ /* 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 { ContactInformation } from './ContactInformation';
import { ContactPerson } from './ContactPerson';
import { LendingStation } from './LendingStation'; import { LendingStation } from './LendingStation';
import { Organization } from './Organization'; import { Organization } from './Organization';
@ -14,6 +15,11 @@ export class Address {
@Column() @Column()
zip: string; zip: string;
@Column({
nullable: true
})
city: string;
} }
@Entity() @Entity()
@ -21,19 +27,15 @@ export class Provider {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number; id: number;
@Column()
name: string;
@Column({ @Column({
nullable: false nullable: false
}) })
formularName: String; formularName: String;
@Column(type => Address) @OneToMany(type => ContactPerson, contactPerson => contactPerson.provider, {
address: Address; nullable: true
})
@OneToMany(type => ContactInformation, contactInformation => contactInformation.provider) contactPersons: ContactPerson[];
contactInformation: ContactInformation[];
@Column() @Column()
isPrivatePerson: boolean; isPrivatePerson: boolean;

@ -7,7 +7,13 @@ export class Workshop {
id: number; id: number;
@Column() @Column()
name: string; type: string;
@Column()
title: string;
@Column()
description: string;
@Column({ @Column({
type: 'date' type: 'date'

@ -5,7 +5,7 @@ export default {
Query: { Query: {
cargoBikeById: (_: any, { id }:{id: any}, { dataSources, req }:{dataSources: any, req: any }) => { cargoBikeById: (_: any, { id }:{id: any}, { dataSources, req }:{dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) { if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.findCargoBikeById({ id }); return dataSources.cargoBikeAPI.findCargoBikeById(id);
} else { } else {
return new GraphQLError('Insufficient Permissions'); return new GraphQLError('Insufficient Permissions');
} }
@ -39,6 +39,22 @@ export default {
} }
} }
}, },
CargoBike: {
engagement (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) {
return dataSources.participantAPI.engagementByCargoBikeId(offset, limit, parent.id);
},
coordinator (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) {
dataSources.participantAPI.participantByCargoBikeId(parent.id);
},
equipment (parent: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) {
return dataSources.cargoBikeAPI.equipmentByCargoBikeId(offset, limit, parent.id);
}
},
Equipment: {
cargoBike (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) {
return dataSources.cargoBikeAPI.cargoBikeByEquipmentId(parent.id);
}
},
Mutation: { Mutation: {
createCargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }:{dataSources: any, req: any }) => { createCargoBike: (_: any, { cargoBike }: { cargoBike: any }, { dataSources, req }:{dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteBike)) { if (req.permissions.includes(Permission.WriteBike)) {

@ -0,0 +1,60 @@
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');
}
},
participants: (_: any, { offset, limit }: { offset: number, limit: number }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.participantAPI.getParticipants(offset, limit);
} else {
return new GraphQLError('Insufficient Permissions');
}
}
},
Participant: {
engagement (parent: any, _: any, { dataSources, req }: { dataSources: any, req: any }) {
return dataSources.participantAPI.engagementByParticipantId(parent.id);
},
contactInformation (parent: any, _: any, { dataSources, req }: { dataSources: any, req: any }) {
return (dataSources.participantAPI.contactInformationByParticipantId(parent.id));
}
},
Engagement: {
cargoBike (parent: any, _: any, { dataSources, req }: { dataSources: any, req: any }) {
return dataSources.cargoBikeAPI.findCargoBikeByEngagementId(parent.id);
},
participant (parent: any, _: any, { dataSources, req }: { dataSources: any, req: any }) {
return dataSources.participantAPI.participantByEngagementId(parent.id);
}
},
Mutation: {
createParticipant: (_: any, { participant }: { participant: any }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteBike)) {
return dataSources.participantAPI.createParticipant(participant);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
createContactInformation: (_: any, { contactInformation }: { contactInformation: any }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteBike)) {
return dataSources.participantAPI.createContactInformation(contactInformation);
} else {
return new GraphQLError('Insufficient Permissions');
}
},
createEngagement: (_: any, { engagement }: { engagement: any }, { dataSources, req }: { dataSources: any, req: any }) => {
if (req.permissions.includes(Permission.WriteBike)) {
return dataSources.participantAPI.createEngagement(engagement);
} else {
return new GraphQLError('Insufficient Permissions');
}
}
}
};

@ -29,18 +29,18 @@ type CargoBike {
""" """
dimensionsAndLoad: DimensionsAndLoad! dimensionsAndLoad: DimensionsAndLoad!
bikeEvents: [BikeEvent] bikeEvents: [BikeEvent]
equipment: [Equipment] equipment(offset: Int!, limit: Int!): [Equipment]
"Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2"
otherEquipment: [String] miscellaneousEquipment: [String]
chainSwaps: [ChainSwap]
"Sticker State" "Sticker State"
stickerBikeNameState: StickerBikeNameState stickerBikeNameState: StickerBikeNameState
note: String note: String
provider: Provider provider: Provider
coordinator: Participant coordinator: Participant
insuranceData: InsuranceData! insuranceData: InsuranceData!
lendingstation: LendingStation lendingStation: LendingStation
taxes: Taxes taxes: Taxes
engagement(offset: Int!, limit: Int!): [Engagement]
"null if not locked by other user" "null if not locked by other user"
lockedBy: ID lockedBy: ID
lockedUntil: Date lockedUntil: Date
@ -69,7 +69,7 @@ input CargoBikeCreateInput {
""" """
dimensionsAndLoad: DimensionsAndLoadCreateInput! dimensionsAndLoad: DimensionsAndLoadCreateInput!
"Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2"
otherEquipment: [String] miscellaneousEquipment: [String]
"Sticker State" "Sticker State"
stickerBikeNameState: StickerBikeNameState stickerBikeNameState: StickerBikeNameState
@ -103,8 +103,8 @@ input CargoBikeUpdateInput {
""" """
dimensionsAndLoad: DimensionsAndLoadUpdateInput dimensionsAndLoad: DimensionsAndLoadUpdateInput
"Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2" "Refers to equipment that is not unique. See kommentierte info tabelle -> Fragen -> Frage 2"
otherEquipment: [String] miscellaneousEquipment: [String]
lendingStationId: ID
"Sticker State" "Sticker State"
stickerBikeNameState: StickerBikeNameState stickerBikeNameState: StickerBikeNameState
note: String note: String
@ -196,13 +196,13 @@ type BikeModel {
type Participant { type Participant {
id: ID! id: ID!
start: Date! start: Date!
end: Date! end: Date
mentor: ContactInformation! contactInformation: ContactInformation!
usernamefLotte: String usernamefLotte: String
usernameSlack: String usernameSlack: String
memberADFC: Boolean! memberADFC: Boolean!
locationZIPs: [String] locationZIPs: [String]
roleCoreTeam: Boolean! memberCoreTeam: Boolean!
roleCoordinator: Boolean! roleCoordinator: Boolean!
roleEmployeADFC: Boolean! roleEmployeADFC: Boolean!
""" """
@ -223,6 +223,58 @@ type Participant {
""" """
distributedActiveBikeParte: Boolean! distributedActiveBikeParte: Boolean!
reserve: String reserve: String
engagement: [Engagement]
}
input ParticipantCreateInput {
start: Date!
end: Date
"must create contactinformation first, if you want to use new"
contactInformationId: ID!
usernamefLotte: String
usernameSlack: String
memberADFC: Boolean!
locationZIPs: [String]
memberCoreTeam: Boolean!
"Date of workshop to become Mentor dt. Pate"
workshopMentor: Date
"Date of last Erste Hilfe Kurs?"
workshopAmbulance: Date
reserve: String
}
type Engagement {
id: ID!
from: Date!
to: Date
participant: Participant
cargoBike: CargoBike
roleCoordinator: Boolean!
roleEmployeADFC: Boolean!
"""
Wahr, wenn die Person Pate ist.
"""
roleMentor: Boolean!
roleAmbulance: Boolean!
roleBringer: Boolean!
}
input EngagementCreateInput {
from: Date!
to: Date
participantId: ID!
cargoBikeId: ID!
roleCoordinator: Boolean!
roleEmployeADFC: Boolean!
"""
Wahr, wenn die Person Pate ist.
"""
roleMentor: Boolean!
roleAmbulance: Boolean!
roleBringer: Boolean!
} }
type Taxes { type Taxes {
@ -449,7 +501,7 @@ type Provider {
id: ID! id: ID!
name: String! name: String!
formularName: String formularName: String
address: Address
providerContactPerson: [ContactInformation] providerContactPerson: [ContactInformation]
isPrivatePerson: Boolean! isPrivatePerson: Boolean!
@ -472,8 +524,8 @@ type ContactInformation {
} }
input ContactInformationCreateInput { input ContactInformationCreateInput {
name: String name: String!
firstName: String firstName: String!
retiredAt: Date retiredAt: Date
phoneExtern: String phoneExtern: String
phone2Extern: String phone2Extern: String
@ -498,8 +550,28 @@ input ContactInformationUpdateInput {
note: String 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 { type Organisation {
id: ID! id: ID!
address: Address
"(dt. Ausleihstation)" "(dt. Ausleihstation)"
lendingStations: [LendingStation] lendingStations: [LendingStation]
"registration number of association" "registration number of association"
@ -518,6 +590,9 @@ type LendingStation {
address: Address! address: Address!
loanTimes: LoanTimes loanTimes: LoanTimes
loanPeriods: [LoanPeriod]! loanPeriods: [LoanPeriod]!
cargoBikes: [CargoBike]
"Totola Amount of cargoBikes currently assigned to the lending station"
numCargoBikes: Int!
} }
input LendingStationCreateInput { input LendingStationCreateInput {
@ -535,6 +610,7 @@ input LendingStationUpdateInput {
address: AddressUpdateInput address: AddressUpdateInput
loanTimes: LoanTimesInput loanTimes: LoanTimesInput
loanPeriods: [LoanPeriodUpdateInput] loanPeriods: [LoanPeriodUpdateInput]
} }
""" """
@ -623,8 +699,10 @@ type Query {
"equipment by id, will return null if id not found" "equipment by id, will return null if id not found"
equipmentById(id: ID!): Equipment equipmentById(id: ID!): Equipment
providers: [Provider]! providers: [Provider]!
"particcipant by id"
participantById(id:ID!): Participant participantById(id:ID!): Participant
participants: [ Participant]! "p"
participants(offset: Int!, limit: Int!): [ Participant]!
lendingStationById(id:ID!): LendingStation lendingStationById(id:ID!): LendingStation
lendingStations: [LendingStation]! lendingStations: [LendingStation]!
contactInformation: [ContactInformation]! contactInformation: [ContactInformation]!
@ -647,6 +725,12 @@ type Mutation {
updateLendingStation(lendingstation: LendingStationUpdateInput!): LendingStation! updateLendingStation(lendingstation: LendingStationUpdateInput!): LendingStation!
"creates new BikeEvent" "creates new BikeEvent"
createBikeEvent(bikeEvent: BikeEventCreateInput): BikeEvent! createBikeEvent(bikeEvent: BikeEventCreateInput): BikeEvent!
"create participant"
createParticipant(participant: ParticipantCreateInput!): Participant!
"create new contactInfo"
createContactInformation(contactInformation: ContactInformationCreateInput!): ContactInformation!
"create Engagement"
createEngagement(engagement: EngagementCreateInput): Engagement!
} }
`; `;

Loading…
Cancel
Save