32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import * as jspb from "google-protobuf";
|
|
import { CofdSheet } from "../_proto/cofd_pb";
|
|
import { Skills, ApiResult, UpdateAttributeRequest, UpdateSkillValueRequest } from "../_proto/cofd_api_pb";
|
|
|
|
const PROTOBUF_CONTENT_TYPE = { 'Content-Type': 'application/x-protobuf' };
|
|
|
|
function staticImplements<T>() {
|
|
return <U extends T>(constructor: U) => { constructor };
|
|
}
|
|
|
|
|
|
async function makeRequest<T extends jspb.Message>(uri: string, params: T): Promise<Uint8Array> {
|
|
let resp = await fetch(uri, {
|
|
method: 'POST',
|
|
headers: { ...PROTOBUF_CONTENT_TYPE },
|
|
body: params.serializeBinary()
|
|
});
|
|
|
|
const data = await resp.arrayBuffer();
|
|
return new Uint8Array(data);
|
|
}
|
|
|
|
export async function updateSkillValue(params: UpdateSkillValueRequest): Promise<ApiResult> {
|
|
let data = await makeRequest('/api/rpc/cofd/update_skill_value', params);
|
|
return ApiResult.deserializeBinary(data);
|
|
}
|
|
|
|
export async function updateAttributeValue(params: UpdateAttributeRequest): Promise<ApiResult> {
|
|
let data = await makeRequest('/api/rpc/cofd/update_attribute_value', params);
|
|
return ApiResult.deserializeBinary(data);
|
|
}
|