0
0
Fork 0
qnips-probeaufgabe/src/app/database-ha-interface.ts

150 lines
3.3 KiB
TypeScript

/*
* Ideally this interface would be generated by
* a schema provided for the endpoint.
*
* Because we don't have one, we manually write it,
* and create our own schema for validation purposes.
*/
export interface Allergen {
Id: string;
Label: string;
}
export interface Day {
Weekday: number;
/* NOTE
Property name is ProductIds,
but property is object containing the ID. */
ProductIds: { ProductId: number }[];
}
export interface Speiseplan {
Allergens: Record<string, Allergen>;
Products: Record<string, Product>;
Rows: Row[];
}
export interface Price {
Betrag: number;
}
export interface Product {
AllergenIds: string[];
ProductId: number;
Name: string;
Price: Price;
}
export interface Row {
Name: string;
Days: Day[];
}
export const emptySpeiseplan: Speiseplan = {
Allergens: {},
Products: {},
Rows: [],
};
Object.freeze(emptySpeiseplan);
export const speiseplanSchema = {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Speiseplan',
type: 'object',
properties: {
Allergens: {
type: 'object',
patternProperties: {
'\\d+_\\d*': {
type: 'object',
properties: {
Id: {
title: 'Allergen identifier',
type: 'string',
},
Label: {
title: 'Allergen label',
type: 'string',
},
},
required: ['Id', 'Label'],
},
},
},
Products: {
type: 'object',
patternProperties: {
'\\d+': {
properties: {
AllergenIds: {
type: 'array',
items: {
type: 'string',
},
uniqueItems: true,
},
ProductId: {
type: 'integer',
},
Name: {
title: 'Product name',
type: 'string',
},
Price: {
type: 'object',
properties: {
Betrag: {
title: 'Preis in Euro',
type: 'number',
minimum: 0,
},
},
required: ['Betrag'],
},
},
required: ['AllergenIds', 'ProductId', 'Name', 'Price'],
},
},
Rows: {
type: 'array',
items: {
type: 'object',
properties: {
Name: {
title: 'Category name',
type: 'string',
},
Days: {
type: 'array',
items: {
type: 'object',
properties: {
Weekday: {
type: 'integer',
minimum: 0,
maximum: 4,
},
ProductIds: {
type: 'object',
properties: {
ProductId: {
type: 'integer',
},
},
required: ['ProductId'],
},
},
required: ['Weekday', 'ProductIds'],
},
},
},
required: ['Name', 'Days'],
},
},
},
},
required: ['Allergens', 'Products', 'Rows'],
};
Object.freeze(speiseplanSchema);