mirror of
https://github.com/plankanban/planka.git
synced 2025-12-26 17:25:03 +03:00
@@ -1,3 +1,8 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
import { attr, fk, oneToOne } from 'redux-orm';
|
||||
|
||||
import BaseModel from './BaseModel';
|
||||
@@ -16,11 +21,25 @@ export default class extends BaseModel {
|
||||
as: 'user',
|
||||
relatedName: 'notifications',
|
||||
}),
|
||||
creatorUserId: fk({
|
||||
to: 'User',
|
||||
as: 'creatorUser',
|
||||
relatedName: 'createdNotifications',
|
||||
}),
|
||||
boardId: fk({
|
||||
to: 'Board',
|
||||
as: 'board',
|
||||
relatedName: 'notifications',
|
||||
}),
|
||||
cardId: fk({
|
||||
to: 'Card',
|
||||
as: 'card',
|
||||
relatedName: 'notifications',
|
||||
}),
|
||||
commentId: oneToOne({
|
||||
to: 'Comment',
|
||||
as: 'comment',
|
||||
}),
|
||||
activityId: oneToOne({
|
||||
to: 'Activity',
|
||||
as: 'activity',
|
||||
@@ -30,11 +49,13 @@ export default class extends BaseModel {
|
||||
static reducer({ type, payload }, Notification) {
|
||||
switch (type) {
|
||||
case ActionTypes.LOCATION_CHANGE_HANDLE:
|
||||
case ActionTypes.USER_UPDATE_HANDLE:
|
||||
case ActionTypes.PROJECT_UPDATE_HANDLE:
|
||||
case ActionTypes.PROJECT_MANAGER_CREATE_HANDLE:
|
||||
case ActionTypes.BOARD_MEMBERSHIP_CREATE_HANDLE:
|
||||
if (payload.deletedNotifications) {
|
||||
payload.deletedNotifications.forEach((notification) => {
|
||||
Notification.withId(notification.id).deleteWithRelated();
|
||||
if (payload.notificationsToDelete) {
|
||||
payload.notificationsToDelete.forEach((notification) => {
|
||||
Notification.withId(notification.id).delete();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,13 +73,27 @@ export default class extends BaseModel {
|
||||
Notification.upsert(notification);
|
||||
});
|
||||
|
||||
break;
|
||||
case ActionTypes.ALL_NOTIFICATIONS_DELETE:
|
||||
Notification.all().delete();
|
||||
|
||||
break;
|
||||
case ActionTypes.ALL_NOTIFICATIONS_DELETE__SUCCESS:
|
||||
payload.notifications.forEach((notification) => {
|
||||
const notificationModel = Notification.withId(notification.id);
|
||||
|
||||
if (notificationModel) {
|
||||
notificationModel.delete();
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATION_CREATE_HANDLE:
|
||||
Notification.upsert(payload.notification);
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATION_DELETE:
|
||||
Notification.withId(payload.id).deleteWithRelated();
|
||||
Notification.withId(payload.id).delete();
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATION_DELETE__SUCCESS:
|
||||
@@ -66,7 +101,7 @@ export default class extends BaseModel {
|
||||
const notificationModel = Notification.withId(payload.notification.id);
|
||||
|
||||
if (notificationModel) {
|
||||
notificationModel.deleteWithRelated();
|
||||
notificationModel.delete();
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -74,15 +109,4 @@ export default class extends BaseModel {
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
deleteRelated() {
|
||||
if (this.action && !this.action.isInCard) {
|
||||
this.action.delete();
|
||||
}
|
||||
}
|
||||
|
||||
deleteWithRelated() {
|
||||
this.deleteRelated();
|
||||
this.delete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user