import { Customer } from "le-coffre-resources/dist/SuperAdmin"; import { Service } from "typedi"; import BaseSuperAdmin from "../BaseSuperAdmin"; // TODO Type get query params -> Where + inclue + orderby export interface IGetCustomersparams { q?: {}; } // TODO Type getbyuid query params export type IPutCustomersParams = { uid?: Customer["uid"]; contact?: Customer["contact"]; }; @Service() export default class Customers extends BaseSuperAdmin { private static instance: Customers; private readonly baseURl = this.namespaceUrl.concat("/customers"); private constructor() { super(); } public static getInstance() { if (!this.instance) { return new this(); } else { return this.instance; } } public async get(q: IGetCustomersparams): 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); } } 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 { return await this.getRequest(url); } catch (err) { this.onError(err); return Promise.reject(err); } } public async put(uid: string, body: IPutCustomersParams): 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); } } }