mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
Initial commit
This commit is contained in:
commit
36fe34e8e1
583 changed files with 91539 additions and 0 deletions
60
client/src/models/Notification.js
Executable file
60
client/src/models/Notification.js
Executable file
|
@ -0,0 +1,60 @@
|
|||
import { Model, attr, fk } from 'redux-orm';
|
||||
|
||||
import ActionTypes from '../constants/ActionTypes';
|
||||
|
||||
export default class extends Model {
|
||||
static modelName = 'Notification';
|
||||
|
||||
static fields = {
|
||||
id: attr(),
|
||||
type: attr(),
|
||||
data: attr(),
|
||||
isRead: attr(),
|
||||
userId: fk({
|
||||
to: 'User',
|
||||
as: 'user',
|
||||
relatedName: 'notifications',
|
||||
}),
|
||||
actionId: fk({
|
||||
to: 'Action',
|
||||
as: 'action',
|
||||
relatedName: 'notifications',
|
||||
}),
|
||||
cardId: fk({
|
||||
to: 'Card',
|
||||
as: 'card',
|
||||
relatedName: 'notifications',
|
||||
}),
|
||||
};
|
||||
|
||||
static reducer({ type, payload }, Notification) {
|
||||
switch (type) {
|
||||
case ActionTypes.NOTIFICATIONS_DELETE:
|
||||
payload.ids.forEach((id) => {
|
||||
Notification.withId(id).delete();
|
||||
});
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATIONS_FETCH_SUCCEEDED:
|
||||
payload.notifications.forEach((notification) => {
|
||||
Notification.upsert(notification);
|
||||
});
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATION_CREATE_RECEIVED:
|
||||
Notification.upsert(payload.notification);
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATION_DELETE_RECEIVED: {
|
||||
const notificationModel = Notification.withId(payload.notification.id);
|
||||
|
||||
if (notificationModel) {
|
||||
notificationModel.delete();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue