Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .changeset/migrate-users-getStatus-openapi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/rest-typings": patch
---

Migrates the `users.getStatus` REST API endpoint from the legacy `API.v1.addRoute` pattern to the new chained `API.v1.get()` pattern with AJV response schema validation and OpenAPI documentation support.
73 changes: 41 additions & 32 deletions apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,47 @@ const usersEndpoints = API.v1

return API.v1.success({ suggestions });
},
)
.get(
'users.getStatus',
{
authRequired: true,
response: {
401: validateUnauthorizedErrorResponse,
200: ajv.compile<{
_id?: string;
status: 'online' | 'offline' | 'away' | 'busy';
connectionStatus?: 'online' | 'offline' | 'away' | 'busy';
}>({
Comment on lines +888 to +892
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's the message props?

type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
_id: { type: 'string' },
status: { type: 'string', enum: ['online', 'offline', 'away', 'busy'] },
connectionStatus: { type: 'string', enum: ['online', 'offline', 'away', 'busy'] },
},
required: ['success', 'status'],
additionalProperties: false,
}),
},
},
async function action() {
if (isUserFromParams(this.queryParams, this.userId, this.user)) {
const user: IUser | null = await Users.findOneById(this.userId);
return API.v1.success({
_id: user?._id,
connectionStatus: (user?.statusConnection || 'offline') as 'online' | 'offline' | 'away' | 'busy',
status: (user?.status || 'offline') as 'online' | 'offline' | 'away' | 'busy',
});
}

const user = await getUserFromParams(this.queryParams);

return API.v1.success({
_id: user._id,
status: (user.status || 'offline') as 'online' | 'offline' | 'away' | 'busy',
});
},
);

API.v1.addRoute(
Expand Down Expand Up @@ -1517,38 +1558,6 @@ API.v1.addRoute(
},
);

// status: 'online' | 'offline' | 'away' | 'busy';
// message?: string;
// _id: string;
// connectionStatus?: 'online' | 'offline' | 'away' | 'busy';
// };

API.v1.addRoute(
'users.getStatus',
{ authRequired: true },
{
async get() {
if (isUserFromParams(this.queryParams, this.userId, this.user)) {
const user: IUser | null = await Users.findOneById(this.userId);
return API.v1.success({
_id: user?._id,
// message: user.statusText,
connectionStatus: (user?.statusConnection || 'offline') as 'online' | 'offline' | 'away' | 'busy',
status: (user?.status || 'offline') as 'online' | 'offline' | 'away' | 'busy',
});
}

const user = await getUserFromParams(this.queryParams);

return API.v1.success({
_id: user._id,
// message: user.statusText,
status: (user.status || 'offline') as 'online' | 'offline' | 'away' | 'busy',
});
},
},
);

settings.watch<number>('Rate_Limiter_Limit_RegisterUser', (value) => {
const userRegisterRoute = '/api/v1/users.registerpost';

Expand Down
9 changes: 0 additions & 9 deletions packages/rest-typings/src/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,6 @@ export type UsersEndpoints = {
POST: (params: { message?: string; status?: UserStatus; userId?: string; username?: string; user?: string }) => void;
};

'/v1/users.getStatus': {
GET: () => {
status: 'online' | 'offline' | 'away' | 'busy';
message?: string;
_id?: string;
connectionStatus?: 'online' | 'offline' | 'away' | 'busy';
};
};

'/v1/users.info': {
GET: (params: UsersInfoParamsGet) => {
user: IUser & { rooms?: Pick<ISubscription, 'rid' | 'name' | 't' | 'roles' | 'unread'>[] };
Expand Down