Commit c38ea334 authored by murtaza98's avatar murtaza98

code refactor

parent 47c30fc0
......@@ -16,5 +16,5 @@ export enum Logs {
INVALID_RESPONSE_FROM_RASA_CONTENT_UNDEFINED = 'Error Parsing RASA\'s Response. Content is undefined',
CLOSE_CHAT_REQUEST_FAILED_ERROR = 'Error: Internal Server Error. Could not close the chat',
HANDOVER_REQUEST_FAILED_ERROR = 'Error occurred while processing handover. Details',
INVALID_DEPARTMENT_NAME_IN_APP_SETTING = 'Error: Department Name is not valid in app setting',
INVALID_DEPARTMENT_NAME_IN_BOTH_SETTING_AND_REQUEST = 'Error: Department Name cannot be empty. Please provide a department name either in App Setting or in the handover Request',
}
......@@ -57,20 +57,18 @@ export const performHandover = async (modify: IModify, read: IRead, rid: string,
currentRoom: room,
};
// Fill livechatTransferData.targetDepartment param
if (targetDepartmentName) {
const targetDepartment: IDepartment = (await read.getLivechatReader().getLivechatDepartmentByIdOrName(targetDepartmentName)) as IDepartment;
if (!targetDepartment) { throw new Error(Logs.INVALID_DEPARTMENT_NAME); }
livechatTransferData.targetDepartment = targetDepartment.id;
} else {
const defaultTargetDepartmentName = await getAppSettingValue(read, AppSetting.RasaDefaultHandoverDepartment);
if (!defaultTargetDepartmentName) { throw new Error(Logs.INVALID_DEPARTMENT_NAME_IN_APP_SETTING); }
const targetDepartment: IDepartment = (await read.getLivechatReader().getLivechatDepartmentByIdOrName(defaultTargetDepartmentName)) as IDepartment;
if (!targetDepartment) { throw new Error(Logs.INVALID_DEPARTMENT_NAME_IN_APP_SETTING); }
livechatTransferData.targetDepartment = targetDepartment.id;
const targetDepartment = targetDepartmentName || await getAppSettingValue(read, AppSetting.RasaDefaultHandoverDepartment);
if (!targetDepartment) {
throw new Error(Logs.INVALID_DEPARTMENT_NAME_IN_BOTH_SETTING_AND_REQUEST);
}
const departmentDB: IDepartment = await read.getLivechatReader().getLivechatDepartmentByIdOrName(targetDepartment) as IDepartment;
if (!departmentDB) {
throw new Error(Logs.INVALID_DEPARTMENT_NAME);
}
livechatTransferData.targetDepartment = departmentDB.id;
const result = await modify.getUpdater().getLivechatUpdater().transferVisitor(visitor, livechatTransferData)
.catch((error) => {
throw new Error(`${ Logs.HANDOVER_REQUEST_FAILED_ERROR } ${error}`);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment