From 9ae1ed25c45c34455e812877fc743888e9195942 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Tue, 29 Oct 2019 18:16:51 +0900 Subject: [PATCH] encoder and decoder are added --- .../src/lib/apis/file-talk-save.ts | 78 +++++++++++++++---- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/projects/ucap-webmessenger-api-common/src/lib/apis/file-talk-save.ts b/projects/ucap-webmessenger-api-common/src/lib/apis/file-talk-save.ts index d370315b..f3c01229 100644 --- a/projects/ucap-webmessenger-api-common/src/lib/apis/file-talk-save.ts +++ b/projects/ucap-webmessenger-api-common/src/lib/apis/file-talk-save.ts @@ -4,8 +4,11 @@ import { APIResponse, APIEncoder, APIDecoder, - ParameterUtil + ParameterUtil, + StatusCode, + JsonAnalization } from '@ucap-webmessenger/api'; +import { JsonObject } from 'type-fest'; export interface FileTalkSaveRequest extends APIRequest { userSeq: string; @@ -21,31 +24,72 @@ export interface FileTalkSaveRequest extends APIRequest { } export interface FileTalkSaveResponse extends APIResponse { - RoomID?: string; - FileName?: string; - FileExt?: string; - FileType?: string; - ThumbURL?: string; - AttSEQ?: string; - AttSize?: string; - AttRegDate?: string; - ImageWidth?: string; - ImageHeight?: string; - CompanyCode?: string; - VoiceTime?: string; - SynapKey?: string; + roomID?: string; + fileName?: string; + fileExt?: string; + fileType?: string; + thumbnailUrl?: string; + attachmentSeq?: string; + attachmentSize?: string; + attachmentRegDate?: string; + imageWidth?: string; + imageHeight?: string; + companyCode?: string; + voiceTime?: 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 = ( 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 = ( 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; + } };