sources/*: simplify source api
This commit is contained in:
@ -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("/")}/`;
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user