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