src/*: use type daterange for timeframes

Instead of to and from, no type dataRange is used.
Type DateRange still has to and from.
pull/23/head
leonnicolas 4 years ago
parent 321dc72123
commit 0754fd5f74
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -183,10 +183,7 @@ export class LendingStationAPI extends DataSource {
async createTimeFrame (timeFrame: any) {
return await this.connection.transaction(async (entityManager: EntityManager) => {
if (timeFrame.to === undefined) {
timeFrame.to = '';
}
timeFrame.dateRange = '[' + timeFrame.from + ',' + timeFrame.to + ')';
genDateRange(timeFrame);
// checking for overlapping time frames
const overlapping = await entityManager.getRepository(TimeFrame)
.createQueryBuilder('timeframe')

@ -23,16 +23,15 @@ import { ActionLog, Actions } from '../../model/ActionLog';
import { UserInputError } from 'apollo-server-express';
export function genDateRange (struct: any) {
if (struct.to === undefined) {
struct.to = '';
}
struct.dateRange = '[' + struct.from + ',' + struct.to + ')';
if (struct.from === undefined) {
if (!struct.dateRange || !struct.dateRange.from) {
delete struct.dateRange;
return;
} else if (!struct.dateRange?.to) {
struct.dateRange.to = '';
} else if (struct.dateRange.to === struct.dateRange.from) {
throw new UserInputError('Date Range can not be empty, provide different dates.');
}
// delete these keys, so the struct can be used to update the engagement entity
delete struct.from;
delete struct.to;
struct.dateRange = '[' + struct.dateRange.from + ',' + struct.dateRange.to + ')';
}
/**

@ -104,14 +104,16 @@ export default {
return parent.loanTimes ? parent.loanTimes : [];
}
},
TimeFrame: {
DateRange: {
from (parent: any) {
return (parent.dateRange as string).split(',')[0].replace('[', '');
return (parent as string).split(',')[0].replace('[', '');
},
to (parent: any) {
const str = (parent.dateRange as string).split(',')[1].replace(')', '');
to (parent: string) {
const str = (parent as string).split(',')[1].replace(')', '');
return (str.length > 0) ? str : null;
},
}
},
TimeFrame: {
cargoBike (parent: any, __: any, { dataSources, req }: { dataSources: any, req: any }) {
if (req.permissions.includes(Permission.ReadBike)) {
return dataSources.cargoBikeAPI.cargoBikeByTimeFrameId(parent.id);

@ -935,13 +935,26 @@ export default gql`
loanTimes: [String!]
}
"(dt. Zeitscheibe) When was a bike where"
type TimeFrame {
id: ID!
"format YYYY-MM-dd"
type DateRange{
from: Date!
"will be infinity of not omitted"
to: Date
}
input DateRangeInput {
"format YYYY-MM-dd"
from: Date!
"""
format YYYY-MM-dd
will be infinity of not omitted
"""
to: Date
}
"(dt. Zeitscheibe) When was a bike where"
type TimeFrame {
id: ID!
dateRange: DateRange!
note: String
lendingStation: LendingStation!
cargoBike: CargoBike!
@ -953,8 +966,7 @@ export default gql`
}
input TimeFrameCreateInput {
from: Date!
to: Date
dateRange: DateRangeInput!
note: String
lendingStationId: ID!
cargoBikeId: ID!
@ -962,8 +974,7 @@ export default gql`
input TimeFrameUpdateInput {
id: ID!
from: Date
to: Date
dateRange: DateRangeInput
note: String
lendingStationId: ID
cargoBikeId: ID

Loading…
Cancel
Save