import { type OfficeFolder } from "le-coffre-resources/dist/Customer"; import BaseCustomer from "../BaseCustomer"; // TODO Type get query params -> Where + inclue + orderby export interface IGetFoldersParams { q?: { select?: {}; where?: {}; orderBy?: {}[]; include?: {}; }; } export default class Folders extends BaseCustomer { private static instance: Folders; private readonly baseURl = this.namespaceUrl.concat("/folders"); private constructor() { super(); } public static getInstance() { if (!this.instance) { return new this(); } else { return this.instance; } } /** * @description : Get all folders */ public async get(q: IGetFoldersParams): Promise { const url = new URL(this.baseURl); Object.entries(q).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); } } /** * @description : Get a folder by uid */ public async getByUid(uid: string, q?: any): Promise { const url = new URL(this.baseURl.concat(`/${uid}`)); if (q) Object.entries(q).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); } } }