RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/livechat/lib/inquiries.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { OmnichannelSortingMechanismSettingType } from '@rocket.chat/core-typings';

type SortOrder = 1 | -1;

type ReturnType =
    | {
            priorityWeight: SortOrder;
            ts: SortOrder;
            _updatedAt: SortOrder;
      }
    | {
            estimatedWaitingTimeQueue: SortOrder;
            ts: SortOrder;
            _updatedAt: SortOrder;
      }
    | {
            ts: SortOrder;
            _updatedAt: SortOrder;
      };

export const getOmniChatSortQuery = (
    sortByMechanism: OmnichannelSortingMechanismSettingType = OmnichannelSortingMechanismSettingType.Timestamp,
): ReturnType => {
    switch (sortByMechanism) {
        case OmnichannelSortingMechanismSettingType.Priority:
            return { priorityWeight: 1, ts: 1, _updatedAt: -1 };
        case OmnichannelSortingMechanismSettingType.SLAs:
            return { estimatedWaitingTimeQueue: 1, ts: 1, _updatedAt: -1 };
        case OmnichannelSortingMechanismSettingType.Timestamp:
        default:
            return { ts: 1, _updatedAt: -1 };
    }
};