import User from "le-coffre-resources/dist/SuperAdmin"; import BaseAdmin from "../BaseAdmin"; // TODO Type get query params -> Where + inclue + orderby export interface IGetUsersparams { where?: {}; include?: {}; select?: {}; } // TODO Type getbyuid query params export type IPutUsersParams = { uid?: User["uid"]; idNot?: User["idNot"]; contact?: User["contact"]; office_membership?: User["office_membership"]; documents?: User["documents"]; }; export default class Users extends BaseAdmin { private static instance: Users; private readonly baseURl = this.namespaceUrl.concat("/users"); private constructor() { super(); } public static getInstance() { if (!this.instance) { return new this(); } else { return this.instance; } } /** * @description : Get all Users */ public async get(q: IGetUsersparams): Promise { const url = new URL(this.baseURl); 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); } } /** * @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); } } /** * @description : Create a User */ // public async post(body: IPostDeedsParams): Promise { // const url = new URL(this.baseURl); // try { // return await this.postRequest(url, body); // } catch (err) { // this.onError(err); // return Promise.reject(err); // } // } /** * @description : Update the folder description */ public async put(uid: string, body: IPutUsersParams): 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); } } }