Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notification-service): adds delete APIs for notification and notification users #115

Merged
merged 3 commits into from
Jan 30, 2021
Merged
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
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