import { Task , User , Tag } from './types' ; import { actionCreators } from './base' ; import { makeTask , makeUser , makeStatus , makeTag , makeComment } from './factory' ; export const createUser = ( data ) => { const user = makeUser ( data ) ; return actionCreators . create ( 'user' , user . id , user ) ; } ; export const updateUser = ( id , data ) => { return actionCreators . update ( 'user' , id , data ) ; } ; export const createStatus = ( data ) => { const status = makeStatus ( data ) ; return actionCreators . create ( 'status' , status . id , status ) ; } ; export const updateStatus = ( id , status ) => { return actionCreators . update ( 'status' , id , status ) ; } ; const commentCascade = ( ) => ( { childCommentIds : commentCascade } ) ; export const deleteStatus = ( id ) => { const cascade = { taskIds : { rootCommentIds : { childCommentIds : commentCascade } } } ; return actionCreators . delete ( 'status' , id , cascade ) ; } ; export const createTask = ( data ) => { const task = makeTask ( data ) ; return actionCreators . batch ( actionCreators . create ( 'task' , task . id , task ) , actionCreators . attach ( 'task' , task . id , 'creatorId' , task . creatorId ) , actionCreators . attach ( 'task' , task . id , 'statusId' , task . statusId ) ) ; } ; export const updateTask = ( id , task ) => { return actionCreators . update ( 'task' , id , task ) ; } ; export const deleteTask = ( id ) => { const cascade = { rootCommentIds : { childCommentIds : commentCascade } } ; return actionCreators . delete ( 'task' , id , cascade ) ; } ; export const assignTask = ( taskId , userId ) => { return actionCreators . attach ( 'task' , taskId , 'assigneeId' , userId ) ; } ; export const unassignTask = ( taskId , userId ) => { return actionCreators . detach ( 'task' , taskId , 'assigneeId' , userId ) ; } ; export const createTag = ( data ) => { const tag = makeTag ( data ) ; return actionCreators . create ( 'tag' , tag . id , tag ) ; } ; export const createRootComment = ( data ) => { const comment = makeComment ( data ) ; return actionCreators . batch ( actionCreators . create ( 'comment' , comment . id , comment ) , actionCreators . attach ( 'comment' , comment . id , 'creatorId' , data . creatorId ) , actionCreators . attach ( 'comment' , comment . id , 'taskId' , data . taskId ) ) ; } ; export const createChildComment = ( data ) => { const comment = makeComment ( data ) ; return actionCreators . batch ( actionCreators . create ( 'comment' , comment . id , comment ) , actionCreators . attach ( 'comment' , comment . id , 'creatorId' , data . creatorId ) , actionCreators . attach ( 'comment' , comment . id , 'parentCommentId' , data . parentCommentId ) ) ; } ; export const deleteComment = ( id ) => { const cascade = { childCommentIds : commentCascade } ; return actionCreators . delete ( 'comment' , id , cascade ) ; } ; export const moveStatus = ( src , dest ) => { return actionCreators . move ( 'status' , src , dest ) ; } ; export const moveStatusTask = ( taskId , srcStatusId , src , destStatusId , dest ) => { if ( srcStatusId === destStatusId ) { return actionCreators . moveAttached ( 'status' , srcStatusId , 'taskIds' , src , dest ) ; } else { return actionCreators . attach ( 'status' , destStatusId , 'taskIds' , taskId , { index : dest } ) ; } } ;