From 9c6972af787678567409877b6bc9f9417e1374e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wieland=20Sch=C3=B6bl?= Date: Mon, 3 May 2021 16:57:38 +0200 Subject: [PATCH] feat: change range offer to use date range add date range type change availability filter --- src/protocol/search/filters/availability.ts | 14 ++-- src/protocol/search/filters/range.ts | 11 +++- src/things/abstract/range.ts | 64 +++++++++++++++++++ .../abstract/thing-that-can-be-offered.ts | 13 ++-- test/resources/DateSeries.3.json | 6 +- test/resources/Dish.1.json | 6 +- test/resources/Dish.2.json | 6 +- test/resources/Dish.3.json | 6 +- test/resources/SearchRequest.1.json | 4 +- 9 files changed, 103 insertions(+), 27 deletions(-) create mode 100644 src/things/abstract/range.ts diff --git a/src/protocol/search/filters/availability.ts b/src/protocol/search/filters/availability.ts index 0c5145f8..1301c397 100644 --- a/src/protocol/search/filters/availability.ts +++ b/src/protocol/search/filters/availability.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 StApps + * Copyright (C) 2019-2021 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -33,17 +33,17 @@ export interface SCSearchAvailabilityFilter extends SCSearchAbstractFilter extends SCSearchAbstractFilterArgumen * Field where the filter will be applied */ field: SCThingsField; + + /** + * Relation when searching on other range fields + * + * Intersects (Default): Both search and field range intersect + * Within: Search range is within the field range + * Contains: Search range contains the field range + */ + relation?: 'intersects' | 'within' | 'contains'; } export interface Bounds { diff --git a/src/things/abstract/range.ts b/src/things/abstract/range.ts new file mode 100644 index 00000000..a1eb5b90 --- /dev/null +++ b/src/things/abstract/range.ts @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2021 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {SCISO8601Date} from '../../general/time'; + +/** + * Date Range + * + * CAUTION: Changing the name requires changes in the core-tools premaps + */ +export type SCISO8601DateRange = SCRange; + +/** + * Generic range type + */ +export type SCRange = { + /** + * Greater than value + */ + gt?: never; + + /** + * Greater or equal to value + */ + gte?: T; + + /** + * Greater than value + */ + lt?: never; + + /** + * Greater or equal to value + */ + lte?: T; +} | { + // tslint:disable:completed-docs + gt?: T; + gte?: never; + lt?: T; + lte?: never; +} | { + gt?: T; + gte?: never; + lt?: never; + lte?: T; +} | { + gt?: never; + gte?: T; + lt?: T; + lte?: never; + // tslint:enable:completed-docs +}; diff --git a/src/things/abstract/thing-that-can-be-offered.ts b/src/things/abstract/thing-that-can-be-offered.ts index 5912db3d..a7c6873b 100644 --- a/src/things/abstract/thing-that-can-be-offered.ts +++ b/src/things/abstract/thing-that-can-be-offered.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 StApps + * Copyright (C) 2019-2021 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -13,10 +13,10 @@ * this program. If not, see . */ import {SCMetaTranslations, SCTranslations} from '../../general/i18n'; -import {SCISO8601Date} from '../../general/time'; import {SCOrganizationWithoutReferences} from '../organization'; import {SCPersonWithoutReferences} from '../person'; import {SCInPlace} from './place'; +import {SCISO8601DateRange} from './range'; import {SCThing, SCThingMeta, SCThingTranslatableProperties, SCThingWithoutReferences} from './thing'; /** @@ -100,14 +100,9 @@ export interface SCThingThatCanBeOfferedOffer availability: SCThingThatCanBeOfferedAvailability; /** - * The time when the thing becomes unavailable as an SCISO8601Date formatted string. + * The time when the thing is available. */ - availabilityEnds?: SCISO8601Date; - - /** - * The time when the thing becomes available as an SCISO8601Date formatted string. - */ - availabilityStarts?: SCISO8601Date; + availabilityRange?: SCISO8601DateRange; /** * List of prices that are distinct for specific groups diff --git a/test/resources/DateSeries.3.json b/test/resources/DateSeries.3.json index f50b4f46..6a0191a9 100644 --- a/test/resources/DateSeries.3.json +++ b/test/resources/DateSeries.3.json @@ -43,8 +43,10 @@ "offers": [ { "availability": "in stock", - "availabilityStarts": "2017-01-30T00:00:00.000Z", - "availabilityEnds": "2017-01-30T23:59:59.999Z", + "availabilityRange": { + "gte": "2017-01-30T00:00:00.000Z", + "lte": "2017-01-30T23:59:59.999Z" + }, "prices": { "default": 6.5, "student": 5, diff --git a/test/resources/Dish.1.json b/test/resources/Dish.1.json index 94aefc40..a66298b9 100644 --- a/test/resources/Dish.1.json +++ b/test/resources/Dish.1.json @@ -19,8 +19,10 @@ "offers": [ { "availability": "in stock", - "availabilityStarts": "2017-01-30T00:00:00.000Z", - "availabilityEnds": "2017-01-30T23:59:59.999Z", + "availabilityRange": { + "gte": "2017-01-30T00:00:00.000Z", + "lte": "2017-01-30T23:59:59.999Z" + }, "prices": { "default": 4.85, "student": 2.85, diff --git a/test/resources/Dish.2.json b/test/resources/Dish.2.json index e647d8be..a79f20a0 100644 --- a/test/resources/Dish.2.json +++ b/test/resources/Dish.2.json @@ -20,8 +20,10 @@ "uid": "3b9b3df6-3a7a-58cc-922f-c7335c002634" }, "availability": "in stock", - "availabilityStarts": "2017-01-30T00:00:00.000Z", - "availabilityEnds": "2017-01-30T23:59:59.999Z", + "availabilityRange": { + "gte": "2017-01-30T00:00:00.000Z", + "lte": "2017-01-30T23:59:59.999Z" + }, "inPlace": { "geo": { "point": { diff --git a/test/resources/Dish.3.json b/test/resources/Dish.3.json index 8c06499c..ad4f0b50 100644 --- a/test/resources/Dish.3.json +++ b/test/resources/Dish.3.json @@ -11,9 +11,11 @@ ], "offers": [ { - "availabilityEnds": "2017-03-27T23:59:59.000Z", - "availabilityStarts": "2017-03-27T00:00:00.000Z", "availability": "in stock", + "availabilityRange": { + "gte": "2017-03-27T00:00:00.000Z", + "lte": "2017-03-27T23:59:59.000Z" + }, "inPlace": { "type": "room", "name": "Cafeteria LEVEL", diff --git a/test/resources/SearchRequest.1.json b/test/resources/SearchRequest.1.json index a4473e58..05cb4100 100644 --- a/test/resources/SearchRequest.1.json +++ b/test/resources/SearchRequest.1.json @@ -22,8 +22,8 @@ }, { "arguments": { - "fromField": "availabilityStarts", - "toField": "availabilityEnds", + "scope": "d", + "field": "availabilityRange", "time": "2018-01-15T04:13:00+00:00" }, "type": "availability"