2023-10-03 11:39:42 +02:00

70 lines
1.8 KiB
TypeScript

import { ContentType } from "@Front/Api/BaseApiService";
import BaseNotary from "../BaseNotary";
import { OfficeFolderAnchor } from "le-coffre-resources/dist/Notary";
export interface IGetAnchorsParams {
where?: {};
include?: {};
select?: {};
}
export default class OfficeFolderAnchors extends BaseNotary {
private static instance: OfficeFolderAnchors;
private readonly baseUrl = this.namespaceUrl.concat("/anchors");
private constructor() {
super();
}
public static getInstance() {
if (!this.instance) {
return new this();
} else {
return this.instance;
}
}
public async get(q?: IGetAnchorsParams): Promise<OfficeFolderAnchor[]> {
const url = new URL(this.baseUrl);
if (q) {
const query = { q };
Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
}
try {
return await this.getRequest<OfficeFolderAnchor[]>(url);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
public async getByUid(uid: string): Promise<OfficeFolderAnchor> {
const url = new URL(this.baseUrl.concat(`/${uid}`));
try {
return await this.getRequest<OfficeFolderAnchor>(url);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
public async post(uid: string): Promise<OfficeFolderAnchor> {
const url = new URL(this.baseUrl.concat(`/${uid}`));
try {
return await this.postRequest<OfficeFolderAnchor>(url, {});
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
public async download(uid: string): Promise<any> {
const url = new URL(this.baseUrl.concat(`/download/${uid}`));
try {
return await this.getRequest<any>(url, undefined, ContentType.PDF, `${uid}.pdf`);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
}