feat: make SCContactPoint extend SCThing

Refactor SCPerson and SCOrganization
This commit is contained in:
Rainer Killinger
2019-08-06 13:02:07 +02:00
parent 5de523a4bf
commit 0d89b14932
10 changed files with 279 additions and 141 deletions

View File

@@ -18,6 +18,7 @@ import {SCArticle, SCArticleMeta, SCArticleWithoutReferences} from './things/art
import {SCBook, SCBookMeta, SCBookWithoutReferences} from './things/book';
import {SCBuilding, SCBuildingMeta, SCBuildingWithoutReferences} from './things/building';
import {SCCatalog, SCCatalogMeta, SCCatalogWithoutReferences} from './things/catalog';
import {SCContactPoint, SCContactPointMeta, SCContactPointWithoutReferences} from './things/contact-point';
import {SCCourseOfStudies, SCCourseOfStudiesMeta, SCCourseOfStudiesWithoutReferences} from './things/course-of-studies';
import {SCDateSeries, SCDateSeriesMeta, SCDateSeriesWithoutReferences} from './things/date-series';
import {SCDiff, SCDiffMeta, SCDiffWithoutReferences} from './things/diff';
@@ -49,6 +50,7 @@ export const SCClasses: { [K in SCThingType]: object } = {
'book': SCBookMeta,
'building': SCBuildingMeta,
'catalog': SCCatalogMeta,
'contact point': SCContactPointMeta,
'course of studies': SCCourseOfStudiesMeta,
'date series': SCDateSeriesMeta,
'diff': SCDiffMeta,
@@ -76,6 +78,7 @@ export type SCThingsWithoutDiff =
| SCBook
| SCBuilding
| SCCatalog
| SCContactPoint
| SCCourseOfStudies
| SCDateSeries
| SCDish
@@ -116,26 +119,27 @@ export type SCAssociatedThingWithoutReferences<THING extends SCThings> =
THING extends SCBook ? SCBookWithoutReferences :
THING extends SCBuilding ? SCBuildingWithoutReferences :
THING extends SCCatalog ? SCCatalogWithoutReferences :
THING extends SCCourseOfStudies ? SCCourseOfStudiesWithoutReferences :
THING extends SCDateSeries ? SCDateSeriesWithoutReferences :
THING extends SCDiff ? SCDiffWithoutReferences :
THING extends SCDish ? SCDishWithoutReferences :
THING extends SCFavorite ? SCFavoriteWithoutReferences :
THING extends SCFloor ? SCFloorWithoutReferences :
THING extends SCMessage ? SCMessageWithoutReferences :
THING extends SCOrganization ? SCOrganizationWithoutReferences :
THING extends SCPerson ? SCPersonWithoutReferences :
THING extends SCPointOfInterest ? SCPointOfInterestWithoutReferences :
THING extends SCRoom ? SCRoomWithoutReferences :
THING extends SCSemester ? SCSemesterWithoutReferences :
THING extends SCSetting ? SCSettingWithoutReferences :
THING extends SCSportCourse ? SCSportCourseWithoutReferences :
THING extends SCStudyModule ? SCStudyModuleWithoutReferences :
THING extends SCTicket ? SCTicketWithoutReferences :
THING extends SCToDo ? SCToDoWithoutReferences :
THING extends SCTour ? SCTourWithoutReferences :
THING extends SCVideo ? SCVideoWithoutReferences :
never;
THING extends SCContactPoint ? SCContactPointWithoutReferences :
THING extends SCCourseOfStudies ? SCCourseOfStudiesWithoutReferences :
THING extends SCDateSeries ? SCDateSeriesWithoutReferences :
THING extends SCDiff ? SCDiffWithoutReferences :
THING extends SCDish ? SCDishWithoutReferences :
THING extends SCFavorite ? SCFavoriteWithoutReferences :
THING extends SCFloor ? SCFloorWithoutReferences :
THING extends SCMessage ? SCMessageWithoutReferences :
THING extends SCOrganization ? SCOrganizationWithoutReferences :
THING extends SCPerson ? SCPersonWithoutReferences :
THING extends SCPointOfInterest ? SCPointOfInterestWithoutReferences :
THING extends SCRoom ? SCRoomWithoutReferences :
THING extends SCSemester ? SCSemesterWithoutReferences :
THING extends SCSetting ? SCSettingWithoutReferences :
THING extends SCSportCourse ? SCSportCourseWithoutReferences :
THING extends SCStudyModule ? SCStudyModuleWithoutReferences :
THING extends SCTicket ? SCTicketWithoutReferences :
THING extends SCToDo ? SCToDoWithoutReferences :
THING extends SCTour ? SCTourWithoutReferences :
THING extends SCVideo ? SCVideoWithoutReferences :
never;
/**
* Thing for a thing without references
@@ -146,23 +150,24 @@ export type SCAssociatedThing<THING extends SCThings> =
THING extends SCBookWithoutReferences ? SCBook :
THING extends SCBuildingWithoutReferences ? SCBuilding :
THING extends SCCatalogWithoutReferences ? SCCatalog :
THING extends SCCourseOfStudiesWithoutReferences ? SCCourseOfStudies :
THING extends SCDateSeriesWithoutReferences ? SCDateSeries :
THING extends SCDiffWithoutReferences ? SCDiff :
THING extends SCDishWithoutReferences ? SCDish :
THING extends SCFavoriteWithoutReferences ? SCFavorite :
THING extends SCFloorWithoutReferences ? SCFloor :
THING extends SCMessageWithoutReferences ? SCMessage :
THING extends SCOrganizationWithoutReferences ? SCOrganization :
THING extends SCPersonWithoutReferences ? SCPerson :
THING extends SCPointOfInterestWithoutReferences ? SCPointOfInterest :
THING extends SCRoomWithoutReferences ? SCRoom :
THING extends SCSemesterWithoutReferences ? SCSemester :
THING extends SCSettingWithoutReferences ? SCSetting :
THING extends SCSportCourseWithoutReferences ? SCSportCourse :
THING extends SCStudyModuleWithoutReferences ? SCStudyModule :
THING extends SCTicketWithoutReferences ? SCTicket :
THING extends SCToDoWithoutReferences ? SCToDo :
THING extends SCTourWithoutReferences ? SCTour :
THING extends SCVideoWithoutReferences ? SCVideo :
never;
THING extends SCContactPointWithoutReferences ? SCContactPoint :
THING extends SCCourseOfStudiesWithoutReferences ? SCCourseOfStudies :
THING extends SCDateSeriesWithoutReferences ? SCDateSeries :
THING extends SCDiffWithoutReferences ? SCDiff :
THING extends SCDishWithoutReferences ? SCDish :
THING extends SCFavoriteWithoutReferences ? SCFavorite :
THING extends SCFloorWithoutReferences ? SCFloor :
THING extends SCMessageWithoutReferences ? SCMessage :
THING extends SCOrganizationWithoutReferences ? SCOrganization :
THING extends SCPersonWithoutReferences ? SCPerson :
THING extends SCPointOfInterestWithoutReferences ? SCPointOfInterest :
THING extends SCRoomWithoutReferences ? SCRoom :
THING extends SCSemesterWithoutReferences ? SCSemester :
THING extends SCSettingWithoutReferences ? SCSetting :
THING extends SCSportCourseWithoutReferences ? SCSportCourse :
THING extends SCStudyModuleWithoutReferences ? SCStudyModule :
THING extends SCTicketWithoutReferences ? SCTicket :
THING extends SCToDoWithoutReferences ? SCToDo :
THING extends SCTourWithoutReferences ? SCTour :
THING extends SCVideoWithoutReferences ? SCVideo :
never;

View File

@@ -27,6 +27,7 @@ export enum SCThingType {
Book = 'book',
Building = 'building',
Catalog = 'catalog',
ContactPoint = 'contact point',
CourseOfStudies = 'course of studies',
DateSeries = 'date series',
Diff = 'diff',

136
src/things/contact-point.ts Normal file
View File

@@ -0,0 +1,136 @@
/*
* Copyright (C) 2019 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 <https://www.gnu.org/licenses/>.
*/
import {SCMetaTranslations} from '../general/i18n';
import {
SCThing,
SCThingMeta,
SCThingType,
SCThingWithoutReferences,
} from './abstract/thing';
import {SCRoomWithoutReferences} from './room';
/**
* A contact point without references
*/
export interface SCContactPointWithoutReferences
extends SCThingWithoutReferences {
/**
* E-mail at the work location
*
* @keyword
*/
email?: string;
/**
* Fax number at the work location
*
* @keyword
*/
faxNumber?: string;
/**
* Office hours for contacting someone at the work location
*
* @see http://wiki.openstreetmap.org/wiki/Key:opening_hours/specification
* @keyword
*/
officeHours?: string;
/**
* Contact number at the work location
*
* @keyword
*/
telephone?: string;
/**
* Type of a contact point
*/
type: SCThingType.ContactPoint;
/**
* URL at the work location
*
* @keyword
*/
url?: string;
}
/**
* A contact point
*
* @see http://schema.org/ContactPoint
*
* @validatable
* @indexable
*/
export interface SCContactPoint
extends SCContactPointWithoutReferences, SCThing {
/**
* Exact place where work is performed
*/
areaServed?: SCRoomWithoutReferences;
/**
* Type of a contact point
*/
type: SCThingType.ContactPoint;
}
/**
* Meta information about a contact point
*/
export class SCContactPointMeta
extends SCThingMeta
implements SCMetaTranslations<SCContactPoint> {
/**
* Translations of fields
*/
fieldTranslations = {
de: {
...SCThingMeta.getInstance<SCThingMeta>().fieldTranslations.de,
areaServed: 'Arbeitsraum',
email: 'E-Mail-Addresse',
faxNumber: 'Faxnummer',
officeHours: 'Sprechzeiten',
telephone: 'Telefonnummer',
url: 'Link',
},
en: {
...SCThingMeta.getInstance<SCThingMeta>().fieldTranslations.en,
areaServed: 'location',
email: 'email address',
faxNumber: 'fax number',
officeHours: 'office hours',
telephone: 'telephone number',
url: 'link',
},
};
/**
* Translations of values of fields
*/
fieldValueTranslations = {
de: {
...SCThingMeta.getInstance<SCThingMeta>().fieldValueTranslations.de,
type: 'Kontaktinformation',
},
en: {
...SCThingMeta.getInstance<SCThingMeta>().fieldValueTranslations.en,
type: SCThingType.ContactPoint,
},
};
}

View File

@@ -15,6 +15,7 @@
import {SCMetaTranslations} from '../general/i18n';
import {SCThingMeta, SCThingType, SCThingWithoutReferences} from './abstract/thing';
import {SCThingInPlace, SCThingInPlaceMeta} from './abstract/thing-in-place';
import {SCContactPointWithoutReferences} from './contact-point';
/**
* An organization without references
@@ -35,6 +36,11 @@ export interface SCOrganizationWithoutReferences
*/
export interface SCOrganization
extends SCOrganizationWithoutReferences, SCThingInPlace {
/**
* A list of contact points concerning the organization
*/
contactPoints?: SCContactPointWithoutReferences[];
/**
* Type of an organization
*/
@@ -52,9 +58,11 @@ export class SCOrganizationMeta
fieldTranslations = {
de: {
...SCThingInPlaceMeta.getInstance<SCThingInPlaceMeta>().fieldTranslations.de,
contactPoints: 'Kontaktinformationen',
},
en: {
...SCThingInPlaceMeta.getInstance<SCThingInPlaceMeta>().fieldTranslations.en,
contactPoints: 'contact details',
},
};

View File

@@ -16,6 +16,7 @@ import {SCMetaTranslations, SCNationality} from '../general/i18n';
import {SCISO8601Date} from '../general/time';
import {SCThing, SCThingMeta, SCThingType, SCThingWithoutReferences} from './abstract/thing';
import {SCBuildingWithoutReferences} from './building';
import {SCContactPointWithoutReferences} from './contact-point';
import {SCOrganizationWithoutReferences} from './organization';
import {SCPointOfInterestWithoutReferences} from './point-of-interest';
import {SCRoomWithoutReferences} from './room';
@@ -159,7 +160,7 @@ export interface SCPerson
/**
* Locations where the person performs her/his work
*/
workLocations?: SCContactPoint[];
workLocations?: SCContactPointWithoutReferences[];
}
/**
@@ -188,13 +189,14 @@ export class SCPersonMeta
jobTitles: 'Berufsbezeichnungen',
nationality: 'Staatsangehörigkeit',
telephone: 'Telefonnummer',
workLocations: 'Arbeitsorte',
workLocations: 'Arbeitsstandorte',
},
en: {
...SCThingMeta.getInstance<SCThingMeta>().fieldTranslations.en,
additionalName: 'additional name',
affiliations: 'affiliations',
birthDate: 'birth date',
contactDetails: 'contact details',
email: 'email',
familyName: 'family name',
faxNumber: 'fax',
@@ -231,53 +233,6 @@ export class SCPersonMeta
};
}
/**
* A contact point
*
* @see http://schema.org/ContactPoint
*/
export interface SCContactPoint {
/**
* Exact place where work is performed
*/
areaServed?: SCRoomWithoutReferences;
/**
* E-mail at the work location
*
* @keyword
*/
email?: string;
/**
* Fax number at the work location
*
* @keyword
*/
faxNumber?: string;
/**
* Times available for contacting at the work location
*
* @keyword
*/
hoursAvailable?: string;
/**
* Contact number at the work location
*
* @keyword
*/
telephone?: string;
/**
* URL at the work location
*
* @keyword
*/
url?: string;
}
/**
* Gender of a person
*/

View File

@@ -0,0 +1,39 @@
{
"errorNames": [],
"instance": {
"type": "contact point",
"name": "Dienstadresse",
"areaServed": {
"type": "room",
"categories": [
"education"
],
"uid": "39c1a574-04ef-5157-9c6f-e271d93eb273",
"name": "3.G 121",
"alternateNames": [
"Dienstzimmer"
],
"geo": {
"point": {
"coordinates": [
8.66919,
50.12834
],
"type": "Point"
}
}
},
"email": "info@example.com",
"faxNumber": "069 / 123450",
"officeHours": "Mo, Mi 8:00-13:00",
"telephone": "069 / 12345",
"url": "https://example.com",
"uid": "be34a419-e9e8-5de0-b998-dd1b19e7beef",
"origin": {
"indexed": "2018-09-11T12:30:00Z",
"name": "Dummy",
"type": "remote"
}
},
"schema": "SCContactPoint"
}

View File

@@ -0,0 +1,26 @@
{
"errorNames": [],
"instance": {
"type": "organization",
"uid": "20e48393-0d2b-5bdc-9d92-5e0dc1e2860f",
"contactPoints": [
{
"type": "contact point",
"name": "Dienstadresse",
"email": "info@example.com",
"faxNumber": "069 / 123450",
"officeHours": "Mo, Mi 8:00-13:00",
"telephone": "069 / 12345",
"url": "https://example.com",
"uid": "be34a419-e9e8-5de0-b998-dd1b19e7beef"
}
],
"name": "Technische Universität Berlin",
"origin": {
"indexed": "2018-09-11T12:30:00Z",
"name": "Dummy",
"type": "remote"
}
},
"schema": "SCOrganization"
}

View File

@@ -17,58 +17,14 @@
"uid": "be34a419-e9e8-5de0-b998-dd1b19e7f451",
"workLocations": [
{
"url": "http://www.fb03.uni-frankfurt.de/1234567",
"email": "mustermann@soz.uni-frankfurt.de",
"faxNumber": "",
"telephone": "069/123-36232; -1324325",
"hoursAvailable": "siehe Homepage",
"areaServed": {
"type": "room",
"categories": [
"education"
],
"uid": "39c1a574-04ef-5157-9c6f-e271d93eb273",
"name": "3.G 121",
"alternateNames": [
"Dienstzimmer"
],
"geo": {
"point": {
"coordinates": [
8.66919,
50.12834
],
"type": "Point"
}
}
}
},
{
"url": "http://www2.uni-frankfurt.de/12345/vizepraesidenten",
"email": "",
"faxNumber": "",
"telephone": "069/123-1235",
"hoursAvailable": "siehe Homepage",
"areaServed": {
"type": "room",
"categories": [
"education"
],
"uid": "5e54aefd-078b-5007-bca1-53dc60f79d37",
"name": "4.P 22",
"alternateNames": [
"Dienstzimmer"
],
"geo": {
"point": {
"coordinates": [
8.66898,
50.12772
],
"type": "Point"
}
}
}
"type": "contact point",
"name": "Dienstadresse",
"email": "info@example.com",
"faxNumber": "069 / 123450",
"officeHours": "Mo, Mi 8:00-13:00",
"telephone": "069 / 12345",
"url": "https://example.com",
"uid": "be34a419-e9e8-5de0-b998-dd1b19e7beef"
}
],
"origin": {

View File

@@ -19,6 +19,7 @@ import {SCArticle, SCArticleWithoutReferences} from '../src/things/article';
import {SCBook, SCBookWithoutReferences} from '../src/things/book';
import {SCBuilding, SCBuildingWithoutReferences} from '../src/things/building';
import {SCCatalog, SCCatalogWithoutReferences} from '../src/things/catalog';
import {SCContactPoint, SCContactPointWithoutReferences} from '../src/things/contact-point';
import {SCCourseOfStudies, SCCourseOfStudiesWithoutReferences} from '../src/things/course-of-studies';
import {SCDateSeries, SCDateSeriesWithoutReferences} from '../src/things/date-series';
import {SCDiff, SCDiffWithoutReferences} from '../src/things/diff';
@@ -126,6 +127,17 @@ assert<Has<SCBuildingPropertyTypes, SCThing>>(false);
assert<Extends<SCBuildingWithoutReferences, SCThing>>(false);
assert<Extends<SCBuilding, SCThing>>(true);
/**
* Types of properties of SCContactPoint
*/
type SCContactPointPropertyTypes = PropertyTypesNested<SCContactPoint>;
assert<NotHas<SCContactPointPropertyTypes, SCThingWithoutReferences>>(false);
assert<Has<SCContactPointPropertyTypes, SCThingWithoutReferences>>(true);
assert<NotHas<SCContactPointPropertyTypes, SCThing>>(true);
assert<Has<SCContactPointPropertyTypes, SCThing>>(false);
assert<Extends<SCContactPointWithoutReferences, SCThing>>(false);
assert<Extends<SCContactPoint, SCThing>>(true);
/**
* Types of properties of SCCatalog
*/