|
1 | 1 | import { Presence } from '@rocket.chat/core-services'; |
| 2 | +import { ajv, validateUnauthorizedErrorResponse, validateForbiddenErrorResponse } from '@rocket.chat/rest-typings'; |
2 | 3 |
|
3 | 4 | import { API } from '../api'; |
4 | 5 |
|
5 | | -API.v1.addRoute( |
| 6 | +API.v1.get( |
6 | 7 | 'presence.getConnections', |
7 | | - { authRequired: true, permissionsRequired: ['manage-user-status'] }, |
8 | 8 | { |
9 | | - async get() { |
10 | | - const result = await Presence.getConnectionCount(); |
11 | | - |
12 | | - return API.v1.success(result); |
| 9 | + authRequired: true, |
| 10 | + permissionsRequired: ['manage-user-status'], |
| 11 | + response: { |
| 12 | + 200: ajv.compile<{ current: number; max: number; success: true }>({ |
| 13 | + type: 'object', |
| 14 | + properties: { |
| 15 | + current: { type: 'number' }, |
| 16 | + max: { type: 'number' }, |
| 17 | + success: { |
| 18 | + type: 'boolean', |
| 19 | + enum: [true], |
| 20 | + }, |
| 21 | + }, |
| 22 | + required: ['current', 'max', 'success'], |
| 23 | + additionalProperties: false, |
| 24 | + }), |
| 25 | + 401: validateUnauthorizedErrorResponse, |
| 26 | + 403: validateForbiddenErrorResponse, |
13 | 27 | }, |
14 | 28 | }, |
| 29 | + async function action() { |
| 30 | + const result = await Presence.getConnectionCount(); |
| 31 | + |
| 32 | + return API.v1.success(result); |
| 33 | + }, |
15 | 34 | ); |
16 | 35 |
|
17 | | -API.v1.addRoute( |
| 36 | +API.v1.post( |
18 | 37 | 'presence.enableBroadcast', |
19 | | - { authRequired: true, permissionsRequired: ['manage-user-status'], twoFactorRequired: true }, |
20 | 38 | { |
21 | | - async post() { |
22 | | - await Presence.toggleBroadcast(true); |
23 | | - |
24 | | - return API.v1.success(); |
| 39 | + authRequired: true, |
| 40 | + permissionsRequired: ['manage-user-status'], |
| 41 | + twoFactorRequired: true, |
| 42 | + response: { |
| 43 | + 200: ajv.compile<{ success: true }>({ |
| 44 | + type: 'object', |
| 45 | + properties: { |
| 46 | + success: { |
| 47 | + type: 'boolean', |
| 48 | + enum: [true], |
| 49 | + }, |
| 50 | + }, |
| 51 | + required: ['success'], |
| 52 | + additionalProperties: false, |
| 53 | + }), |
| 54 | + 401: validateUnauthorizedErrorResponse, |
| 55 | + 403: validateForbiddenErrorResponse, |
25 | 56 | }, |
26 | 57 | }, |
| 58 | + async function action() { |
| 59 | + await Presence.toggleBroadcast(true); |
| 60 | + |
| 61 | + return API.v1.success({}); |
| 62 | + }, |
27 | 63 | ); |
0 commit comments