Merge branch 'task-168-enhance/tree_to_one_request_week_calendar' into 'development'

Task 168 enhance/tree to one request week calendar

See merge request !136
parents dffb6345 99985584
......@@ -395,4 +395,67 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
})
/**router GET "/week-data-start/{userId}` which receives user through req.body.user,
* returns list of Task related to the userId,
* object with key displayName related to userId, list of Project related to user
*/
router.get('/week-data-start/:userId',auth, async (req: Request, res: Response):Promise<Response>=>{
console.log('week-data-start')
const {userId} = req.params
try{
const requesterUser= req.body.user
const user = await dataSource
.getRepository(User)
.findOne({
relations:{
members:true
},
where:{
id:userId
}
})
if (!user) return res.status(404).send({Message:'user not found'})
const projects = await dataSource
.getRepository(Project)
.find({
relations:{
members:true
},
where:{
members:{
user:{
id:requesterUser.id
}
}
}
})
if (!projects) return res.status(404).send({Message:'projects not found'})
const projectIds = projects.map(project=>{return project.id})
const tasks = await dataSource
.getRepository(Task)
.find({
relations:{
executor:true,
},
where:
{
executor:{
id:userId
}},
})
const {displayName} = user
if (!tasks) return res.status(404).send({Message:'tasks not found'})
return res.send({displayName, projects, tasks})
} catch(e){
return res.status(502).send({message:(e as Error).message})
}
})
export default router;
......@@ -11,6 +11,7 @@ import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import { AllHoursOneHourFormat, AllHoursTwoHourFormat } from '../../constants';
import { getWeekInfoString, getWeekFromCurrentDate, dateToISOLikeButLocal } from '../../helpers/CalendarHelpers';
import { fetchWeekDataStart } from '../../store/actions/commonActions';
import { fetchAllUserProjects } from '../../store/actions/projectsActions';
import { addCalendarTask, addCopyCalendarTask, deactivateCreateCopyTasksMode, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions';
import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions';
......@@ -44,14 +45,17 @@ function WeekCalendar() {
useEffect(() => {
if (userCalendarId) {
setUserId(userCalendarId)
dispatch(fetchCalendarTasks(userCalendarId))
dispatch(fetchCurrentCalendarDisplayName(userCalendarId))
dispatch(fetchAllUserProjects())
// dispatch(fetchCalendarTasks(userCalendarId))
// dispatch(fetchCurrentCalendarDisplayName(userCalendarId))
// dispatch(fetchAllUserProjects())
dispatch(fetchWeekDataStart(userCalendarId))
} else {
setUserId(user.id)
dispatch(fetchCalendarTasks(user.id))
dispatch(fetchCurrentCalendarDisplayName(user.id))
dispatch(fetchAllUserProjects())
dispatch(fetchWeekDataStart(user.id))
// dispatch(fetchCalendarTasks(user.id))
// dispatch(fetchCurrentCalendarDisplayName(user.id))
// dispatch(fetchAllUserProjects())
}
}, [userCalendarId, dispatch, user.id])
......
......@@ -34,6 +34,10 @@ export const ACTIVATE_CREATE_COPY_TASKS_MODE = "ACTIVATE_CREATE_COPY_TASKS_MODE"
export const DEACTIVATE_CREATE_COPY_TASKS_MODE = "DEACTIVATE_CREATE_COPY_TASKS_MODE"
export const FETCH_WEEK_DATA_START_REQUEST = "FETCH_WEEK_DATA_START_REQUEST";
export const FETCH_WEEK_DATA_START_SUCCESS = "FETCH_WEEK_DATA_START_SUCCESS";
export const FETCH_WEEK_DATA_START_FAILURE = "FETCH_WEEK_DATA_START_FAILURE";
......
import axios from '../../axiosPlanner';
import {
FETCH_WEEK_DATA_START_REQUEST,
FETCH_WEEK_DATA_START_SUCCESS,
FETCH_WEEK_DATA_START_FAILURE,
FETCH_CALENDAR_TASKS_REQUEST,
} from '../actionTypes/tasksTypes';
import {fetchAllUserProjectsSuccess} from './projectsActions';
import { fetchCalendarTasksSuccess } from './tasksActions';
import { fetchCurrentCalendarDisplayNameSuccess } from './usersActions';
export const showNotification = (message, variant="success") => {
return {type: "SHOW_NOTIFICATION", message, variant}
}
export const hideNotification = () => {
return {type: "HIDE_NOTIFICATION"};
};
\ No newline at end of file
};
/** weekDataStart, recieves userId returns type WEEK_DATA_START_REQUEST*/
const fetchWeekDataStartRequest = () => {
return { type: FETCH_WEEK_DATA_START_REQUEST }
}
/** weekDataStart, recieves userId returns type WEEK_DATA_START_SUCCESS*/
const fetchWeekDataStartSuccess = (weekData) => {
return { type: FETCH_WEEK_DATA_START_SUCCESS, weekData }
}
/** weekDataStart, recieves userId returns type WEEK_DATA_START_FAILURE*/
const fetchWeekDataStartFailure = (error) => {
return { type: FETCH_WEEK_DATA_START_FAILURE, error }
}
/**fetchWeekDataStart, recieves userId ,make GET request to 'tasks/week-data-start/{userId}, recieves weekdata */
export const fetchWeekDataStart = (userId) => {
return async (dispatch) => {
dispatch(fetchWeekDataStartRequest());
try {
console.log('fetchWeekDataStart front', userId)
const response = await axios.get(`/tasks/week-data-start/${userId}`);
dispatch(fetchCalendarTasksSuccess(response.data.tasks))
dispatch(fetchAllUserProjectsSuccess(response.data.projects));
dispatch(fetchCurrentCalendarDisplayNameSuccess(response.data.displayName));
} catch (error) {
dispatch(fetchWeekDataStartFailure(error.response.data));
}
}
}
\ No newline at end of file
......@@ -143,7 +143,7 @@ export const createMember = (memberData) => {
};
}
const fetchAllUserProjectsSuccess = (projects) => {
export const fetchAllUserProjectsSuccess = (projects) => {
return { type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects };
};
......
......@@ -24,6 +24,10 @@ import {
SORT_TASKS,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_FAILURE,
FETCH_PROJECTS_NON_WATCHER_REQUEST,
FETCH_WEEK_DATA_START_FAILURE,
FETCH_WEEK_DATA_START_REQUEST,
FETCH_WEEK_DATA_START_SUCCESS
} from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner'
......@@ -31,7 +35,7 @@ const fetchCalendarTasksRequest = () => {
return { type: FETCH_CALENDAR_TASKS_REQUEST }
};
const fetchCalendarTasksSuccess = (tasks) => {
export const fetchCalendarTasksSuccess = (tasks) => {
return { type: FETCH_CALENDAR_TASKS_SUCCESS, tasks }
};
......@@ -352,4 +356,7 @@ export const activateCreateCopyTasksMode = (task, navigate) => {
export const deactivateCreateCopyTasksMode = () => {
return { type: DEACTIVATE_CREATE_COPY_TASKS_MODE }
}
\ No newline at end of file
}
......@@ -137,7 +137,7 @@ export const fetchUsersAllFields = () => {
}
};
const fetchCurrentCalendarDisplayNameSuccess = (displayName) => {
export const fetchCurrentCalendarDisplayNameSuccess = (displayName) => {
return {type: FETCH_DISPLAYNAME_SUCCESS, displayName}
}
......
......@@ -23,6 +23,7 @@ import {
ACTIVATE_CREATE_COPY_TASKS_MODE,
DEACTIVATE_CREATE_COPY_TASKS_MODE,
SORT_TASKS,
FETCH_WEEK_DATA_START_FAILURE,
} from "../actionTypes/tasksTypes";
......@@ -156,6 +157,8 @@ const tasksReduсer = (state = initialState, action) => {
return { ...state, copyMode: { working: true, task: action.task } }
case DEACTIVATE_CREATE_COPY_TASKS_MODE:
return { ...state, copyMode: { working: false, task: null } }
case FETCH_WEEK_DATA_START_FAILURE:
return { ...state, loading: false, error: action.error };
case SORT_TASKS:
let filteredTasks = []
if (action.activeTasksOn) {
......
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