73 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-09-18 15:02:21 +09:00
import { DeviceType } from '@ucap-webmessenger/core';
2019-09-20 11:39:09 +09:00
import {
APIRequest,
APIResponse,
APIEncoder,
APIDecoder,
2019-11-05 13:46:17 +09:00
ParameterUtil,
JsonAnalization,
StatusCode
2019-09-20 11:39:09 +09:00
} from '@ucap-webmessenger/api';
2019-11-05 13:46:17 +09:00
import { JsonObject } from 'type-fest';
2019-09-18 15:02:21 +09:00
export interface TranslationSaveRequest extends APIRequest {
userSeq: string;
deviceType: DeviceType;
token: string;
2019-11-05 13:46:17 +09:00
roomSeq?: string;
2019-09-18 15:02:21 +09:00
original?: string;
srcLocale: string;
destLocale: string;
}
export interface TranslationSaveResponse extends APIResponse {
2019-11-05 13:46:17 +09:00
translationSeq?: string;
roomSeq?: string;
registrationDate?: string;
srcLocale?: string;
destLocale?: string;
original?: string;
translation?: string;
returnJson?: any;
2019-09-18 15:02:21 +09:00
}
2019-09-20 11:39:09 +09:00
2019-11-05 13:46:17 +09:00
const translationSaveEncodeMap = {
userSeq: 'p_user_seq',
deviceType: 'p_device_type',
token: 'p_token',
roomSeq: 'p_room_id',
original: 'p_original',
srcLocale: 'p_src_locale',
destLocale: 'p_dest_locale'
};
2019-09-20 11:39:09 +09:00
export const encodeTranslationSave: APIEncoder<TranslationSaveRequest> = (
req: TranslationSaveRequest
) => {
return ParameterUtil.encode(translationSaveEncodeMap, req);
};
export const decodeTranslationSave: APIDecoder<TranslationSaveResponse> = (
res: any
) => {
2019-11-05 13:46:17 +09:00
try {
const json: JsonObject | Error = JsonAnalization.receiveAnalization(res);
return {
statusCode: json.StatusCode,
translationSeq: json.EventTransSEQ,
roomSeq: json.RoomID,
registrationDate: json.RegDate,
srcLocale: json.SrcLocale,
destLocale: json.DestLocale,
original: json.Original,
translation: json.Translation,
returnJson: res
} as TranslationSaveResponse;
} catch (e) {
return {
statusCode: StatusCode.Fail,
errorMessage: e
} as TranslationSaveResponse;
}
2019-09-20 11:39:09 +09:00
};