2021-05-12 06:35:00 +00:00
|
|
|
import { GrpcRequest } from '../grpc-request';
|
|
|
|
import { Request } from '../request';
|
2020-11-02 00:55:22 +00:00
|
|
|
import * as models from '../index';
|
2020-11-13 23:31:18 +00:00
|
|
|
import { isGrpcRequest, isGrpcRequestId } from './is-model';
|
|
|
|
|
|
|
|
export function getById(requestId: string): Promise<Request | GrpcRequest | null> {
|
|
|
|
return isGrpcRequestId(requestId)
|
|
|
|
? models.grpcRequest.getById(requestId)
|
|
|
|
: models.request.getById(requestId);
|
|
|
|
}
|
2020-11-02 00:55:22 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export function remove(request: Request | GrpcRequest) {
|
2020-11-02 00:55:22 +00:00
|
|
|
return isGrpcRequest(request)
|
|
|
|
? models.grpcRequest.remove(request)
|
|
|
|
: models.request.remove(request);
|
|
|
|
}
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export function update<T extends object>(request: T, patch: Partial<T> = {}): Promise<T> {
|
|
|
|
// @ts-expect-error -- TSCONVERSION
|
2020-11-02 00:55:22 +00:00
|
|
|
return isGrpcRequest(request)
|
|
|
|
? models.grpcRequest.update(request, patch)
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION
|
2020-11-02 00:55:22 +00:00
|
|
|
: models.request.update(request, patch);
|
|
|
|
}
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export function duplicate<T extends object>(request: T, patch: Partial<T> = {}): Promise<T> {
|
|
|
|
// @ts-expect-error -- TSCONVERSION
|
2020-11-02 00:55:22 +00:00
|
|
|
return isGrpcRequest(request)
|
|
|
|
? models.grpcRequest.duplicate(request, patch)
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION
|
2020-11-02 00:55:22 +00:00
|
|
|
: models.request.duplicate(request, patch);
|
|
|
|
}
|