mirror of
https://github.com/plankanban/planka.git
synced 2025-07-23 15:19:44 +02:00
51 lines
1.2 KiB
JavaScript
Executable file
51 lines
1.2 KiB
JavaScript
Executable file
import http from './http';
|
|
import socket from './socket';
|
|
|
|
/* Transformers */
|
|
|
|
export const transformAttachment = (attachment) => ({
|
|
...attachment,
|
|
createdAt: new Date(attachment.createdAt),
|
|
});
|
|
|
|
/* Actions */
|
|
|
|
const createAttachment = (cardId, data, requestId) =>
|
|
http.post(`/cards/${cardId}/attachments?requestId=${requestId}`, data).then((body) => ({
|
|
...body,
|
|
item: transformAttachment(body.item),
|
|
}));
|
|
|
|
const updateAttachment = (id, data) =>
|
|
socket.patch(`/attachments/${id}`, data).then((body) => ({
|
|
...body,
|
|
item: transformAttachment(body.item),
|
|
}));
|
|
|
|
const deleteAttachment = (id) =>
|
|
socket.delete(`/attachments/${id}`).then((body) => ({
|
|
...body,
|
|
item: transformAttachment(body.item),
|
|
}));
|
|
|
|
/* Event handlers */
|
|
|
|
const makeHandleAttachmentCreate = (next) => (body) => {
|
|
next({
|
|
...body,
|
|
item: transformAttachment(body.item),
|
|
});
|
|
};
|
|
|
|
const makeHandleAttachmentUpdate = makeHandleAttachmentCreate;
|
|
|
|
const makeHandleAttachmentDelete = makeHandleAttachmentCreate;
|
|
|
|
export default {
|
|
createAttachment,
|
|
updateAttachment,
|
|
deleteAttachment,
|
|
makeHandleAttachmentCreate,
|
|
makeHandleAttachmentUpdate,
|
|
makeHandleAttachmentDelete,
|
|
};
|