import { Rule } from "le-coffre-resources/dist/Admin"; import BaseAdmin from "../BaseAdmin"; export type IGetRulesParams = { where?: {}; include?: {}; select?: {}; }; export default class Rules extends BaseAdmin { private static instance: Rules; private readonly baseURl = this.namespaceUrl.concat("/rules"); private constructor() { super(); } public static getInstance() { if (!this.instance) { return new Rules(); } else { return this.instance; } } public async get(q: IGetRulesParams): 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); } } 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); } } }