UNPKG

amocrm-client

Version:
19 lines (16 loc) 972 B
import { TFactoryConstructor } from "../../../types"; import { IEntityAttributes, IResourceEntity, IResourceFactory } from "../../../interfaces/api"; import { IRequestOptions } from "../../../interfaces/common"; export interface ICanDeleteByIdFactory<T extends IResourceEntity<IResourceFactory<T>>> extends IResourceFactory<T> { deleteById(identity: number, options?: IRequestOptions): Promise<boolean>; } export function hasDeleteById<T extends IResourceEntity<IResourceFactory<T>>>(Base: TFactoryConstructor<T>): TFactoryConstructor<T> { return class HasDeleteById extends Base implements ICanDeleteByIdFactory<T> { async deleteById(identity: number, options?: IRequestOptions) { const url = this.getUrl('/' + identity); const request = this.getRequest(); const { response } = await request.delete<IEntityAttributes>(url, options); return response.statusCode == 204; } }; }