Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
72 changes: 48 additions & 24 deletions apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,30 +285,54 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'rooms.saveNotification',
{ authRequired: true },
{
async post() {
const { roomId, notifications } = this.bodyParams;

if (!roomId) {
return API.v1.failure("The 'roomId' param is required");
}

if (!notifications || Object.keys(notifications).length === 0) {
return API.v1.failure("The 'notifications' param is required");
}

await Promise.all(
Object.entries(notifications as Notifications).map(async ([notificationKey, notificationValue]) =>
saveNotificationSettingsMethod(this.userId, roomId, notificationKey as NotificationFieldType, notificationValue),
),
);

return API.v1.success();
},
},
const saveNotificationBodySchema = ajv.compile<{
roomId: string;
notifications: Record<string, string>;
}>({
type: 'object',
properties: {
roomId: { type: 'string' },
notifications: {
type: 'object',
minProperties: 1,
additionalProperties: { type: 'string' },
},
},
required: ['roomId', 'notifications'],
additionalProperties: false,
});

const saveNotificationResponseSchema = ajv.compile({
type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
},
required: ['success'],
additionalProperties: false,
});

export const roomsSaveNotificationEndpoint = API.v1.post(
'rooms.saveNotification',
{
authRequired: true,
body: saveNotificationBodySchema,
response: {
200: saveNotificationResponseSchema,
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
},
},
async function action() {
const { roomId, notifications } = this.bodyParams;

await Promise.all(
Object.entries(notifications as Notifications).map(async ([notificationKey, notificationValue]) =>
saveNotificationSettingsMethod(this.userId, roomId, notificationKey as NotificationFieldType, notificationValue),
),
);

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

API.v1.addRoute(
Expand Down
3 changes: 0 additions & 3 deletions packages/rest-typings/src/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,7 @@
}) => { message: IMessage | null };
};

'/v1/rooms.saveNotification': {
POST: (params: { roomId: string; notifications: Notifications }) => void;
};

Check failure on line 803 in packages/rest-typings/src/v1/rooms.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Delete `⏎`
'/v1/rooms.nameExists': {
GET: (params: { roomName: string }) => {
exists: boolean;
Expand Down
Loading