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';
|
|
|
|
import { transformCard } from './cards';
|
2022-08-04 13:31:14 +02:00
|
|
|
import { transformActivity } from './activities';
|
|
|
|
|
|
|
|
/* Transformers */
|
|
|
|
|
|
|
|
export const transformNotification = (notification) => ({
|
|
|
|
...omit(notification, 'actionId'),
|
|
|
|
activityId: notification.actionId,
|
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
/* Actions */
|
|
|
|
|
2022-04-26 18:01:55 +05:00
|
|
|
const getNotifications = () =>
|
|
|
|
socket.get('/notifications').then((body) => ({
|
2020-02-03 18:42:31 +05:00
|
|
|
...body,
|
2022-08-04 13:31:14 +02:00
|
|
|
items: body.items.map(transformNotification),
|
2020-02-03 18:42:31 +05:00
|
|
|
included: {
|
2022-08-04 13:31:14 +02:00
|
|
|
...omit(body.included, 'actions'),
|
2020-02-03 18:42:31 +05:00
|
|
|
cards: body.included.cards.map(transformCard),
|
2022-08-04 13:31:14 +02:00
|
|
|
activities: body.included.actions.map(transformActivity),
|
2020-02-03 18:42:31 +05:00
|
|
|
},
|
|
|
|
}));
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-04-26 18:01:55 +05:00
|
|
|
const getNotification = (id) =>
|
|
|
|
socket.get(`/notifications/${id}`).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: {
|
2022-08-04 13:31:14 +02:00
|
|
|
...omit(body.included, 'actions'),
|
2019-08-31 04:07:25 +05:00
|
|
|
cards: body.included.cards.map(transformCard),
|
2022-08-04 13:31:14 +02:00
|
|
|
activities: body.included.actions.map(transformActivity),
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
}));
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
const updateNotifications = (ids, data) =>
|
|
|
|
socket.patch(`/notifications/${ids.join(',')}`, data).then((body) => ({
|
|
|
|
...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,
|
2021-06-24 01:05:22 +05:00
|
|
|
getNotification,
|
2019-08-31 04:07:25 +05:00
|
|
|
updateNotifications,
|
2022-08-04 13:31:14 +02:00
|
|
|
makeHandleNotificationCreate,
|
|
|
|
makeHandleNotificationUpdate,
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|