use ids insteaf of objects

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

@ -118,11 +118,6 @@ export class CargoBikeAPI extends DataSource {
.values([cargoBike])
.returning('*')
.execute();
await entityManager.getRepository(CargoBike)
.createQueryBuilder('cargobike')
.relation(CargoBike, 'provider')
.of(inserts.identifiers[0].id)
.set(cargoBike?.providerId);
cargoBike?.equipmentTypeIds && await entityManager.getRepository(CargoBike)
.createQueryBuilder('cargobike')
.relation(CargoBike, 'equipmentTypeIds')
@ -372,7 +367,7 @@ export class CargoBikeAPI extends DataSource {
.getOne();
}
async eqiupmentTypes (offset: number, limit: number) {
async equipmentTypes (offset: number, limit: number) {
return await this.connection.getRepository(EquipmentType)
.createQueryBuilder('et')
.select()

@ -41,18 +41,22 @@ export class LendingStationAPI extends DataSource {
* @param id of cargoBike
*/
async lendingStationByCargoBikeId (id: number) {
return (await this.connection.getRepository(TimeFrame)
.createQueryBuilder('timeframe')
.leftJoinAndSelect('timeframe.lendingStation', 'lendingStation')
.where('timeframe."cargoBikeId" = :id', { id: id })
.andWhere('timeframe."dateRange" && daterange(CURRENT_DATE,CURRENT_DATE,\'[]\')')
.getOne())?.lendingStation;
return await this.connection.getRepository(TimeFrame)
.createQueryBuilder('tf')
.relation(TimeFrame, 'lendingStationId')
.of((await this.connection.getRepository(TimeFrame)// TODO maybe this can be done with a sub query
.createQueryBuilder('tf')
.select()
.where('"cargoBikeId" = :cid', { cid: id })
.andWhere('"dateRange" && daterange(CURRENT_DATE,CURRENT_DATE,\'[]\')')
.getOne())?.id)
.loadOne();
}
async lendingStationByTimeFrameId (id: number) {
return await this.connection.getRepository(LendingStation)
.createQueryBuilder('lendingStation')
.relation(TimeFrame, 'lendingStation')
.relation(TimeFrame, 'lendingStationId')
.of(id)
.loadOne();
}
@ -198,7 +202,7 @@ export class LendingStationAPI extends DataSource {
.returning('*')
.values([timeFrame])
.execute();
await entityManager.getRepository(TimeFrame)
/* await entityManager.getRepository(TimeFrame)
.createQueryBuilder()
.relation(TimeFrame, 'cargoBike')
.of(inserts.identifiers[0].id)
@ -208,6 +212,7 @@ export class LendingStationAPI extends DataSource {
.relation(TimeFrame, 'lendingStation')
.of(inserts.identifiers[0].id)
.set(timeFrame.lendingStationId);
*/
});
} catch (e) {
if (e instanceof UserInputError) {

@ -40,12 +40,16 @@ export class ParticipantAPI extends DataSource {
}
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();
return await this.connection.getRepository(Engagement)
.createQueryBuilder('e')
.relation(Engagement, 'participantId')
.of((await this.connection.getRepository(Engagement)// TODO do this with a sub query
.createQueryBuilder('e')
.select()
.where('"dateRange" && daterange(CURRENT_DATE,CURRENT_DATE,\'[]\')')
.andWhere('"cargoBikeId" = :id', { id: id })
.getOne())?.id
).loadOne();
}
async engagementByParticipantId (id: number) {
@ -128,7 +132,7 @@ export class ParticipantAPI extends DataSource {
}
/**
* creates participant and creates realtion to given contactInformation
* creates participant and creates relation to given contactInformation
* @param participant to be created
*/
async createParticipant (participant: any) {
@ -142,7 +146,7 @@ export class ParticipantAPI extends DataSource {
.returning('*')
.execute();
});
return this.getParticipantById(inserts.identifiers[0].id);
return this.getParticipantById(inserts?.identifiers[0].id);
}
async createEngagement (engagement: any) {
@ -167,7 +171,7 @@ export class ParticipantAPI extends DataSource {
.returning('*')
.execute();
});
return this.engagementById(inserts.identifiers[0].id);
return this.engagementById(inserts?.identifiers[0].id);
}
async createEngagementType (engagementType: any) {

@ -40,7 +40,7 @@ export class ProviderAPI extends DataSource {
async providerByCargoBikeId (id: number) {
return await this.connection.getRepository(CargoBike)
.createQueryBuilder('cb')
.relation(CargoBike, 'provider')
.relation(CargoBike, 'providerId')
.of(id)
.loadOne();
}

@ -181,10 +181,10 @@ export class CargoBike implements Lockable {
})
note: string;
@ManyToOne(type => Provider, {
@ManyToOne(type => Provider, provider => provider.cargoBikeIds, {
nullable: true
})
provider: Provider;
providerId: number;
@OneToMany(type => BikeEvent, bikeEvent => bikeEvent.cargoBikeId, {
nullable: true,
@ -196,7 +196,7 @@ export class CargoBike implements Lockable {
@Column(type => InsuranceData)
insuranceData: InsuranceData;
@OneToMany(type => TimeFrame, loanPeriod => loanPeriod.cargoBike, {
@OneToMany(type => TimeFrame, timeFrame => timeFrame.cargoBikeId, {
nullable: true
})
timeFrames: TimeFrame[];

@ -3,20 +3,6 @@ import { CargoBike, Lockable } from './CargoBike';
@Entity()
export class Equipment implements Lockable {
setValues ({ id, serialNo, title, description, cargoBike }: {
id: number,
serialNo: string,
title: string,
description: string,
cargoBike: CargoBike
}) {
this.id = id;
this.serialNo = serialNo;
this.title = title;
this.description = description;
this.cargoBike = cargoBike;
}
@PrimaryGeneratedColumn()
id: number;

@ -56,7 +56,7 @@ export class LendingStation implements Lockable {
@Column(type => LoanPeriod)
loanPeriod: LoanPeriod;
@OneToMany(type => TimeFrame, timeFrame => timeFrame.lendingStation)
@OneToMany(type => TimeFrame, timeFrame => timeFrame.lendingStationId)
timeFrames: TimeFrame[];
@ManyToOne(type => Organisation, organization => organization.lendingStations)

@ -55,8 +55,8 @@ export class Provider implements Lockable {
})
organisationId: number;
@OneToMany(type => CargoBike, cargoBike => cargoBike.provider)
cargoBikes: CargoBike[];
@OneToMany(type => CargoBike, cargoBike => cargoBike.providerId)
cargoBikeIds: number[];
@Column({
nullable: true,

@ -1,4 +1,4 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { LendingStation } from './LendingStation';
import { CargoBike, Lockable } from './CargoBike';
@ -16,7 +16,10 @@ export class TimeFrame implements Lockable {
dateRange: Date[];
@ManyToOne(type => LendingStation, lendingStation => lendingStation.timeFrames)
lendingStation: LendingStation;
@JoinColumn({
name: 'lendingStationId'
})
lendingStationId: number;
@Column({
nullable: true
@ -24,7 +27,10 @@ export class TimeFrame implements Lockable {
note: string;
@ManyToOne(type => CargoBike, cargoBike => cargoBike.timeFrames)
cargoBike: CargoBike;
@JoinColumn({
name: 'cargoBikeId'
})
cargoBikeId: number;
@Column({
nullable: true,

Loading…
Cancel
Save