import { File } from "le-coffre-resources/dist/Customer"; import BaseCustomer from "../BaseCustomer"; // TODO Type get query params -> Where + inclue + orderby export interface IGetFilesparams { where?: {}; include?: {}; } // TODO Type getbyuid query params export type IPutFilesParams = {}; export interface IPostFilesParams {} export default class Files extends BaseCustomer { private static instance: Files; private readonly baseURl = this.namespaceUrl.concat("/files"); private constructor() { super(); } public static getInstance() { return (this.instance ??= new this()); } public async get(q: IGetFilesparams): Promise { 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 { const files = await this.getRequest(url); return files; } catch (err) { this.onError(err); return Promise.reject(err); } } /** * @description : Create a File */ public async post(body: any): Promise { const url = new URL(this.baseURl); try { return await this.postRequestFormData(url, body); } catch (err) { this.onError(err); return Promise.reject(err); } } public getUploadLink(uid: string): string { return this.baseURl.concat(`/download/${uid}`); } public async getByUid(uid: string, q?: any): Promise { 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 { const file = await this.getRequest(url); return file; } catch (err) { this.onError(err); return Promise.reject(err); } } public async put(uid: string, body: IPutFilesParams): Promise { const url = new URL(this.baseURl.concat(`/${uid}`)); try { return await this.putRequest(url, body); } catch (err) { this.onError(err); return Promise.reject(err); } } /** * @description : Delete a folder only if the folder don't contains customers */ public async delete(uid: string): Promise { const url = new URL(this.baseURl.concat(`/${uid}`)); try { return await this.deleteRequest(url); } catch (err) { this.onError(err); return Promise.reject(err); } } }