amocrm-client
Version:
JS Library for AmoCRM
19 lines (16 loc) • 855 B
text/typescript
import { IResourceEntity, IResourceFactory } from "../../../interfaces/api";
import { TConstructor, TEntityConstructor } from "../../../types";
import { IRequestOptions } from "../../../interfaces/common";
import { IHasUpdateFactory } from "../../factories/mixins/hasUpdate";
export interface IHasUpdateEntity<T extends IResourceFactory<IResourceEntity<T>>> extends IResourceEntity<T> {
update(options?: IRequestOptions): Promise<T>;
}
export function hasUpdate<T extends IHasUpdateFactory<IResourceEntity<T>>>(Base: TEntityConstructor<T>): TConstructor<IResourceEntity<T>> {
return class HasUpdate extends Base {
async update(options?: IRequestOptions) {
const criteria = [this];
const [entity] = await this.getFactory().update(criteria, options);
return entity;
}
};
}