94 lines
2.3 KiB
TypeScript
94 lines
2.3 KiB
TypeScript
import { Document } from "le-coffre-resources/dist/Customer";
|
|
|
|
import BaseCustomer from "../BaseCustomer";
|
|
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
|
|
|
|
// TODO Type get query params -> Where + inclue + orderby
|
|
export interface IGetDocumentsparams {
|
|
where?: {};
|
|
include?: {};
|
|
}
|
|
|
|
// TODO Type getbyuid query params
|
|
|
|
export type IPutDocumentsParams = {
|
|
document_status?: EDocumentStatus;
|
|
refused_reason?: string;
|
|
};
|
|
|
|
export interface IPostDocumentsParams {}
|
|
|
|
export default class Documents extends BaseCustomer {
|
|
private static instance: Documents;
|
|
private readonly baseURl = this.namespaceUrl.concat("/documents");
|
|
|
|
private constructor() {
|
|
super();
|
|
}
|
|
|
|
public static getInstance() {
|
|
if (!this.instance) {
|
|
return new this();
|
|
} else {
|
|
return this.instance;
|
|
}
|
|
}
|
|
|
|
public async get(q: IGetDocumentsparams): Promise<Document[]> {
|
|
const url = new URL(this.baseURl);
|
|
const query = { q };
|
|
if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
|
try {
|
|
return await this.getRequest<Document[]>(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @description : Create a Document
|
|
*/
|
|
public async post(body: any): Promise<Document> {
|
|
const url = new URL(this.baseURl);
|
|
try {
|
|
return await this.postRequest<Document>(url, body);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
public async getByUid(uid: string, q?: any): Promise<Document> {
|
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
|
const query = { q };
|
|
if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
|
try {
|
|
return await this.getRequest<Document>(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
public async put(uid: string, body: IPutDocumentsParams): Promise<Document> {
|
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
|
try {
|
|
return await this.putRequest<Document>(url, body);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
public async delete(uid: string): Promise<Document> {
|
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
|
try {
|
|
return await this.deleteRequest<Document>(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
}
|