Skip to content

Commit 4cc4c14

Browse files
committed
Moving all schemas from rest-typings to a single source
1 parent 86e3288 commit 4cc4c14

File tree

2 files changed

+34
-37
lines changed
  • apps/meteor/app/api/server/v1
  • packages/rest-typings/src/v1

2 files changed

+34
-37
lines changed

apps/meteor/app/api/server/v1/chat.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Message } from '@rocket.chat/core-services';
2-
import type { IMessage, IThreadMainMessage } from '@rocket.chat/core-typings';
2+
import type { IMessage, IRoom, IThreadMainMessage } from '@rocket.chat/core-typings';
33
import { MessageTypes } from '@rocket.chat/message-types';
44
import { Messages, Users, Rooms, Subscriptions } from '@rocket.chat/models';
55
import {
@@ -12,7 +12,6 @@ import {
1212
isChatSyncMessagesProps,
1313
isChatGetMessageProps,
1414
isChatPostMessageProps,
15-
isChatSearchProps,
1615
isChatSendMessageProps,
1716
isChatIgnoreUserProps,
1817
isChatGetPinnedMessagesProps,
@@ -26,6 +25,7 @@ import {
2625
isChatGetDiscussionsProps,
2726
validateBadRequestErrorResponse,
2827
validateUnauthorizedErrorResponse,
28+
type PaginatedRequest,
2929
} from '@rocket.chat/rest-typings';
3030
import { escapeRegExp } from '@rocket.chat/string-helpers';
3131
import { Meteor } from 'meteor/meteor';
@@ -119,6 +119,35 @@ const ChatUnfollowMessageLocalSchema = {
119119
additionalProperties: false,
120120
};
121121

122+
//chat.search starts
123+
type ChatSearch = PaginatedRequest<{
124+
roomId: IRoom['_id'];
125+
searchText: string;
126+
}>;
127+
128+
const ChatSearchSchema = {
129+
type: 'object',
130+
properties: {
131+
roomId: {
132+
type: 'string',
133+
},
134+
searchText: {
135+
type: 'string',
136+
},
137+
count: {
138+
type: 'number',
139+
nullable: true,
140+
},
141+
offset: {
142+
type: 'number',
143+
nullable: true,
144+
},
145+
},
146+
required: ['roomId', 'searchText'],
147+
additionalProperties: false,
148+
};
149+
//chat.search ends
150+
122151
const isChatStarMessageLocalProps = ajv.compile<ChatStarMessageLocal>(ChatStarMessageLocalSchema);
123152

124153
const isChatUnstarMessageLocalProps = ajv.compile<ChatUnstarMessageLocal>(ChatUnstarMessageLocalSchema);
@@ -127,6 +156,8 @@ const isChatFollowMessageLocalProps = ajv.compile<ChatFollowMessageLocal>(ChatFo
127156

128157
const isChatUnfollowMessageLocalProps = ajv.compile<ChatUnfollowMessageLocal>(ChatUnfollowMessageLocalSchema);
129158

159+
const isChatSearchLocalProps = ajv.compile<ChatSearch>(ChatSearchSchema);
160+
130161
API.v1.addRoute(
131162
'chat.delete',
132163
{ authRequired: true, validateParams: isChatDeleteProps },
@@ -563,7 +594,7 @@ const chatEndpoints = API.v1
563594
'chat.search',
564595
{
565596
authRequired: true,
566-
query: isChatSearchProps,
597+
query: isChatSearchLocalProps,
567598
response: {
568599
400: validateBadRequestErrorResponse,
569600
401: validateUnauthorizedErrorResponse,

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -323,35 +323,6 @@ const ChatIgnoreUserSchema = {
323323

324324
export const isChatIgnoreUserProps = ajv.compile<ChatIgnoreUser>(ChatIgnoreUserSchema);
325325

326-
type ChatSearch = PaginatedRequest<{
327-
roomId: IRoom['_id'];
328-
searchText: string;
329-
}>;
330-
331-
const ChatSearchSchema = {
332-
type: 'object',
333-
properties: {
334-
roomId: {
335-
type: 'string',
336-
},
337-
searchText: {
338-
type: 'string',
339-
},
340-
count: {
341-
type: 'number',
342-
nullable: true,
343-
},
344-
offset: {
345-
type: 'number',
346-
nullable: true,
347-
},
348-
},
349-
required: ['roomId', 'searchText'],
350-
additionalProperties: false,
351-
};
352-
353-
export const isChatSearchProps = ajv.compile<ChatSearch>(ChatSearchSchema);
354-
355326
interface IChatUpdate {
356327
roomId: IRoom['_id'];
357328
msgId: string;
@@ -933,11 +904,6 @@ export type ChatEndpoints = {
933904
'/v1/chat.ignoreUser': {
934905
GET: (params: ChatIgnoreUser) => void;
935906
};
936-
'/v1/chat.search': {
937-
GET: (params: ChatSearch) => {
938-
messages: IMessage[];
939-
};
940-
};
941907
'/v1/chat.update': {
942908
POST: (params: ChatUpdate) => {
943909
message: IMessage;

0 commit comments

Comments
 (0)