Skip to content

Commit

Permalink
feat(notification-service): adds delete APIs for notification and not…
Browse files Browse the repository at this point in the history
…ification users (#115)
  • Loading branch information
vineet-suri authored Jan 30, 2021
1 parent c96e0af commit 2462bd6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class NotificationUserController {
@authenticate(STRATEGY.BEARER, {
passReqToCallback: true,
})
@authorize({permissions: [PermissionKey.ViewNotification]})
@authorize({permissions: [PermissionKey.DeleteNotification]})
@del(`${basePath}/{id}`, {
responses: {
'204': {
Expand All @@ -291,6 +291,28 @@ export class NotificationUserController {
await this.notificationUserRepository.deleteById(id);
}

@authenticate(STRATEGY.BEARER, {
passReqToCallback: true,
})
@authorize({permissions: [PermissionKey.DeleteNotification]})
@del(basePath, {
responses: {
[STATUS_CODE.NO_CONTENT]: {
description: 'Notification DELETE success',
},
},
})
async deleteAll(
@inject(AuthenticationBindings.CURRENT_USER)
currentUser: IAuthUserWithPermissions,
@param.query.object('where', getWhereSchemaFor(NotificationUser))
where?: Where<NotificationUser>,
): Promise<Count> {
return this.notificationUserRepository.deleteAll(
this._createWhereBuilder(currentUser, where).build(),
);
}

private async _verifyOwned(
id: string,
currentUser: IAuthUserWithPermissions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Where,
} from '@loopback/repository';
import {
del,
get,
getFilterSchemaFor,
getModelSchemaRef,
Expand All @@ -29,6 +30,7 @@ import {
NotificationUserRepository,
} from '../repositories';
import {INotificationUserManager} from '../types';
const basePath = '/notifications';

const maxBodyLen = 1000;
export class NotificationController {
Expand All @@ -45,7 +47,7 @@ export class NotificationController {

@authenticate(STRATEGY.BEARER)
@authorize({permissions: [PermissionKey.CreateNotification]})
@post('/notifications', {
@post(basePath, {
responses: {
[STATUS_CODE.OK]: {
description: 'Notification model instance',
Expand Down Expand Up @@ -82,7 +84,7 @@ export class NotificationController {

@authenticate(STRATEGY.BEARER)
@authorize({permissions: [PermissionKey.CreateNotification]})
@post('/notifications/bulk', {
@post(`${basePath}/bulk`, {
responses: {
[STATUS_CODE.OK]: {
description: 'Array of Notifications',
Expand Down Expand Up @@ -132,7 +134,7 @@ export class NotificationController {

@authenticate(STRATEGY.BEARER)
@authorize({permissions: [PermissionKey.ViewNotification]})
@get('/notifications/count', {
@get(`${basePath}/count`, {
responses: {
[STATUS_CODE.OK]: {
description: 'Notification model count',
Expand All @@ -149,7 +151,7 @@ export class NotificationController {

@authenticate(STRATEGY.BEARER)
@authorize({permissions: ['*']})
@get('/notifications', {
@get(basePath, {
responses: {
[STATUS_CODE.OK]: {
description: 'Array of Notification model instances',
Expand All @@ -170,7 +172,7 @@ export class NotificationController {

@authenticate(STRATEGY.BEARER)
@authorize({permissions: [PermissionKey.ViewNotification]})
@get('/notifications/{id}', {
@get(`${basePath}/{id}`, {
responses: {
[STATUS_CODE.OK]: {
description: 'Notification model instance',
Expand All @@ -184,6 +186,22 @@ export class NotificationController {
return this.notificationRepository.findById(id);
}

@authenticate(STRATEGY.BEARER)
@authorize({permissions: [PermissionKey.DeleteNotification]})
@del(basePath, {
responses: {
[STATUS_CODE.NO_CONTENT]: {
description: 'Notification DELETE success',
},
},
})
async deleteAll(
@param.query.object('where', getWhereSchemaFor(Notification))
where?: Where<Notification>,
): Promise<Count> {
return this.notificationRepository.deleteAll(where);
}

createNotifUsers(notif: Notification) {
if (!notif.receiver || !notif.receiver.to) {
throw new HttpErrors.UnprocessableEntity(ErrorKeys.ReceiverNotFound);
Expand Down

0 comments on commit 2462bd6

Please sign in to comment.