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
const dateTimeTask = await dataSource console.log(req.body)
.createQueryBuilder() const dateTimeTask = await dataSource
.select('dateTikeTask') .createQueryBuilder()
.from(DateTimeTask,'dateTimeTask') .select('dateTimeTask')
.where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId}) .from(DateTimeTask,'dateTimeTask')
.getOne() .where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId})
if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"}) .getOne()
dateTimeTask.dateTimeStart=start if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"})
dateTimeTask.dateTimeDue=due dateTimeTask.dateTimeStart=dateTimeStart
await dateTimeTask.save() dateTimeTask.dateTimeDue=dateTimeDue
const task = taskFinderById(taskId) console.log(dateTimeTask)
return res.send({task}) await dateTimeTask.save()
} const task = taskFinderById(taskId)
return res.send({message :"Something wrong in make-copy router"}) return res.send({task})
}) })
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;
...@@ -34,7 +34,12 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ ...@@ -34,7 +34,12 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
newTask.author= user; newTask.author= user;
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,37 +29,50 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -29,37 +29,50 @@ 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 = []
if (task.dateTimeStart && task.dateTimeDue) { for (let task of action.tasks) {
if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) && for (let copy of task.dateTimeTasks) {
new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) { newTasksWithoutInfoForCell.push({
const dateStart = task.dateTimeStart.split('T')[0] ...copy,
const timeStart = task.dateTimeStart.split('T')[1] executor: task.executor,
const timeEnd = task.dateTimeDue.split('T')[1] author: task.author,
const dayStart = parseInt(dateStart.split('-')[2]) priority: task.priority,
const monthStartNumber = parseInt(dateStart.split('-')[1]) title: task.title,
const yearStartNumber = parseInt(dateStart.split('-')[0]) description: task.description
const timeStartHour = parseInt(timeStart.split(':')[0])
const timeEndHour = parseInt(timeEnd.split(':')[0])
const timeStartMinute = parseInt(timeStart.split(':')[1])
const timeEndMinute = parseInt(timeEnd.split(':')[1])
const newObj = {...task,
infoForCell: {
startDay: dayStart,
startHour: timeStartHour,
startMonth: monthStartNumber,
startYear: yearStartNumber,
startMinute: timeStartMinute,
endHour: timeEndHour,
endMinute: timeEndMinute,
}
}
newArr.push(newObj)
}
}
}) })
return {...state, loading: false, calendarTasks: newArr}; }
}
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) {
const dateStart = task.dateTimeStart.split('T')[0]
const timeStart = task.dateTimeStart.split('T')[1]
const timeEnd = task.dateTimeDue.split('T')[1]
const dayStart = parseInt(dateStart.split('-')[2])
const monthStartNumber = parseInt(dateStart.split('-')[1])
const yearStartNumber = parseInt(dateStart.split('-')[0])
const timeStartHour = parseInt(timeStart.split(':')[0])
const timeEndHour = parseInt(timeEnd.split(':')[0])
const timeStartMinute = parseInt(timeStart.split(':')[1])
const timeEndMinute = parseInt(timeEnd.split(':')[1])
const newObj = {...task,
infoForCell: {
startDay: dayStart,
startHour: timeStartHour,
startMonth: monthStartNumber,
startYear: yearStartNumber,
startMinute: timeStartMinute,
endHour: timeEndHour,
endMinute: timeEndMinute,
}
}
newTasksWithInfoForCell.push(newObj)
}
}
})
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