From 2c20508c3499a89f2f3948fadb427ca19d6db39f Mon Sep 17 00:00:00 2001 From: vineet-suri <49708329+vineet-suri@users.noreply.github.com> Date: Wed, 19 May 2021 12:24:52 +0530 Subject: [PATCH] fix(notification-service): adds PATCH notification APIs (#213) RFIT-1632 --- .../controllers/notification.controller.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/services/notification-service/src/controllers/notification.controller.ts b/services/notification-service/src/controllers/notification.controller.ts index 694621f2a2..9f96d652f1 100644 --- a/services/notification-service/src/controllers/notification.controller.ts +++ b/services/notification-service/src/controllers/notification.controller.ts @@ -14,6 +14,7 @@ import { getWhereSchemaFor, HttpErrors, param, + patch, post, requestBody, } from '@loopback/rest'; @@ -186,6 +187,58 @@ export class NotificationController { return this.notificationRepository.findById(id); } + @authenticate(STRATEGY.BEARER, { + passReqToCallback: true, + }) + @authorize({permissions: [PermissionKey.UpdateNotification]}) + @patch(basePath, { + responses: { + [STATUS_CODE.OK]: { + description: 'Notification PATCH success count', + content: {[CONTENT_TYPE.JSON]: {schema: CountSchema}}, + }, + }, + }) + async updateAll( + @requestBody({ + content: { + [CONTENT_TYPE.JSON]: { + schema: getModelSchemaRef(Notification, {partial: true}), + }, + }, + }) + notification: Notification, + @param.query.object('where', getWhereSchemaFor(Notification)) + where?: Where, + ): Promise { + return this.notificationRepository.updateAll(notification, where); + } + + @authenticate(STRATEGY.BEARER, { + passReqToCallback: true, + }) + @authorize({permissions: [PermissionKey.UpdateNotification]}) + @patch(`${basePath}/{id}`, { + responses: { + '204': { + description: 'Notification PATCH success', + }, + }, + }) + async updateById( + @param.path.string('id') id: string, + @requestBody({ + content: { + [CONTENT_TYPE.JSON]: { + schema: getModelSchemaRef(Notification, {partial: true}), + }, + }, + }) + notification: Notification, + ): Promise { + await this.notificationRepository.updateById(id, notification); + } + @authenticate(STRATEGY.BEARER) @authorize({permissions: [PermissionKey.DeleteNotification]}) @del(basePath, {