Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {
isLivechatTagsListProps,
GETLivechatTagsSuccessResponse,
GETLivechatTagByIdSuccessResponse,
isPOSTLivechatTagsSaveParams,
POSTLivechatTagsSaveSuccessResponse,
isPOSTLivechatTagsDeleteParams,
POSTLivechatTagsDeleteSuccessResponse,
validateBadRequestErrorResponse,
validateForbiddenErrorResponse,
validateUnauthorizedErrorResponse,
validateNotFoundErrorResponse,
} from '@rocket.chat/rest-typings';

import { findTags, findTagById } from './lib/tags';
Expand All @@ -14,15 +18,21 @@ import type { ExtractRoutesFromAPI } from '../../../../../app/api/server/ApiClas
import { getPaginationItems } from '../../../../../app/api/server/helpers/getPaginationItems';
import { LivechatEnterprise } from '../lib/LivechatEnterprise';

API.v1.addRoute(
'livechat/tags',
{
authRequired: true,
permissionsRequired: { GET: { permissions: ['view-l-room', 'manage-livechat-tags'], operation: 'hasAny' } },
license: ['livechat-enterprise'],
},
{
async get() {
const livechatTagsEndpoints = API.v1
.get(
'livechat/tags',
{
authRequired: true,
permissionsRequired: { GET: { permissions: ['view-l-room', 'manage-livechat-tags'], operation: 'hasAny' } },
license: ['livechat-enterprise'],
query: isLivechatTagsListProps,
response: {
200: GETLivechatTagsSuccessResponse,
401: validateUnauthorizedErrorResponse,
403: validateForbiddenErrorResponse,
},
},
async function action() {
const { offset, count } = await getPaginationItems(this.queryParams);
const { sort } = await this.parseJsonQuery();
const { text, viewAll, department } = this.queryParams;
Expand All @@ -41,18 +51,21 @@ API.v1.addRoute(
}),
);
},
},
);

API.v1.addRoute(
'livechat/tags/:tagId',
{
authRequired: true,
permissionsRequired: { GET: { permissions: ['view-l-room', 'manage-livechat-tags'], operation: 'hasAny' } },
license: ['livechat-enterprise'],
},
{
async get() {
)
.get(
'livechat/tags/:tagId',
{
authRequired: true,
permissionsRequired: { GET: { permissions: ['view-l-room', 'manage-livechat-tags'], operation: 'hasAny' } },
license: ['livechat-enterprise'],
response: {
200: GETLivechatTagByIdSuccessResponse,
401: validateUnauthorizedErrorResponse,
403: validateForbiddenErrorResponse,
404: validateNotFoundErrorResponse,
},
},
async function action() {
const { tagId } = this.urlParams;

const tag = await findTagById({
Expand All @@ -66,10 +79,7 @@ API.v1.addRoute(

return API.v1.success(tag);
},
},
);

const livechatTagsEndpoints = API.v1
)
.post(
'livechat/tags.save',
{
Expand Down Expand Up @@ -119,5 +129,5 @@ type LivechatTagsEndpoints = ExtractRoutesFromAPI<typeof livechatTagsEndpoints>;

declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
interface Endpoints extends LivechatTagsEndpoints {}
interface Endpoints extends LivechatTagsEndpoints { }
}
60 changes: 50 additions & 10 deletions packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,14 @@ const POSTLivechatTagsDeleteSuccessResponseSchema = {

export const POSTLivechatTagsDeleteSuccessResponse = ajv.compile<void>(POSTLivechatTagsDeleteSuccessResponseSchema);

type LivechatTagsListProps = PaginatedRequest<{ text: string; viewAll?: 'true' | 'false'; department?: string }, 'name'>;
type LivechatTagsListProps = PaginatedRequest<{ text?: string; viewAll?: 'true' | 'false'; department?: string }, 'name'>;

const LivechatTagsListSchema = {
type: 'object',
properties: {
text: {
type: 'string',
nullable: true,
},
department: {
type: 'string',
Expand Down Expand Up @@ -683,12 +684,58 @@ const LivechatTagsListSchema = {
nullable: true,
},
},
required: ['text'],
additionalProperties: false,
};

export const isLivechatTagsListProps = ajvQuery.compile<LivechatTagsListProps>(LivechatTagsListSchema);

const GETLivechatTagsSuccessResponseSchema = {
type: 'object',
properties: {
tags: {
type: 'array',
items: {
type: 'object',
properties: {
_id: { type: 'string' },
name: { type: 'string' },
description: { type: 'string' },
numDepartments: { type: 'number' },
departments: { type: 'array', items: { type: 'string' } },
},
required: ['_id', 'name', 'numDepartments', 'departments'],
additionalProperties: false,
},
},
count: { type: 'number' },
offset: { type: 'number' },
total: { type: 'number' },
success: { type: 'boolean', enum: [true] },
},
required: ['tags', 'count', 'offset', 'total', 'success'],
additionalProperties: false,
};

export const GETLivechatTagsSuccessResponse = ajv.compile<{ tags: ILivechatTag[]; count: number; offset: number; total: number }>(
GETLivechatTagsSuccessResponseSchema,
);

const GETLivechatTagByIdSuccessResponseSchema = {
type: 'object',
properties: {
_id: { type: 'string' },
name: { type: 'string' },
description: { type: 'string' },
numDepartments: { type: 'number' },
departments: { type: 'array', items: { type: 'string' } },
success: { type: 'boolean', enum: [true] },
},
required: ['_id', 'name', 'numDepartments', 'departments', 'success'],
additionalProperties: false,
};

export const GETLivechatTagByIdSuccessResponse = ajv.compile<ILivechatTag>(GETLivechatTagByIdSuccessResponseSchema);

type LivechatDepartmentProps = PaginatedRequest<{
text?: string;
onlyMyDepartments?: booleanString;
Expand Down Expand Up @@ -4621,14 +4668,7 @@ export type OmnichannelEndpoints = {
'/v1/livechat/monitors/:username': {
GET: () => ILivechatMonitor;
};
'/v1/livechat/tags': {
GET: (params: LivechatTagsListProps) => PaginatedResult<{
tags: ILivechatTag[];
}>;
};
'/v1/livechat/tags/:tagId': {
GET: () => ILivechatTag;
};

'/v1/livechat/department': {
GET: (params?: LivechatDepartmentProps) => PaginatedResult<{
departments: ILivechatDepartment[];
Expand Down