Added domain model, repo improvements
This commit is contained in:
parent
dcb0c014f2
commit
a018f01d2a
5 changed files with 61 additions and 1 deletions
2
.npmignore
Normal file
2
.npmignore
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
src/
|
||||||
|
!lib/**
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# oohost.js
|
||||||
|
|
||||||
|
TypeScript library for accessing the oohost API
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "oohost.js",
|
"name": "oohost.js",
|
||||||
"version": "0.0.5",
|
"version": "0.0.6",
|
||||||
"description": "TypeScript library for accessing the oohost API",
|
"description": "TypeScript library for accessing the oohost API",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "oohost.cz",
|
"author": "oohost.cz",
|
||||||
|
|
|
@ -2,4 +2,5 @@ export * from "./API";
|
||||||
export * from "./APIList";
|
export * from "./APIList";
|
||||||
export * from "./models/Base";
|
export * from "./models/Base";
|
||||||
export * from "./models/User";
|
export * from "./models/User";
|
||||||
|
export * from "./models/Domain";
|
||||||
export * from "./models/Certificate";
|
export * from "./models/Certificate";
|
||||||
|
|
54
src/models/Domain.ts
Normal file
54
src/models/Domain.ts
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import { API, Response } from "../API";
|
||||||
|
import { APIList } from "../APIList";
|
||||||
|
import { UserInclude } from "./User";
|
||||||
|
|
||||||
|
export class Domain {
|
||||||
|
|
||||||
|
public readonly selector: DomainSelector = {};
|
||||||
|
|
||||||
|
constructor(selector: string) {
|
||||||
|
let id = parseInt(selector);
|
||||||
|
if (Number.isInteger(id)) {
|
||||||
|
this.selector.id = id;
|
||||||
|
} else {
|
||||||
|
this.selector.domain = selector;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getDetails() {
|
||||||
|
let res = await API.get("domains/details", {...this.selector});
|
||||||
|
let details: DomainDetails | null = res.get().details ?? null;
|
||||||
|
return {details, res};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async remove(): Promise<Response> {
|
||||||
|
return await API.get("domains/remove", {...this.selector});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async add(domain: string) {
|
||||||
|
let res = await API.get("domains/add", {domain});
|
||||||
|
let id: number | null = res.success ? res.get().info.id : null;
|
||||||
|
return {id, res};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getList(): APIList<DomainListItem> {
|
||||||
|
return new APIList("domains/list");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DomainSelector {
|
||||||
|
id?: number,
|
||||||
|
domain?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DomainListItem {
|
||||||
|
id: number,
|
||||||
|
domain: string,
|
||||||
|
status: number,
|
||||||
|
created_at: string,
|
||||||
|
updated_at: string,
|
||||||
|
User: UserInclude
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DomainDetails = DomainListItem;
|
Loading…
Reference in a new issue