From 4ab8770fbc0ecc8ecd55438b9f300307ae627ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovan=20Kruni=C4=87?= Date: Tue, 27 Jul 2021 11:11:45 +0200 Subject: [PATCH] refactor: every indexable thing can be a favorite --- src/meta.ts | 8 ++-- src/things/abstract/saveable-thing.ts | 6 +-- src/things/diff.ts | 5 +-- src/things/favorite.ts | 33 +++----------- src/things/setting.ts | 1 - test/resources/Favorite.json | 64 ++++++++++++++++++++++++--- test/schema.spec.ts | 2 +- 7 files changed, 72 insertions(+), 47 deletions(-) diff --git a/src/meta.ts b/src/meta.ts index 1258dcd4..ef157104 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -72,7 +72,7 @@ export const SCClasses: { [K in SCThingType]: object } = { 'video': SCVideoMeta, }; -export type SCThingsWithoutDiff = +export type SCIndexableThings = SCAcademicEvent | SCArticle | SCBook @@ -82,7 +82,6 @@ export type SCThingsWithoutDiff = | SCCourseOfStudies | SCDateSeries | SCDish - | SCFavorite | SCFloor | SCMessage | SCOrganization @@ -90,7 +89,6 @@ export type SCThingsWithoutDiff = | SCPointOfInterest | SCRoom | SCSemester - | SCSetting | SCSportCourse | SCStudyModule | SCTicket @@ -102,8 +100,8 @@ export type SCThingsWithoutDiff = * An object that exists in the StAppsCore */ export type SCThings = - SCThingsWithoutDiff - | SCDiff; + SCIndexableThings + | SCDiff | SCFavorite | SCSetting; /** * A field of a thing diff --git a/src/things/abstract/saveable-thing.ts b/src/things/abstract/saveable-thing.ts index 41c28dbe..67c90bb4 100644 --- a/src/things/abstract/saveable-thing.ts +++ b/src/things/abstract/saveable-thing.ts @@ -12,6 +12,7 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ +import {SCIndexableThings} from '../../meta'; import {SCThing, SCThingUserOrigin, SCThingWithoutReferences} from './thing'; /** @@ -19,18 +20,17 @@ import {SCThing, SCThingUserOrigin, SCThingWithoutReferences} from './thing'; */ export interface SCSaveableThingWithoutReferences extends SCThingWithoutReferences { - // noop } /** * An encapsulation of the data (e.g. a thing) that is saved, which provides additional information. */ -export interface SCSaveableThing +export interface SCSaveableThing extends SCSaveableThingWithoutReferences, SCThing { /** * The contained data */ - data: T; + data: SCIndexableThings; /** * Type of the origin */ diff --git a/src/things/diff.ts b/src/things/diff.ts index a7ea1bcf..1ee663f7 100644 --- a/src/things/diff.ts +++ b/src/things/diff.ts @@ -15,7 +15,7 @@ import * as jsonpatch from 'json-patch'; import {SCMetaTranslations} from '../general/i18n'; import {SCISO8601Date} from '../general/time'; -import {SCThingsWithoutDiff} from '../meta'; +import {SCIndexableThings} from '../meta'; import {SCThing, SCThingMeta, SCThingType, SCThingWithoutReferences} from './abstract/thing'; /** @@ -48,14 +48,13 @@ export interface SCDiffWithoutReferences * A diff * * @validatable - * @indexable */ export interface SCDiff extends SCDiffWithoutReferences, SCThing { /** * Original object the diff was generated on */ - object: SCThingsWithoutDiff; + object: SCIndexableThings; /** * Type of a diff diff --git a/src/things/favorite.ts b/src/things/favorite.ts index 1f2688be..ae38f5aa 100644 --- a/src/things/favorite.ts +++ b/src/things/favorite.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. @@ -14,45 +14,24 @@ */ import {SCSaveableThing, SCSaveableThingWithoutReferences} from './abstract/saveable-thing'; import {SCThingMeta, SCThingType} from './abstract/thing'; -import {SCAcademicEventWithoutReferences} from './academic-event'; -import {SCArticleWithoutReferences} from './article'; -import {SCBookWithoutReferences} from './book'; -import {SCBuildingWithoutReferences} from './building'; -import {SCPersonWithoutReferences} from './person'; -import {SCPointOfInterestWithoutReferences} from './point-of-interest'; -import {SCRoomWithoutReferences} from './room'; -import {SCSportCourseWithoutReferences} from './sport-course'; -import {SCToDoWithoutReferences} from './todo'; - -/** - * Types that can be made a favorite (added as a favorite) - */ -export type SCFavoriteDataTypes = SCAcademicEventWithoutReferences - | SCArticleWithoutReferences - | SCBookWithoutReferences - | SCBuildingWithoutReferences - | SCPersonWithoutReferences - | SCPointOfInterestWithoutReferences - | SCRoomWithoutReferences - | SCSportCourseWithoutReferences - | SCToDoWithoutReferences; /** * A favorite without references */ export interface SCFavoriteWithoutReferences extends SCSaveableThingWithoutReferences { - // noop + /** + * Type of a favorite + */ + type: SCThingType.Favorite; } /** * A favorite * * @validatable - * @indexable */ -export interface SCFavorite - extends SCSaveableThing, SCFavoriteWithoutReferences { +export interface SCFavorite extends SCSaveableThing { /** * Type of a favorite */ diff --git a/src/things/setting.ts b/src/things/setting.ts index 9212694a..304e1ae0 100644 --- a/src/things/setting.ts +++ b/src/things/setting.ts @@ -84,7 +84,6 @@ export enum SCSettingInputType { * A setting with references * * @validatable - * @indexable */ export interface SCSetting extends SCSettingWithoutReferences, SCThing, diff --git a/test/resources/Favorite.json b/test/resources/Favorite.json index 2302a62e..210b4551 100644 --- a/test/resources/Favorite.json +++ b/test/resources/Favorite.json @@ -6,17 +6,67 @@ "uid": "3af3ccaa-f066-5eff-9a3d-a70567f3d70d", "data": { "type": "academic event", - "description": "Grundlagen, algebraische Grundbegriffe, Vektorräume, lineare Abbildungen und Gleichungen, Determinanten", - "uid": "b17eb963-42b5-5861-adce-2b7b2607ef0a", - "name": "Lineare Algebra I für Mathematiker", + "description": "Fortsetzung der Algebra I: Galoistheorie mit Anwendungen, ausgewählte Spezialthemen.", + "uid": "681a59a1-23c2-5d78-861a-8c86a3abf2b9", + "name": "Algebra II", "categories": [ "lecture" ], + "academicTerms": [ + { + "uid": "aacd5611-b5be-54ce-b39f-c52f7e9a631d", + "type": "semester", + "name": "Sommersemester 2018", + "acronym": "SS 2018", + "alternateNames": [ + "SoSe 2018" + ], + "startDate": "2018-04-01", + "endDate": "2018-09-30", + "eventsStartDate": "2018-04-09", + "eventsEndDate": "2018-07-13" + } + ], + "performers": [ + { + "type": "person", + "uid": "7f8ce700-2679-51a5-86b5-3dfba85a33ff", + "givenName": "Peter", + "familyName": "Bürgisser", + "gender": "male", + "honorificPrefix": "Prof. Dr.", + "name": "Peter Bürgisser" + } + ], "majors": [ - "Wirtschaftsmathematik BSc", - "Technomathematik BSc", - "Mathematik BSc" - ] + "Mathematik D", + "Mathematik L2", + "Mathematik StRGym", + "Mathematik StRBeruf", + "Mathematik BSc", + "Mathematik MSc" + ], + "origin": { + "indexed": "2018-09-11T12:30:00Z", + "name": "Dummy", + "type": "remote", + "maintainer": { + "type": "organization", + "name": "tubIT", + "uid": "25f76840-db89-5da2-a8a2-75992f637613" + }, + "modified": "2018-09-01T10:00:00Z", + "originalId": "foo bar", + "responsibleEntity": { + "type": "person", + "uid": "7f8ce700-2679-51a5-86b5-3dfba85a33ff", + "givenName": "Peter", + "familyName": "Bürgisser", + "gender": "male", + "honorificPrefix": "Prof. Dr.", + "name": "Peter Bürgisser" + } + } }, "origin": { "created": "2018-09-11T12:30:00Z", diff --git a/test/schema.spec.ts b/test/schema.spec.ts index 58e5dad0..8e2a6968 100644 --- a/test/schema.spec.ts +++ b/test/schema.spec.ts @@ -121,7 +121,7 @@ export class SchemaSpec { } } - const thingsReflection = SchemaSpec.objects.SCThingsWithoutDiff; + const thingsReflection = SchemaSpec.objects.SCIndexableThings; // tslint:disable-next-line:no-unused-expression expect(thingsReflection).not.to.be.undefined;