amocrm-client
Version:
JS Library for AmoCRM
19 lines (16 loc) • 972 B
text/typescript
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;
}
};
}