sources/*: simplify source api

This commit is contained in:
Jens Langhammer
2021-02-08 10:15:59 +01:00
parent cd5631ec76
commit 3ced67b151
12 changed files with 85 additions and 57 deletions

View File

@ -7,6 +7,13 @@ export interface QueryArguments {
[key: string]: number | string | boolean | null;
}
export interface BaseInheritanceModel {
verbose_name: string;
verbose_name_plural: string;
}
export class Client {
makeUrl(url: string[], query?: QueryArguments): string {
let builtUrl = `/api/${VERSION}/${url.join("/")}/`;

View File

@ -1,12 +1,14 @@
import { DefaultClient, PBResponse, QueryArguments } from "./Client";
import { DefaultClient, BaseInheritanceModel, PBResponse, QueryArguments } from "./Client";
export class Policy {
export class Policy implements BaseInheritanceModel {
pk: string;
name: string;
constructor() {
throw Error();
}
verbose_name: string;
verbose_name_plural: string;
static get(pk: string): Promise<Policy> {
return DefaultClient.fetch<Policy>(["policies", "all", pk]);

View File

@ -1,6 +1,6 @@
import { DefaultClient, PBResponse, QueryArguments } from "./Client";
import { BaseInheritanceModel, DefaultClient, PBResponse, QueryArguments } from "./Client";
export class Provider {
export class Provider implements BaseInheritanceModel {
pk: number;
name: string;
authorization_flow: string;

View File

@ -1,6 +1,6 @@
import { DefaultClient, PBResponse, QueryArguments } from "./Client";
import { BaseInheritanceModel, DefaultClient, PBResponse, QueryArguments } from "./Client";
export class Source {
export class Source implements BaseInheritanceModel {
pk: string;
name: string;
slug: string;
@ -11,6 +11,8 @@ export class Source {
constructor() {
throw Error();
}
verbose_name: string;
verbose_name_plural: string;
static get(slug: string): Promise<Source> {
return DefaultClient.fetch<Source>(["sources", "all", slug]);
@ -19,4 +21,8 @@ export class Source {
static list(filter?: QueryArguments): Promise<PBResponse<Source>> {
return DefaultClient.fetch<PBResponse<Source>>(["sources", "all"], filter);
}
static adminUrl(rest: string): string {
return `/administration/sources/${rest}`;
}
}