add: webpage routes and models
This commit is contained in:
parent
6530543683
commit
cc2096a409
20 changed files with 482 additions and 0 deletions
15
src/clients/webpage.client.ts
Normal file
15
src/clients/webpage.client.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { BaseClient } from "./clientBase";
|
||||
|
||||
export class WebPageClient extends BaseClient {
|
||||
constructor({ serverAdress, webapiToken }: { serverAdress: string; webapiToken: string }) {
|
||||
super({ serverAdress, webapiToken });
|
||||
|
||||
this.setAccessToken(webapiToken);
|
||||
}
|
||||
|
||||
public refreshToken(): Promise<void> {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
reject("some error occured by Code 401");
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,6 +1,11 @@
|
|||
export { WebApiClient } from "./clients/webapi.client";
|
||||
export { WebPageClient } from "./clients/webpage.client";
|
||||
|
||||
export * as AdminRequests from "./requests/admin";
|
||||
export * as AdminModels from "./viewmodels/admin";
|
||||
export * as AdminTypes from "./types/admin";
|
||||
export * as AdminEnums from "./enums/admin";
|
||||
|
||||
export * as WebpageRequests from "./requests/webpage";
|
||||
export * as WebpageModels from "./viewmodels/webpage";
|
||||
export * as WebpageTypes from "./types/webpage";
|
||||
|
|
4
src/requests/webpage.ts
Normal file
4
src/requests/webpage.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export { default as ArticleRequests } from "./webpage/articleRequests";
|
||||
export { default as EventRequests } from "./webpage/eventRequests";
|
||||
export { default as OperationRequests } from "./webpage/operationRequests";
|
||||
export { default as VehicleRequests } from "./webpage/vehicleRequests";
|
31
src/requests/webpage/articleRequests.ts
Normal file
31
src/requests/webpage/articleRequests.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { AxiosResponse } from "axios";
|
||||
import { RequestDefinition, RequestData, ImplementsRequestInterface } from "../requestBase";
|
||||
import { BaseClient } from "../../clients/clientBase";
|
||||
import { Article } from "../../viewmodels/webpage/collection";
|
||||
|
||||
interface IArticleRequests {
|
||||
getArticles: RequestDefinition<void, void, Article[]>;
|
||||
getArticleById: RequestDefinition<{ id: string }, void, Article>;
|
||||
createArticle: RequestDefinition<void, Partial<Article>, string>;
|
||||
updateArticle: RequestDefinition<{ id: string }, Partial<Article>, void>;
|
||||
deleteArticle: RequestDefinition<{ id: string }, void, void>;
|
||||
}
|
||||
|
||||
@ImplementsRequestInterface<IArticleRequests>()
|
||||
export default abstract class ArticleRequests {
|
||||
static async getArticles({ http }: BaseClient): Promise<AxiosResponse<Article[], any>> {
|
||||
return await http.get("/articles");
|
||||
}
|
||||
static async getArticleById({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<Article, any>> {
|
||||
return await http.get(`/articles/${p.params.id}`);
|
||||
}
|
||||
static async createArticle({ http }: BaseClient, p: RequestData<void, Partial<Article>>): Promise<AxiosResponse<string, any>> {
|
||||
return await http.post("/articles", p.body);
|
||||
}
|
||||
static async updateArticle({ http }: BaseClient, p: RequestData<{ id: string }, Partial<Article>>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/articles/${p.params.id}`, p.body);
|
||||
}
|
||||
static async deleteArticle({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/articles/${p.params.id}`);
|
||||
}
|
||||
}
|
31
src/requests/webpage/eventRequests.ts
Normal file
31
src/requests/webpage/eventRequests.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { AxiosResponse } from "axios";
|
||||
import { RequestDefinition, RequestData, ImplementsRequestInterface } from "../requestBase";
|
||||
import { BaseClient } from "../../clients/clientBase";
|
||||
import { Event } from "../../viewmodels/webpage/collection";
|
||||
|
||||
interface IEventRequests {
|
||||
getEvents: RequestDefinition<void, void, Event[]>;
|
||||
getEventById: RequestDefinition<{ id: string }, void, Event>;
|
||||
createEvent: RequestDefinition<void, Partial<Event>, string>;
|
||||
updateEvent: RequestDefinition<{ id: string }, Partial<Event>, void>;
|
||||
deleteEvent: RequestDefinition<{ id: string }, void, void>;
|
||||
}
|
||||
|
||||
@ImplementsRequestInterface<IEventRequests>()
|
||||
export default abstract class EventRequests {
|
||||
static async getEvents({ http }: BaseClient): Promise<AxiosResponse<Event[], any>> {
|
||||
return await http.get("/events");
|
||||
}
|
||||
static async getEventById({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<Event, any>> {
|
||||
return await http.get(`/events/${p.params.id}`);
|
||||
}
|
||||
static async createEvent({ http }: BaseClient, p: RequestData<void, Partial<Event>>): Promise<AxiosResponse<string, any>> {
|
||||
return await http.post("/events", p.body);
|
||||
}
|
||||
static async updateEvent({ http }: BaseClient, p: RequestData<{ id: string }, Partial<Event>>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/events/${p.params.id}`, p.body);
|
||||
}
|
||||
static async deleteEvent({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/events/${p.params.id}`);
|
||||
}
|
||||
}
|
31
src/requests/webpage/operationRequests.ts
Normal file
31
src/requests/webpage/operationRequests.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { AxiosResponse } from "axios";
|
||||
import { RequestDefinition, RequestData, ImplementsRequestInterface } from "../requestBase";
|
||||
import { BaseClient } from "../../clients/clientBase";
|
||||
import { Operation } from "../../viewmodels/webpage/collection";
|
||||
|
||||
interface IOperationRequests {
|
||||
getOperations: RequestDefinition<void, void, Operation[]>;
|
||||
getOperationById: RequestDefinition<{ id: string }, void, Operation>;
|
||||
createOperation: RequestDefinition<void, Partial<Operation>, string>;
|
||||
updateOperation: RequestDefinition<{ id: string }, Partial<Operation>, void>;
|
||||
deleteOperation: RequestDefinition<{ id: string }, void, void>;
|
||||
}
|
||||
|
||||
@ImplementsRequestInterface<IOperationRequests>()
|
||||
export default abstract class OperationRequests {
|
||||
static async getOperations({ http }: BaseClient): Promise<AxiosResponse<Operation[], any>> {
|
||||
return await http.get("/operations");
|
||||
}
|
||||
static async getOperationById({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<Operation, any>> {
|
||||
return await http.get(`/operations/${p.params.id}`);
|
||||
}
|
||||
static async createOperation({ http }: BaseClient, p: RequestData<void, Partial<Operation>>): Promise<AxiosResponse<string, any>> {
|
||||
return await http.post("/operations", p.body);
|
||||
}
|
||||
static async updateOperation({ http }: BaseClient, p: RequestData<{ id: string }, Partial<Operation>>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/operations/${p.params.id}`, p.body);
|
||||
}
|
||||
static async deleteOperation({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/operations/${p.params.id}`);
|
||||
}
|
||||
}
|
31
src/requests/webpage/vehicleRequests.ts
Normal file
31
src/requests/webpage/vehicleRequests.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { AxiosResponse } from "axios";
|
||||
import { RequestDefinition, RequestData, ImplementsRequestInterface } from "../requestBase";
|
||||
import { BaseClient } from "../../clients/clientBase";
|
||||
import { Vehicle } from "../../viewmodels/webpage/collection";
|
||||
|
||||
interface IVehicleRequests {
|
||||
getVehicles: RequestDefinition<void, void, Vehicle[]>;
|
||||
getVehicleById: RequestDefinition<{ id: string }, void, Vehicle>;
|
||||
createVehicle: RequestDefinition<void, Partial<Vehicle>, string>;
|
||||
updateVehicle: RequestDefinition<{ id: string }, Partial<Vehicle>, void>;
|
||||
deleteVehicle: RequestDefinition<{ id: string }, void, void>;
|
||||
}
|
||||
|
||||
@ImplementsRequestInterface<IVehicleRequests>()
|
||||
export default abstract class VehicleRequests {
|
||||
static async getVehicles({ http }: BaseClient): Promise<AxiosResponse<Vehicle[], any>> {
|
||||
return await http.get("/vehicles");
|
||||
}
|
||||
static async getVehicleById({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<Vehicle, any>> {
|
||||
return await http.get(`/vehicles/${p.params.id}`);
|
||||
}
|
||||
static async createVehicle({ http }: BaseClient, p: RequestData<void, Partial<Vehicle>>): Promise<AxiosResponse<string, any>> {
|
||||
return await http.post("/vehicles", p.body);
|
||||
}
|
||||
static async updateVehicle({ http }: BaseClient, p: RequestData<{ id: string }, Partial<Vehicle>>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/vehicles/${p.params.id}`, p.body);
|
||||
}
|
||||
static async deleteVehicle({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<void, any>> {
|
||||
return await http.post(`/vehicles/${p.params.id}`);
|
||||
}
|
||||
}
|
2
src/types/webpage.ts
Normal file
2
src/types/webpage.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * as ComponentTypes from "./webpage/componentTypes";
|
||||
export * as TextTypes from "./webpage/textTypes";
|
42
src/types/webpage/componentTypes.ts
Normal file
42
src/types/webpage/componentTypes.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { List } from "postcss/lib/list";
|
||||
import {
|
||||
Spacer,
|
||||
Gallery,
|
||||
FullText,
|
||||
FullImage,
|
||||
DualColumnText,
|
||||
ColumnImageText,
|
||||
FileViewer,
|
||||
FileDownload,
|
||||
Embedding,
|
||||
Section,
|
||||
} from "../../viewmodels/webpage/component/dynamic-zone";
|
||||
import { EmphasiseArticle } from "../../viewmodels/webpage/component/shared";
|
||||
|
||||
export type ComponentNames =
|
||||
| "shared.list"
|
||||
| "shared.emphasise-article"
|
||||
| "dynamic-zone.section"
|
||||
| "dynamic-zone.spacer"
|
||||
| "dynamic-zone.gallery"
|
||||
| "dynamic-zone.full-text"
|
||||
| "dynamic-zone.full-image"
|
||||
| "dynamic-zone.dual-column-text"
|
||||
| "dynamic-zone.column-image-text"
|
||||
| "dynamic-zone.file-viewer"
|
||||
| "dynamic-zone.file-download"
|
||||
| "dynamic-zone.embedding";
|
||||
|
||||
export type ComponentTypes =
|
||||
| List
|
||||
| EmphasiseArticle
|
||||
| Section
|
||||
| Spacer
|
||||
| Gallery
|
||||
| FullText
|
||||
| FullImage
|
||||
| DualColumnText
|
||||
| ColumnImageText
|
||||
| FileViewer
|
||||
| FileDownload
|
||||
| Embedding;
|
10
src/types/webpage/textTypes.ts
Normal file
10
src/types/webpage/textTypes.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
export type TypeField = TextField | { type: "link"; url: string; children: Array<TextField> };
|
||||
|
||||
export type TextField = {
|
||||
type: "text";
|
||||
text: string;
|
||||
strikethrough?: boolean;
|
||||
underline?: boolean;
|
||||
italic?: boolean;
|
||||
bold?: boolean;
|
||||
};
|
4
src/viewmodels/webpage.ts
Normal file
4
src/viewmodels/webpage.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export * as CollectionModels from "./webpage/collection";
|
||||
export * as ComponentModels from "./webpage/component";
|
||||
export * as FieldModels from "./webpage/field";
|
||||
export * as SingleModels from "./webpage/single";
|
59
src/viewmodels/webpage/collection.ts
Normal file
59
src/viewmodels/webpage/collection.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
import { ComponentTypes } from "../../types/webpage/componentTypes";
|
||||
import { File } from "./component/base";
|
||||
import { Hero } from "./component/items";
|
||||
import { ContentField } from "./field";
|
||||
|
||||
export interface BaseCollection {
|
||||
id: number;
|
||||
documentId: string;
|
||||
slug: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
publishedAt: string;
|
||||
locale: string;
|
||||
|
||||
title: string;
|
||||
description: string;
|
||||
date: string;
|
||||
content: ContentField | undefined;
|
||||
image: File | undefined;
|
||||
attachment: Array<File>;
|
||||
}
|
||||
|
||||
export interface Article extends BaseCollection {}
|
||||
|
||||
export interface Event extends BaseCollection {}
|
||||
|
||||
export interface Operation extends BaseCollection {}
|
||||
|
||||
export interface Vehicle extends BaseCollection {}
|
||||
|
||||
export interface Lookup {
|
||||
id: number;
|
||||
documentId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
publishedAt: string;
|
||||
|
||||
reference: string;
|
||||
collection: "events" | "vehicles" | "articles" | "operations";
|
||||
show_image: boolean;
|
||||
show_date: boolean;
|
||||
list_with_date: "none" | "by-year" | "by-month";
|
||||
items_with_number: "none" | "numbered" | "inverted";
|
||||
enable_detail: boolean;
|
||||
}
|
||||
|
||||
export interface Page {
|
||||
id: number;
|
||||
documentId: string;
|
||||
identifier: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
publishedAt: string;
|
||||
locale: string;
|
||||
slug: string;
|
||||
hero: Hero;
|
||||
content: Array<ComponentTypes>;
|
||||
localizations: any[];
|
||||
}
|
5
src/viewmodels/webpage/component.ts
Normal file
5
src/viewmodels/webpage/component.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
export * as BaseModels from "./component/base";
|
||||
export * as DaynamicZoneModels from "./component/dynamic-zone";
|
||||
export * as GlobalModels from "./component/global";
|
||||
export * as ItemsModels from "./component/items";
|
||||
export * as SharedModels from "./component/shared";
|
41
src/viewmodels/webpage/component/base.ts
Normal file
41
src/viewmodels/webpage/component/base.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { ComponentNames } from "../../../types/webpage/componentTypes";
|
||||
|
||||
export interface Component {
|
||||
__component: ComponentNames;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export interface File {
|
||||
id: number;
|
||||
documentId: string;
|
||||
name: string;
|
||||
alternativeText: string | null;
|
||||
caption: string | null;
|
||||
width: number;
|
||||
height: number;
|
||||
formats: Record<string, ImageFormat> | null;
|
||||
hash: string;
|
||||
ext: string;
|
||||
mime: string;
|
||||
size: number;
|
||||
url: string;
|
||||
previewUrl: string | null;
|
||||
provider: string;
|
||||
provider_metadata: any;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
publishedAt: string;
|
||||
}
|
||||
|
||||
export interface ImageFormat {
|
||||
name: string;
|
||||
hash: string;
|
||||
ext: string;
|
||||
mime: string;
|
||||
path: string | null;
|
||||
width: number;
|
||||
height: number;
|
||||
size: number;
|
||||
sizeInBytes: number;
|
||||
url: string;
|
||||
}
|
55
src/viewmodels/webpage/component/dynamic-zone.ts
Normal file
55
src/viewmodels/webpage/component/dynamic-zone.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { ContentField } from "../field";
|
||||
import { File, Component } from "./base";
|
||||
|
||||
export interface ColumnImageText extends Component {
|
||||
__component: "dynamic-zone.column-image-text";
|
||||
text: ContentField;
|
||||
image_left: boolean;
|
||||
image: File;
|
||||
}
|
||||
|
||||
export interface DualColumnText extends Component {
|
||||
__component: "dynamic-zone.dual-column-text";
|
||||
left_side: ContentField;
|
||||
right_side: ContentField;
|
||||
}
|
||||
|
||||
export interface Embedding extends Component {
|
||||
__component: "dynamic-zone.embedding";
|
||||
link: string;
|
||||
}
|
||||
|
||||
export interface FileDownload extends Component {
|
||||
__component: "dynamic-zone.file-download";
|
||||
file: File;
|
||||
}
|
||||
|
||||
export interface FileViewer extends Component {
|
||||
__component: "dynamic-zone.file-viewer";
|
||||
file: File;
|
||||
}
|
||||
|
||||
export interface FullImage extends Component {
|
||||
__component: "dynamic-zone.full-image";
|
||||
image: File;
|
||||
}
|
||||
|
||||
export interface FullText extends Component {
|
||||
__component: "dynamic-zone.full-text";
|
||||
text: ContentField;
|
||||
}
|
||||
|
||||
export interface Gallery extends Component {
|
||||
__component: "dynamic-zone.gallery";
|
||||
images: Array<File>;
|
||||
}
|
||||
|
||||
export interface Section extends Component {
|
||||
__component: "dynamic-zone.section";
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface Spacer extends Component {
|
||||
__component: "dynamic-zone.spacer";
|
||||
}
|
19
src/viewmodels/webpage/component/global.ts
Normal file
19
src/viewmodels/webpage/component/global.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { NavbarItem, FooterLink } from "./items";
|
||||
|
||||
export interface SEO {
|
||||
metaTitle: string;
|
||||
metaDescription: string;
|
||||
keywords: string;
|
||||
}
|
||||
|
||||
export interface Navbar {
|
||||
id: number;
|
||||
navbar_items: NavbarItem[];
|
||||
}
|
||||
|
||||
export interface Footer {
|
||||
id: number;
|
||||
copyright: undefined | string;
|
||||
maintained_by: undefined | string;
|
||||
links: FooterLink[];
|
||||
}
|
37
src/viewmodels/webpage/component/items.ts
Normal file
37
src/viewmodels/webpage/component/items.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Page } from "../collection";
|
||||
import { File } from "./base";
|
||||
|
||||
export interface FooterLink {
|
||||
id: number;
|
||||
text: string;
|
||||
URL: string;
|
||||
target: string;
|
||||
}
|
||||
|
||||
export interface Hero {
|
||||
id: number;
|
||||
title: string | undefined;
|
||||
banner: File | undefined;
|
||||
}
|
||||
|
||||
export interface Link {
|
||||
text: string;
|
||||
URL: string;
|
||||
target: "_blank" | "_self" | "_parent" | "_top";
|
||||
}
|
||||
|
||||
export interface NavbarItem {
|
||||
id: number;
|
||||
name: string;
|
||||
URL: string;
|
||||
default_active_child: string;
|
||||
page: any;
|
||||
navbar_sub_items: NavbarSubItem[];
|
||||
}
|
||||
|
||||
export interface NavbarSubItem {
|
||||
id: number;
|
||||
name: string;
|
||||
URL: string;
|
||||
page: Page | null;
|
||||
}
|
13
src/viewmodels/webpage/component/shared.ts
Normal file
13
src/viewmodels/webpage/component/shared.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Article, Lookup } from "../collection";
|
||||
import { Component } from "./base";
|
||||
|
||||
export interface List extends Component {
|
||||
__component: "shared.list";
|
||||
lookup: Lookup;
|
||||
}
|
||||
|
||||
export interface EmphasiseArticle extends Component {
|
||||
__component: "shared.emphasise-article";
|
||||
articles: Array<Article>;
|
||||
link_to_articles: string;
|
||||
}
|
20
src/viewmodels/webpage/field.ts
Normal file
20
src/viewmodels/webpage/field.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { TextField, TypeField } from "../../types/webpage/textTypes";
|
||||
|
||||
export interface ContentField
|
||||
extends Array<
|
||||
| {
|
||||
type: "paragraph" | "heading" | "quote";
|
||||
children: Array<TypeField>;
|
||||
level?: number;
|
||||
}
|
||||
| {
|
||||
type: "list";
|
||||
format: "unordered" | "ordered";
|
||||
children: Array<{ type: "list-item"; children: Array<TypeField> }>;
|
||||
}
|
||||
| {
|
||||
type: "code";
|
||||
children: Array<TextField>;
|
||||
language: "plaintext";
|
||||
}
|
||||
> {}
|
27
src/viewmodels/webpage/single.ts
Normal file
27
src/viewmodels/webpage/single.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { ComponentTypes } from "../../types/webpage/componentTypes";
|
||||
import { File } from "./component/base";
|
||||
import { Navbar, Footer, SEO } from "./component/global";
|
||||
|
||||
export interface Global {
|
||||
id: number;
|
||||
documentId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
publishedAt: string;
|
||||
locale: string;
|
||||
logo: File;
|
||||
navbar: Navbar | undefined;
|
||||
footer: Footer | undefined;
|
||||
SEO: SEO | undefined;
|
||||
}
|
||||
|
||||
export interface Homepage {
|
||||
id: number;
|
||||
documentId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
publishedAt: string;
|
||||
locale: string;
|
||||
backdrop: undefined | File;
|
||||
content: Array<ComponentTypes>;
|
||||
}
|
Loading…
Add table
Reference in a new issue