1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-08-01 19:45:26 +02:00

ref: Refactoring

This commit is contained in:
Maksim Eltyshev 2022-08-04 13:31:14 +02:00
parent aa4723d7fe
commit 3f8216dca8
189 changed files with 3781 additions and 3486 deletions

View file

@ -1,36 +0,0 @@
import socket from './socket';
/* Transformers */
export const transformAction = (action) => ({
...action,
createdAt: new Date(action.createdAt),
});
/* Actions */
const getActions = (cardId, data) =>
socket.get(`/cards/${cardId}/actions`, data).then((body) => ({
...body,
items: body.items.map(transformAction),
}));
/* Event handlers */
const makeHandleActionCreate = (next) => (body) => {
next({
...body,
item: transformAction(body.item),
});
};
const makeHandleActionUpdate = makeHandleActionCreate;
const makeHandleActionDelete = makeHandleActionCreate;
export default {
getActions,
makeHandleActionCreate,
makeHandleActionUpdate,
makeHandleActionDelete,
};

36
client/src/api/activities.js Executable file
View file

@ -0,0 +1,36 @@
import socket from './socket';
/* Transformers */
export const transformActivity = (activity) => ({
...activity,
createdAt: new Date(activity.createdAt),
});
/* Actions */
const getActivities = (cardId, data) =>
socket.get(`/cards/${cardId}/actions`, data).then((body) => ({
...body,
items: body.items.map(transformActivity),
}));
/* Event handlers */
const makeHandleActivityCreate = (next) => (body) => {
next({
...body,
item: transformActivity(body.item),
});
};
const makeHandleActivityUpdate = makeHandleActivityCreate;
const makeHandleActivityDelete = makeHandleActivityCreate;
export default {
getActivities,
makeHandleActivityCreate,
makeHandleActivityUpdate,
makeHandleActivityDelete,
};

View file

@ -78,14 +78,9 @@ const makeHandleCardCreate = (next) => (body) => {
});
};
const makeHandleCardUpdate = (next) => (body) => {
next({
...body,
item: transformCard(body.item),
});
};
const makeHandleCardUpdate = makeHandleCardCreate;
const makeHandleCardDelete = makeHandleCardUpdate;
const makeHandleCardDelete = makeHandleCardCreate;
export default {
getCards,

View file

@ -1,28 +0,0 @@
import socket from './socket';
import { transformAction } from './actions';
/* Actions */
const createCommentAction = (cardId, data) =>
socket.post(`/cards/${cardId}/comment-actions`, data).then((body) => ({
...body,
item: transformAction(body.item),
}));
const updateCommentAction = (id, data) =>
socket.patch(`/comment-actions/${id}`, data).then((body) => ({
...body,
item: transformAction(body.item),
}));
const deleteCommentAction = (id) =>
socket.delete(`/comment-actions/${id}`).then((body) => ({
...body,
item: transformAction(body.item),
}));
export default {
createCommentAction,
updateCommentAction,
deleteCommentAction,
};

View file

@ -0,0 +1,28 @@
import socket from './socket';
import { transformActivity } from './activities';
/* Actions */
const createCommentActivity = (cardId, data) =>
socket.post(`/cards/${cardId}/comment-actions`, data).then((body) => ({
...body,
item: transformActivity(body.item),
}));
const updateCommentActivity = (id, data) =>
socket.patch(`/comment-actions/${id}`, data).then((body) => ({
...body,
item: transformActivity(body.item),
}));
const deleteCommentActivity = (id) =>
socket.delete(`/comment-actions/${id}`).then((body) => ({
...body,
item: transformActivity(body.item),
}));
export default {
createCommentActivity,
updateCommentActivity,
deleteCommentActivity,
};

View file

@ -13,8 +13,8 @@ import cardMemberships from './card-memberships';
import cardLabels from './card-labels';
import tasks from './tasks';
import attachments from './attachments';
import actions from './actions';
import commentActions from './comment-actions';
import activities from './activities';
import commentActivities from './comment-activities';
import notifications from './notifications';
export { http, socket };
@ -33,7 +33,7 @@ export default {
...cardLabels,
...tasks,
...attachments,
...actions,
...commentActions,
...activities,
...commentActivities,
...notifications,
};

View file

@ -1,33 +1,61 @@
import omit from 'lodash/omit';
import socket from './socket';
import { transformCard } from './cards';
import { transformAction } from './actions';
import { transformActivity } from './activities';
/* Transformers */
export const transformNotification = (notification) => ({
...omit(notification, 'actionId'),
activityId: notification.actionId,
});
/* Actions */
const getNotifications = () =>
socket.get('/notifications').then((body) => ({
...body,
items: body.items.map(transformNotification),
included: {
...body.included,
...omit(body.included, 'actions'),
cards: body.included.cards.map(transformCard),
actions: body.included.actions.map(transformAction),
activities: body.included.actions.map(transformActivity),
},
}));
const getNotification = (id) =>
socket.get(`/notifications/${id}`).then((body) => ({
...body,
item: transformNotification(body.item),
included: {
...body.included,
...omit(body.included, 'actions'),
cards: body.included.cards.map(transformCard),
actions: body.included.actions.map(transformAction),
activities: body.included.actions.map(transformActivity),
},
}));
const updateNotifications = (ids, data) => socket.patch(`/notifications/${ids.join(',')}`, data);
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;
export default {
getNotifications,
getNotification,
updateNotifications,
makeHandleNotificationCreate,
makeHandleNotificationUpdate,
};