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
if(!token) return res.status(401).send({Message:'token not exists'})
req.body={...req.body,executorStatus:false}
req.body={...req.body,authorStatus:false}
const executor = await dataSource
.createQueryBuilder()
.select("user")
......
......@@ -43,23 +43,24 @@ router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Resp
} )
/** change date time of copy of task in calendar view */
router.put("change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
const {executorStatus,dateTimeTaskId,taskId, start, due} = req.body
if (executorStatus){
router.put("/change-copy", async(req:Request, res: Response):Promise<Response>=>{
console.log('change')
const {dateTimeTaskId,taskId, dateTimeStart, dateTimeDue} = req.body
console.log(req.body)
const dateTimeTask = await dataSource
.createQueryBuilder()
.select('dateTikeTask')
.select('dateTimeTask')
.from(DateTimeTask,'dateTimeTask')
.where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId})
.getOne()
if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"})
dateTimeTask.dateTimeStart=start
dateTimeTask.dateTimeDue=due
dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue
console.log(dateTimeTask)
await dateTimeTask.save()
const task = taskFinderById(taskId)
return res.send({task})
}
return res.send({message :"Something wrong in make-copy router"})
})
export default router;
......@@ -25,7 +25,7 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
/**create new task */
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();
newTask.title = title;
newTask.description = description;
......@@ -35,6 +35,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
newTask.executor= executor;
newTask.priority = priority;
await newTask.save();
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStart
newDateTimeTask.dateTimeDue = dateTimeDue
newDateTimeTask.task = newTask
await newDateTimeTask.save()
return res.send({newTask});
})
......
......@@ -153,11 +153,13 @@ function MonthCalendar() {
const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, day, timeStartHour, 0))
const newTask = {
...currentTask,
dateTimeTaskId: currentTask.id,
dateTimeStart: start,
dateTimeDue: due
}
delete newTask.id
delete newTask.infoForCell
if (currentTask.id) {
if (newTask.dateTimeTaskId) {
await dispatch(editCalendarTask(newTask))
} else {
await dispatch(addCalendarTask(newTask))
......
......@@ -74,9 +74,10 @@ export const addCalendarTask = (task) => {
return async (dispatch, getState) => {
dispatch(addTaskRequest());
try {
await axios.post("/tasks", task);
const response = await axios.post("/tasks", task);
dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks())
console.log(response.data)
} catch (error) {
dispatch(addTaskFailure(error.response.data));
}
......@@ -84,7 +85,20 @@ export const addCalendarTask = (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());
try {
await axios.post("/tasks", task);
......@@ -112,7 +126,7 @@ export const editTask = (task) => {
return async (dispatch, getState) => {
dispatch(editTaskRequest());
try {
await axios.put("/tasks", task);
await axios.put("/change-copy", task);
dispatch(editTaskSuccess())
dispatch(fetchAllTasks())
} catch (error) {
......@@ -125,7 +139,7 @@ export const editCalendarTask = (task) => {
return async (dispatch, getState) => {
dispatch(editTaskRequest());
try {
await axios.put("/tasks", task);
await axios.put("/copy-tasks/change-copy", task);
dispatch(editTaskSuccess())
dispatch(fetchCalendarTasks())
} catch (error) {
......
......@@ -29,8 +29,21 @@ const tasksReduсer = (state = initialState, action) => {
case FETCH_CALENDAR_TASKS_REQUEST:
return {...state, loading: true};
case FETCH_CALENDAR_TASKS_SUCCESS:
const newArr = []
action.tasks.forEach((task)=>{
const newTasksWithoutInfoForCell = []
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 (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) &&
new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) {
......@@ -55,11 +68,11 @@ const tasksReduсer = (state = initialState, action) => {
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:
return {...state, loading: false, tasks: action.tasks};
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