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 { 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(url); } catch (err) { this.onError(err); return Promise.reject(err); } } public async getByUid(uid: string): Promise { const url = new URL(this.baseUrl.concat(`/${uid}`)); try { return await this.getRequest(url); } catch (err) { this.onError(err); return Promise.reject(err); } } public async post(uid: string): Promise { const url = new URL(this.baseUrl.concat(`/${uid}`)); try { return await this.postRequest(url, {}); } catch (err) { this.onError(err); return Promise.reject(err); } } public async download(uid: string): Promise { const url = new URL(this.baseUrl.concat(`/download/${uid}`)); try { return await this.getRequest(url, undefined, ContentType.PDF, `${uid}.pdf`); } catch (err) { this.onError(err); return Promise.reject(err); } } }