71 lines
1.6 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-09-18 15:02:21 +09:00
export interface TranslationSaveRequest extends APIRequest {
userSeq: number;
2019-09-18 15:02:21 +09:00
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-12-31 14:36:32 +09:00
translationSeq?: number;
2019-11-05 13:46:17 +09:00
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 {
return {
2019-12-31 14:36:32 +09:00
statusCode: res.StatusCode,
translationSeq: !!res.EventTransSeq ? Number(res.EventTransSeq) : 0,
roomSeq: res.RoomID,
registrationDate: res.RegDate,
srcLocale: res.SrcLocale,
destLocale: res.DestLocale,
original: res.Original,
translation: res.Translation,
returnJson: JSON.stringify(res)
2019-11-05 13:46:17 +09:00
} as TranslationSaveResponse;
} catch (e) {
return {
statusCode: StatusCode.Fail,
errorMessage: e
} as TranslationSaveResponse;
}
2019-09-20 11:39:09 +09:00
};