49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { Subscription } from "le-coffre-resources/dist/Admin";
|
|
import BaseAdmin from "../../../../../common/Api/LeCoffreApi/Admin/BaseAdmin";
|
|
|
|
export interface IPostSubscriptionsParams {
|
|
emails: string[];
|
|
}
|
|
|
|
export default class Subscriptions extends BaseAdmin {
|
|
private static instance: Subscriptions;
|
|
private readonly baseURl = this.namespaceUrl.concat("/subscriptions");
|
|
|
|
private constructor() {
|
|
super();
|
|
}
|
|
|
|
public static getInstance() {
|
|
if (!this.instance) {
|
|
return new this();
|
|
} else {
|
|
return this.instance;
|
|
}
|
|
}
|
|
|
|
public async get(q: any) {
|
|
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 {
|
|
return await this.getRequest<Subscription[]>(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @description : Create a Document
|
|
*/
|
|
public async post(body: IPostSubscriptionsParams) {
|
|
const url = new URL(this.baseURl.concat(`/invite`));
|
|
try {
|
|
return await this.postRequest(url, body as any);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
}
|