|
|
@ -1,4 +1,5 @@
|
|
|
|
import { DataSource } from 'apollo-datasource';
|
|
|
|
import { DataSource } from 'apollo-datasource';
|
|
|
|
|
|
|
|
import { ApolloError } from 'apollo-server';
|
|
|
|
import { GraphQLError } from 'graphql';
|
|
|
|
import { GraphQLError } from 'graphql';
|
|
|
|
import { Connection, EntityManager, getConnection } from 'typeorm';
|
|
|
|
import { Connection, EntityManager, getConnection } from 'typeorm';
|
|
|
|
import { CargoBike } from '../../model/CargoBike';
|
|
|
|
import { CargoBike } from '../../model/CargoBike';
|
|
|
@ -59,6 +60,14 @@ export class LendingStationAPI extends DataSource {
|
|
|
|
.getMany() || [];
|
|
|
|
.getMany() || [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async timeFramesByCargoBikeId (id: number) {
|
|
|
|
|
|
|
|
return await this.connection.getRepository(CargoBike)
|
|
|
|
|
|
|
|
.createQueryBuilder('cargobike')
|
|
|
|
|
|
|
|
.relation(CargoBike, 'timeFrames')
|
|
|
|
|
|
|
|
.of(id)
|
|
|
|
|
|
|
|
.loadMany();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async timeFramesByLendingStationId (id: number) {
|
|
|
|
async timeFramesByLendingStationId (id: number) {
|
|
|
|
return await this.connection.getRepository(TimeFrame)
|
|
|
|
return await this.connection.getRepository(TimeFrame)
|
|
|
|
.createQueryBuilder('timeFrame')
|
|
|
|
.createQueryBuilder('timeFrame')
|
|
|
@ -134,6 +143,7 @@ export class LendingStationAPI extends DataSource {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async createTimeFrame (timeFrame: any) {
|
|
|
|
async createTimeFrame (timeFrame: any) {
|
|
|
|
|
|
|
|
// TODO check overlapping time frames
|
|
|
|
let inserts: any;
|
|
|
|
let inserts: any;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await this.connection.transaction(async (entityManager: EntityManager) => {
|
|
|
|
await this.connection.transaction(async (entityManager: EntityManager) => {
|
|
|
@ -159,7 +169,8 @@ export class LendingStationAPI extends DataSource {
|
|
|
|
.set(timeFrame.lendingStationId);
|
|
|
|
.set(timeFrame.lendingStationId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
return new GraphQLError('Transaction could not be completed');
|
|
|
|
// TODO: throw diffrent error when date input is wrong
|
|
|
|
|
|
|
|
return new ApolloError('Transaction could not be completed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inserts.generatedMaps[0].id = inserts.identifiers[0].id;
|
|
|
|
inserts.generatedMaps[0].id = inserts.identifiers[0].id;
|
|
|
|
return inserts.generatedMaps[0];
|
|
|
|
return inserts.generatedMaps[0];
|
|
|
|