Commit 923dc0c1 authored by Ermolaev Timur's avatar Ermolaev Timur

#78 Реализовал отображение и редактирования времени задач

parent ef9b5054
...@@ -27,7 +27,6 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next ...@@ -27,7 +27,6 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
if(!token) return res.status(401).send({Message:'token not exists'}) if(!token) return res.status(401).send({Message:'token not exists'})
req.body={...req.body,executorStatus:false} req.body={...req.body,executorStatus:false}
req.body={...req.body,authorStatus:false} req.body={...req.body,authorStatus:false}
const executor = await dataSource const executor = await dataSource
.createQueryBuilder() .createQueryBuilder()
.select("user") .select("user")
......
...@@ -43,23 +43,24 @@ router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Resp ...@@ -43,23 +43,24 @@ router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Resp
} ) } )
/** change date time of copy of task in calendar view */ /** change date time of copy of task in calendar view */
router.put("change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{ router.put("/change-copy", async(req:Request, res: Response):Promise<Response>=>{
const {executorStatus,dateTimeTaskId,taskId, start, due} = req.body console.log('change')
if (executorStatus){ const {dateTimeTaskId,taskId, dateTimeStart, dateTimeDue} = req.body
console.log(req.body)
const dateTimeTask = await dataSource const dateTimeTask = await dataSource
.createQueryBuilder() .createQueryBuilder()
.select('dateTikeTask') .select('dateTimeTask')
.from(DateTimeTask,'dateTimeTask') .from(DateTimeTask,'dateTimeTask')
.where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId}) .where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId})
.getOne() .getOne()
if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"}) if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"})
dateTimeTask.dateTimeStart=start dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=due dateTimeTask.dateTimeDue=dateTimeDue
console.log(dateTimeTask)
await dateTimeTask.save() await dateTimeTask.save()
const task = taskFinderById(taskId) const task = taskFinderById(taskId)
return res.send({task}) return res.send({task})
}
return res.send({message :"Something wrong in make-copy router"})
}) })
export default router; export default router;
...@@ -25,7 +25,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => { ...@@ -25,7 +25,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
/**create new task */ /**create new task */
router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
const {user,title,description,project,executor, dateTimeDeadLine,priority} = req.body; const {user,title,description,project,executor, dateTimeDeadLine,priority, dateTimeStart, dateTimeDue} = req.body;
const newTask = new Task(); const newTask = new Task();
newTask.title = title; newTask.title = title;
newTask.description = description; newTask.description = description;
...@@ -35,6 +35,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ ...@@ -35,6 +35,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
newTask.executor= executor; newTask.executor= executor;
newTask.priority = priority; newTask.priority = priority;
await newTask.save(); await newTask.save();
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStart
newDateTimeTask.dateTimeDue = dateTimeDue
newDateTimeTask.task = newTask
await newDateTimeTask.save()
return res.send({newTask}); return res.send({newTask});
}) })
......
...@@ -153,11 +153,13 @@ function MonthCalendar() { ...@@ -153,11 +153,13 @@ function MonthCalendar() {
const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, day, timeStartHour, 0)) const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, day, timeStartHour, 0))
const newTask = { const newTask = {
...currentTask, ...currentTask,
dateTimeTaskId: currentTask.id,
dateTimeStart: start, dateTimeStart: start,
dateTimeDue: due dateTimeDue: due
} }
delete newTask.id
delete newTask.infoForCell delete newTask.infoForCell
if (currentTask.id) { if (newTask.dateTimeTaskId) {
await dispatch(editCalendarTask(newTask)) await dispatch(editCalendarTask(newTask))
} else { } else {
await dispatch(addCalendarTask(newTask)) await dispatch(addCalendarTask(newTask))
......
...@@ -74,9 +74,10 @@ export const addCalendarTask = (task) => { ...@@ -74,9 +74,10 @@ export const addCalendarTask = (task) => {
return async (dispatch, getState) => { return async (dispatch, getState) => {
dispatch(addTaskRequest()); dispatch(addTaskRequest());
try { try {
await axios.post("/tasks", task); const response = await axios.post("/tasks", task);
dispatch(addTaskSuccess()) dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks()) dispatch(fetchCalendarTasks())
console.log(response.data)
} catch (error) { } catch (error) {
dispatch(addTaskFailure(error.response.data)); dispatch(addTaskFailure(error.response.data));
} }
...@@ -84,7 +85,20 @@ export const addCalendarTask = (task) => { ...@@ -84,7 +85,20 @@ export const addCalendarTask = (task) => {
} }
export const addTask = (task) => { export const addTask = (task) => {
return async (dispatch, getState) => { return async (dispatch) => {
dispatch(addTaskRequest());
try {
await axios.post("/tasks", task);
dispatch(addTaskSuccess())
dispatch(fetchAllTasks())
} catch (error) {
dispatch(addTaskFailure(error.response.data));
}
}
}
export const addCopyTask = (task) => {
return async (dispatch) => {
dispatch(addTaskRequest()); dispatch(addTaskRequest());
try { try {
await axios.post("/tasks", task); await axios.post("/tasks", task);
...@@ -112,7 +126,7 @@ export const editTask = (task) => { ...@@ -112,7 +126,7 @@ export const editTask = (task) => {
return async (dispatch, getState) => { return async (dispatch, getState) => {
dispatch(editTaskRequest()); dispatch(editTaskRequest());
try { try {
await axios.put("/tasks", task); await axios.put("/change-copy", task);
dispatch(editTaskSuccess()) dispatch(editTaskSuccess())
dispatch(fetchAllTasks()) dispatch(fetchAllTasks())
} catch (error) { } catch (error) {
...@@ -125,7 +139,7 @@ export const editCalendarTask = (task) => { ...@@ -125,7 +139,7 @@ export const editCalendarTask = (task) => {
return async (dispatch, getState) => { return async (dispatch, getState) => {
dispatch(editTaskRequest()); dispatch(editTaskRequest());
try { try {
await axios.put("/tasks", task); await axios.put("/copy-tasks/change-copy", task);
dispatch(editTaskSuccess()) dispatch(editTaskSuccess())
dispatch(fetchCalendarTasks()) dispatch(fetchCalendarTasks())
} catch (error) { } catch (error) {
......
...@@ -29,8 +29,21 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -29,8 +29,21 @@ const tasksReduсer = (state = initialState, action) => {
case FETCH_CALENDAR_TASKS_REQUEST: case FETCH_CALENDAR_TASKS_REQUEST:
return {...state, loading: true}; return {...state, loading: true};
case FETCH_CALENDAR_TASKS_SUCCESS: case FETCH_CALENDAR_TASKS_SUCCESS:
const newArr = [] const newTasksWithoutInfoForCell = []
action.tasks.forEach((task)=>{ const newTasksWithInfoForCell = []
for (let task of action.tasks) {
for (let copy of task.dateTimeTasks) {
newTasksWithoutInfoForCell.push({
...copy,
executor: task.executor,
author: task.author,
priority: task.priority,
title: task.title,
description: task.description
})
}
}
newTasksWithoutInfoForCell.forEach((task)=>{
if (task.dateTimeStart && task.dateTimeDue) { if (task.dateTimeStart && task.dateTimeDue) {
if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) && if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) &&
new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) { new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) {
...@@ -55,11 +68,11 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -55,11 +68,11 @@ const tasksReduсer = (state = initialState, action) => {
endMinute: timeEndMinute, endMinute: timeEndMinute,
} }
} }
newArr.push(newObj) newTasksWithInfoForCell.push(newObj)
} }
} }
}) })
return {...state, loading: false, calendarTasks: newArr}; return {...state, loading: false, calendarTasks: newTasksWithInfoForCell};
case FETCH_ALL_TASKS_SUCCESS: case FETCH_ALL_TASKS_SUCCESS:
return {...state, loading: false, tasks: action.tasks}; return {...state, loading: false, tasks: action.tasks};
case FETCH_CALENDAR_TASKS_FAILURE: case FETCH_CALENDAR_TASKS_FAILURE:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment