1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-22 14:49:43 +02:00
planka/client/src/api/notifications.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
2022-08-04 13:31:14 +02:00
import omit from 'lodash/omit';
2019-08-31 04:07:25 +05:00
import socket from './socket';
2022-08-04 13:31:14 +02:00
/* Transformers */
export const transformNotification = (notification) => ({
...(notification.actionId
? {
...omit(notification, 'actionId'),
activityId: notification.actionId,
}
: notification),
2022-08-04 13:31:14 +02:00
});
2019-08-31 04:07:25 +05:00
/* Actions */
const getNotifications = (headers) =>
socket.get('/notifications', undefined, headers).then((body) => ({
...body,
2022-08-04 13:31:14 +02:00
items: body.items.map(transformNotification),
}));
2019-08-31 04:07:25 +05:00
/* const getNotification = (id, headers) =>
socket.get(`/notifications/${id}`, undefined, headers).then((body) => ({
2019-08-31 04:07:25 +05:00
...body,
2022-08-04 13:31:14 +02:00
item: transformNotification(body.item),
2019-08-31 04:07:25 +05:00
included: {
users: body.included.users.map(transformUser),
2019-08-31 04:07:25 +05:00
},
})); */
const updateNotification = (id, data, headers) =>
socket.patch(`/notifications/${id}`, data, headers).then((body) => ({
...body,
item: transformNotification(body.item),
}));
const readAllNotifications = (headers) =>
socket.post('/notifications/read-all', undefined, headers).then((body) => ({
2022-08-04 13:31:14 +02:00
...body,
items: body.items.map(transformNotification),
}));
/* Event handlers */
const makeHandleNotificationCreate = (next) => (body) => {
next({
...body,
item: transformNotification(body.item),
});
};
const makeHandleNotificationUpdate = makeHandleNotificationCreate;
2019-08-31 04:07:25 +05:00
export default {
getNotifications,
// getNotification,
updateNotification,
readAllNotifications,
2022-08-04 13:31:14 +02:00
makeHandleNotificationCreate,
makeHandleNotificationUpdate,
2019-08-31 04:07:25 +05:00
};