Skip to content

Commit bfe3fe9

Browse files
refactor: address review — move response schemas inline, remove manual typings
1 parent 731de22 commit bfe3fe9

File tree

2 files changed

+44
-55
lines changed

2 files changed

+44
-55
lines changed

apps/meteor/app/livechat/server/api/v1/agent.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import type { ILivechatAgent } from '@rocket.chat/core-typings';
22
import { ILivechatAgentStatus } from '@rocket.chat/core-typings';
33
import { Users } from '@rocket.chat/models';
44
import {
5-
GETAgentInfoSuccessResponse,
6-
GETAgentNextSuccessResponse,
5+
ajv,
76
isGETAgentNextToken,
87
isPOSTLivechatAgentSaveInfoParams,
98
isPOSTLivechatAgentStatusProps,
@@ -23,6 +22,38 @@ import { saveAgentInfo } from '../../lib/omni-users';
2322
import { setUserStatusLivechat, allowAgentChangeServiceStatus } from '../../lib/utils';
2423
import { findRoom, findGuest, findAgent, findOpenRoom } from '../lib/livechat';
2524

25+
const GETAgentInfoSuccessResponse = ajv.compile<{ agent: ILivechatAgent | { hiddenInfo: true }; success: boolean }>({
26+
type: 'object',
27+
properties: {
28+
agent: {
29+
type: 'object',
30+
},
31+
success: {
32+
type: 'boolean',
33+
enum: [true],
34+
},
35+
},
36+
required: ['agent', 'success'],
37+
additionalProperties: false,
38+
});
39+
40+
const GETAgentNextSuccessResponse = ajv.compile<
41+
{ agent?: ILivechatAgent | { hiddenInfo: true }; success: boolean } | { success: boolean }
42+
>({
43+
type: 'object',
44+
properties: {
45+
agent: {
46+
type: 'object',
47+
},
48+
success: {
49+
type: 'boolean',
50+
enum: [true],
51+
},
52+
},
53+
required: ['success'],
54+
additionalProperties: false,
55+
});
56+
2657
const livechatAgentInfoEndpoint = API.v1.get(
2758
'livechat/agent.info/:rid/:token',
2859
{

packages/rest-typings/src/v1/omnichannel.ts

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,43 +2285,6 @@ const GETAgentNextTokenSchema = {
22852285

22862286
export const isGETAgentNextToken = ajvQuery.compile<GETAgentNextToken>(GETAgentNextTokenSchema);
22872287

2288-
const GETAgentInfoSuccessResponseSchema = {
2289-
type: 'object',
2290-
properties: {
2291-
agent: {
2292-
type: 'object',
2293-
},
2294-
success: {
2295-
type: 'boolean',
2296-
enum: [true],
2297-
},
2298-
},
2299-
required: ['agent', 'success'],
2300-
additionalProperties: false,
2301-
};
2302-
2303-
export const GETAgentInfoSuccessResponse = ajv.compile<{ agent: ILivechatAgent | { hiddenInfo: true }; success: boolean }>(
2304-
GETAgentInfoSuccessResponseSchema,
2305-
);
2306-
2307-
const GETAgentNextSuccessResponseSchema = {
2308-
type: 'object',
2309-
properties: {
2310-
agent: {
2311-
type: 'object',
2312-
},
2313-
success: {
2314-
type: 'boolean',
2315-
enum: [true],
2316-
},
2317-
},
2318-
required: ['success'],
2319-
additionalProperties: false,
2320-
};
2321-
2322-
export const GETAgentNextSuccessResponse = ajv.compile<
2323-
{ agent?: ILivechatAgent | { hiddenInfo: true }; success: boolean } | { success: boolean }
2324-
>(GETAgentNextSuccessResponseSchema);
23252288

23262289
type GETLivechatConfigParams = {
23272290
token?: string;
@@ -2885,14 +2848,14 @@ type POSTLivechatRoomCloseByUserParams = {
28852848
generateTranscriptPdf?: boolean;
28862849
forceClose?: boolean;
28872850
transcriptEmail?:
2888-
| {
2889-
// Note: if sendToVisitor is false, then any previously requested transcripts (like via livechat:requestTranscript) will be also cancelled
2890-
sendToVisitor: false;
2891-
}
2892-
| {
2893-
sendToVisitor: true;
2894-
requestData: Pick<NonNullable<IOmnichannelRoom['transcriptRequest']>, 'email' | 'subject'>;
2895-
};
2851+
| {
2852+
// Note: if sendToVisitor is false, then any previously requested transcripts (like via livechat:requestTranscript) will be also cancelled
2853+
sendToVisitor: false;
2854+
}
2855+
| {
2856+
sendToVisitor: true;
2857+
requestData: Pick<NonNullable<IOmnichannelRoom['transcriptRequest']>, 'email' | 'subject'>;
2858+
};
28962859
};
28972860

28982861
const POSTLivechatRoomCloseByUserParamsSchema = {
@@ -4397,8 +4360,8 @@ export const isLivechatTriggerWebhookCallParams = ajv.compile<LivechatTriggerWeb
43974360

43984361
type POSTLivechatRoomsCloseAll =
43994362
| {
4400-
departmentIds?: string[];
4401-
}
4363+
departmentIds?: string[];
4364+
}
44024365
| undefined;
44034366

44044367
const POSTLivechatRoomsCloseAllSchema = {
@@ -4920,12 +4883,7 @@ export type OmnichannelEndpoints = {
49204883
'/v1/omnichannel/contact.search': {
49214884
GET: (params: GETOmnichannelContactSearchProps) => { contact: ILivechatVisitor | null };
49224885
};
4923-
'/v1/livechat/agent.info/:rid/:token': {
4924-
GET: () => { agent: ILivechatAgent | { hiddenInfo: true } };
4925-
};
4926-
'/v1/livechat/agent.next/:token': {
4927-
GET: (params: GETAgentNextToken) => { agent: ILivechatAgent | { hiddenInfo: true } } | void;
4928-
};
4886+
49294887
'/v1/livechat/config': {
49304888
GET: (params: GETLivechatConfigParams) => {
49314889
config: { [k: string]: string | boolean } & { room?: IOmnichannelRoom; agent?: ILivechatAgent };

0 commit comments

Comments
 (0)