encoder and decoder are added

This commit is contained in:
병준 박 2019-10-29 18:16:51 +09:00
parent eef36fcb44
commit 9ae1ed25c4

View File

@ -4,8 +4,11 @@ import {
APIResponse, APIResponse,
APIEncoder, APIEncoder,
APIDecoder, APIDecoder,
ParameterUtil ParameterUtil,
StatusCode,
JsonAnalization
} from '@ucap-webmessenger/api'; } from '@ucap-webmessenger/api';
import { JsonObject } from 'type-fest';
export interface FileTalkSaveRequest extends APIRequest { export interface FileTalkSaveRequest extends APIRequest {
userSeq: string; userSeq: string;
@ -21,31 +24,72 @@ export interface FileTalkSaveRequest extends APIRequest {
} }
export interface FileTalkSaveResponse extends APIResponse { export interface FileTalkSaveResponse extends APIResponse {
RoomID?: string; roomID?: string;
FileName?: string; fileName?: string;
FileExt?: string; fileExt?: string;
FileType?: string; fileType?: string;
ThumbURL?: string; thumbnailUrl?: string;
AttSEQ?: string; attachmentSeq?: string;
AttSize?: string; attachmentSize?: string;
AttRegDate?: string; attachmentRegDate?: string;
ImageWidth?: string; imageWidth?: string;
ImageHeight?: string; imageHeight?: string;
CompanyCode?: string; companyCode?: string;
VoiceTime?: string; voiceTime?: string;
SynapKey?: string; synapKey?: string;
returnJson?: any;
} }
const fileTalkSaveEncodeMap = {}; const fileTalkSaveEncodeMap = {
userSeq: 'p_user_seq',
deviceType: 'p_device_type',
token: 'p_token',
file: 'file',
fileName: 'p_file_name',
thumb: 'thumb',
voice: 'p_voice',
voiceTime: 'p_voice_time',
roomId: 'p_room_id',
type: 'p_type'
};
export const encodeFileTalkSave: APIEncoder<FileTalkSaveRequest> = ( export const encodeFileTalkSave: APIEncoder<FileTalkSaveRequest> = (
req: FileTalkSaveRequest req: FileTalkSaveRequest
) => { ) => {
return ParameterUtil.encode(fileTalkSaveEncodeMap, req); const extraParams: any = {};
if (!!req.voice) {
extraParams.voice = req.voice ? 'Y' : 'N';
}
return ParameterUtil.encode(fileTalkSaveEncodeMap, req, extraParams);
}; };
export const decodeFileTalkSave: APIDecoder<FileTalkSaveResponse> = ( export const decodeFileTalkSave: APIDecoder<FileTalkSaveResponse> = (
res: any res: any
) => { ) => {
return {} as FileTalkSaveResponse; try {
const json: JsonObject | Error = JsonAnalization.receiveAnalization(res);
return {
statusCode: json.StatusCode,
roomID: json.RoomID,
fileName: json.FileName,
fileExt: json.FileExt,
fileType: json.FileType,
thumbnailUrl: json.ThumbURL,
attachmentSeq: json.AttSEQ,
attachmentSize: json.AttSize,
attachmentRegDate: json.AttRegDate,
imageWidth: json.ImageWidth,
imageHeight: json.ImageHeight,
companyCode: json.CompanyCode,
voiceTime: json.VoiceTime,
synapKey: json.SynapKey,
returnJson: res
} as FileTalkSaveResponse;
} catch (e) {
return {
statusCode: StatusCode.Fail,
errorMessage: e
} as FileTalkSaveResponse;
}
}; };