snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
296
apps/meteor/server/api/v1/omnichannel/dashboards.ts
Normal file
296
apps/meteor/server/api/v1/omnichannel/dashboards.ts
Normal file
@@ -0,0 +1,296 @@
|
||||
import { OmnichannelAnalytics } from '@rocket.chat/core-services';
|
||||
import { Users } from '@rocket.chat/models';
|
||||
import {
|
||||
isGETDashboardTotalizerParams,
|
||||
isGETDashboardsAgentStatusParams,
|
||||
isGETLivechatAnalyticsDashboardsChartDataParams,
|
||||
validateUnauthorizedErrorResponse,
|
||||
validateForbiddenErrorResponse,
|
||||
GETLivechatAnalyticsDashboardsChartDataSuccessSchema,
|
||||
} from '@rocket.chat/rest-typings';
|
||||
|
||||
import { API } from '../..';
|
||||
import {
|
||||
getProductivityMetricsAsyncCached,
|
||||
getConversationsMetricsAsyncCached,
|
||||
getAgentsProductivityMetricsAsyncCached,
|
||||
getChatsMetricsAsyncCached,
|
||||
findAllChatsStatusAsyncCached,
|
||||
findAllChatMetricsByAgentAsyncCached,
|
||||
findAllAgentsStatusAsyncCached,
|
||||
findAllChatMetricsByDepartmentAsyncCached,
|
||||
findAllResponseTimeMetricsAsyncCached,
|
||||
} from '../../../lib/omnichannel/analytics/dashboards';
|
||||
import type { ExtractRoutesFromAPI } from '../../ApiClass';
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/conversation-totalizers',
|
||||
{
|
||||
authRequired: true,
|
||||
permissionsRequired: ['view-livechat-manager'],
|
||||
validateParams: isGETDashboardTotalizerParams,
|
||||
},
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
|
||||
const user = await Users.findOneById(this.userId, { projection: { utcOffset: 1, language: 1 } });
|
||||
if (!user) {
|
||||
return API.v1.failure('User not found');
|
||||
}
|
||||
|
||||
const totalizers = await getConversationsMetricsAsyncCached({ start, end, departmentId, user });
|
||||
return API.v1.success(totalizers);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/agents-productivity-totalizers',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardTotalizerParams },
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
|
||||
const user = await Users.findOneById(this.userId, { projection: { utcOffset: 1, language: 1 } });
|
||||
if (!user) {
|
||||
return API.v1.failure('User not found');
|
||||
}
|
||||
|
||||
const totalizers = await getAgentsProductivityMetricsAsyncCached({ start, end, departmentId, user });
|
||||
return API.v1.success(totalizers);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/chats-totalizers',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardTotalizerParams },
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
const startDate = new Date(start);
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
const endDate = new Date(end);
|
||||
|
||||
const totalizers = await getChatsMetricsAsyncCached({ start: startDate, end: endDate, departmentId });
|
||||
return API.v1.success(totalizers);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/productivity-totalizers',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardTotalizerParams },
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
|
||||
const user = await Users.findOneById(this.userId, { projection: { utcOffset: 1, language: 1 } });
|
||||
if (!user) {
|
||||
return API.v1.failure('User not found');
|
||||
}
|
||||
|
||||
const totalizers = await getProductivityMetricsAsyncCached({ start, end, departmentId, user });
|
||||
|
||||
return API.v1.success(totalizers);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/charts/chats',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardTotalizerParams },
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
const startDate = new Date(start);
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
const endDate = new Date(end);
|
||||
|
||||
const result = await findAllChatsStatusAsyncCached({ start: startDate, end: endDate, departmentId });
|
||||
|
||||
return API.v1.success(result);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/charts/chats-per-agent',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardTotalizerParams },
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
const startDate = new Date(start);
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
const endDate = new Date(end);
|
||||
const result = await findAllChatMetricsByAgentAsyncCached({ start: startDate, end: endDate, departmentId });
|
||||
|
||||
return API.v1.success(result);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/charts/agents-status',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardsAgentStatusParams },
|
||||
{
|
||||
async get() {
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
const result = await findAllAgentsStatusAsyncCached({ departmentId });
|
||||
|
||||
return API.v1.success(result);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/charts/chats-per-department',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardTotalizerParams },
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
const startDate = new Date(start);
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
const endDate = new Date(end);
|
||||
|
||||
const result = (await findAllChatMetricsByDepartmentAsyncCached({ start: startDate, end: endDate, departmentId })) as {
|
||||
[k: string]: { open: number; closed: number };
|
||||
};
|
||||
|
||||
return API.v1.success(result);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.addRoute(
|
||||
'livechat/analytics/dashboards/charts/timings',
|
||||
{ authRequired: true, permissionsRequired: ['view-livechat-manager'], validateParams: isGETDashboardTotalizerParams },
|
||||
{
|
||||
async get() {
|
||||
const { start, end } = this.queryParams;
|
||||
const { departmentId } = this.queryParams;
|
||||
|
||||
if (isNaN(Date.parse(start))) {
|
||||
return API.v1.failure('The "start" query parameter must be a valid date.');
|
||||
}
|
||||
const startDate = new Date(start);
|
||||
|
||||
if (isNaN(Date.parse(end))) {
|
||||
return API.v1.failure('The "end" query parameter must be a valid date.');
|
||||
}
|
||||
const endDate = new Date(end);
|
||||
|
||||
const result = await findAllResponseTimeMetricsAsyncCached({ start: startDate, end: endDate, departmentId });
|
||||
|
||||
return API.v1.success(result);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const livechatAnalyticsEndpoints = API.v1.get(
|
||||
'livechat/analytics/dashboards/charts-data',
|
||||
{
|
||||
response: {
|
||||
200: GETLivechatAnalyticsDashboardsChartDataSuccessSchema,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
},
|
||||
authRequired: true,
|
||||
permissionsRequired: ['view-livechat-manager'],
|
||||
query: isGETLivechatAnalyticsDashboardsChartDataParams,
|
||||
},
|
||||
async function action() {
|
||||
const { chartName, start, end, departmentId } = this.queryParams;
|
||||
|
||||
const chartData = await OmnichannelAnalytics.getAnalyticsChartData({
|
||||
daterange: {
|
||||
from: start,
|
||||
to: end,
|
||||
},
|
||||
chartOptions: {
|
||||
name: chartName,
|
||||
},
|
||||
utcOffset: this.user.utcOffset,
|
||||
executedBy: this.user._id,
|
||||
departmentId,
|
||||
});
|
||||
|
||||
if (!chartData) {
|
||||
return API.v1.success({
|
||||
chartLabel: chartName,
|
||||
dataLabels: [],
|
||||
dataPoints: [],
|
||||
});
|
||||
}
|
||||
|
||||
return API.v1.success(chartData);
|
||||
},
|
||||
);
|
||||
|
||||
type LivechatAnalyticsEndpoints = ExtractRoutesFromAPI<typeof livechatAnalyticsEndpoints>;
|
||||
|
||||
declare module '@rocket.chat/rest-typings' {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
|
||||
interface Endpoints extends LivechatAnalyticsEndpoints {}
|
||||
}
|
||||
Reference in New Issue
Block a user