amocrm-client
Version:
JS Library for AmoCRM
20 lines (18 loc) • 961 B
text/typescript
import { ICriteria, IResourceEntity } from "../../../interfaces/api";
import { TConstructor, TEntityConstructor } from "../../../types";
import { IRequestOptions } from "../../../interfaces/common";
import { ICanDeleteByIdFactory } from "../../factories/mixins/hasDeleteById";
export interface IHasDeleteEntity<T extends ICanDeleteByIdFactory<IResourceEntity<T>>> {
delete(options?: IRequestOptions): Promise<boolean>;
}
export function hasDelete<T extends ICanDeleteByIdFactory<IResourceEntity<T>>>(Base: TEntityConstructor<T>): TConstructor<IResourceEntity<T>> {
return class HasDelete extends Base {
async fetch(criteria?: ICriteria<any, any>, options?: IRequestOptions) {
if (this.isNew()) return false;
const id = <number>this.id;
const factory = this.getFactory();
const isSuccess = await factory.deleteById(id, options);
return isSuccess;
}
};
}