#110 added setup on non watcher users in user-task request

parent 0f1d3b06
...@@ -3,7 +3,7 @@ import {Task} from '../models/Task'; ...@@ -3,7 +3,7 @@ import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source'; import {myDataSource} from '../app-data-source';
import { User } from '../models/User'; import { User } from '../models/User';
import { Member, MemberRole } from '../models/Member'; import { Member, MemberRole } from '../models/Member';
import { In } from 'typeorm'; import { In, Not } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask'; import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfTask, taskFinderById } from '../helpers'; import { auth, authAuthorOrExecutorOfTask, taskFinderById } from '../helpers';
import { Project } from '../models/Project'; import { Project } from '../models/Project';
...@@ -341,7 +341,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{ ...@@ -341,7 +341,7 @@ router.post('/project',async (req: Request, res: Response):Promise<Response>=>{
/**check other users tasks that are related to the user through common projects, by user token*/ /**check other users tasks that are related to the user through common projects, by user token*/
router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{
const {user} = req.body const {user} = req.body
const projects = await dataSource const projectsWithTasks = await dataSource
.getRepository(Project) .getRepository(Project)
.find( .find(
{ relations:{ { relations:{
...@@ -358,18 +358,32 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp ...@@ -358,18 +358,32 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
} }
} }
}}) }})
if (!projects) return res.status(404).send({Message:'projects not found'}) if (!projectsWithTasks) return res.status(404).send({Message:'projects not found'})
let tasks:Task[] = [] let tasks:Task[] = []
if (projects.length>0) { if (projectsWithTasks.length>0) {
for (let project of projects){ for (let project of projectsWithTasks){
if (project?.tasks) { if (project?.tasks) {
tasks=tasks.concat(project.tasks) tasks=tasks.concat(project.tasks)
} }
} }
} }
const projectIds= projectsWithTasks.map(project=> {if(project.title!=="Личные дела")return project.id})
const projects = await dataSource
.getRepository(Project)
.find({
relations:{
members:{
user:true
}},
where:{
id:In(projectIds),
members:{
roleProject: Not(MemberRole.WATCHER)
}
},
})
return res.send({projects, tasks}) return res.send({projects, tasks})
}) })
......
...@@ -12,7 +12,7 @@ import { useDispatch, useSelector } from "react-redux"; ...@@ -12,7 +12,7 @@ import { useDispatch, useSelector } from "react-redux";
import TaskModal from "../../components/UsersTasksCompoments/TaskModal/TaskModal"; import TaskModal from "../../components/UsersTasksCompoments/TaskModal/TaskModal";
import moment from "moment"; import moment from "moment";
import MyTaskToolBar from "../../components/UsersTasksCompoments/UsersTaskToolBar"; import MyTaskToolBar from "../../components/UsersTasksCompoments/UsersTaskToolBar";
import { fetchAllTasks, deleteTask,editTask, deleteDateTimeTask} from "../../store/actions/tasksActions"; import { fetchAllTasks, deleteTask,editTask, deleteDateTimeTask , fetchAllTasksByMembership} from "../../store/actions/tasksActions";
import NewTaskForm from "../../components/UsersTasksCompoments/NewTaskForm"; import NewTaskForm from "../../components/UsersTasksCompoments/NewTaskForm";
import TableRowTask from "../../components/UsersTasksCompoments/TableRowTask/TableRowTask"; import TableRowTask from "../../components/UsersTasksCompoments/TableRowTask/TableRowTask";
import UsersTasksHeader from "./UsersTasksHeader/UsersTasksHeader"; import UsersTasksHeader from "./UsersTasksHeader/UsersTasksHeader";
...@@ -23,9 +23,10 @@ export default function UsersTasks() { ...@@ -23,9 +23,10 @@ export default function UsersTasks() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const tasks = useSelector((state) => state.tasks.tasks); const tasks = useSelector((state) => state.tasks.tasks);
const projects = useSelector((state) => state.tasks.projects);
const user = useSelector((state) => state.users.user); const user = useSelector((state) => state.users.user);
const [executors, setExecutors]=useState([]) const [executors, setExecutors]=useState([])
const [projects,setProjects]=useState([])
const [currentProject, setCurrentProject] = useState(null); const [currentProject, setCurrentProject] = useState(null);
const [recievedTasks, setRecievedTasks] = useState([]); const [recievedTasks, setRecievedTasks] = useState([]);
const [addTaskForm, setAddTaskForm] = useState(false); const [addTaskForm, setAddTaskForm] = useState(false);
...@@ -40,15 +41,14 @@ export default function UsersTasks() { ...@@ -40,15 +41,14 @@ export default function UsersTasks() {
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasks()); dispatch(fetchAllTasksByMembership());
filterProjectsNamesFromTasks()
if (tasks && tasks?.length > 0) { if (tasks && tasks?.length > 0) {
setRecievedTasks(tasks); setRecievedTasks(tasks);
} }
}, [dispatch, tasks?.length]); }, [dispatch, tasks?.length]);
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasks()); dispatch(fetchAllTasksByMembership());
}, [addTaskForm, setAddTaskForm]); }, [addTaskForm, setAddTaskForm]);
...@@ -112,7 +112,8 @@ useEffect(() => { ...@@ -112,7 +112,8 @@ useEffect(() => {
const onProjectChange = (e, task) => { const onProjectChange = (e, task) => {
const projectId = e.target.value; const projectId = e.target.value;
const project = uniqueProjects.find((uniqueProject) => uniqueProject.id === projectId); const project = projects.find((uniqueProject) => uniqueProject.id === projectId);
setCurrentProject(project)
const { id } = task; const { id } = task;
const newTasks = recievedTasks.map((task) => { const newTasks = recievedTasks.map((task) => {
if (task.id === id) { if (task.id === id) {
...@@ -218,20 +219,20 @@ useEffect(() => { ...@@ -218,20 +219,20 @@ useEffect(() => {
const rawProjects= tasks?.map(task=>task.project) const rawProjects= tasks?.map(task=>task.project)
const filterProjectsNamesFromTasks = ()=>{ // const filterProjectsNamesFromTasks = ()=>{
if (tasks && tasks?.length > 0) { // if (tasks && tasks?.length > 0) {
let rawSetProjectNames = [] // let rawSetProjectNames = []
for (let project of rawProjects){ // for (let project of rawProjects){
if (project===null){ // if (project===null){
} else{ // } else{
rawSetProjectNames.push(project.title) // rawSetProjectNames.push(project.title)
} // }
} // }
let uniqueTitlesProjects = [...new Set(rawSetProjectNames)]; // let uniqueTitlesProjects = [...new Set(rawSetProjectNames)];
setProjects(uniqueTitlesProjects) // setProjects(uniqueTitlesProjects)
} // }
} // }
const uniqueProjects = rawProjects?.reduce((results, value, index) => { const uniqueProjects = rawProjects?.reduce((results, value, index) => {
const exist = results.find((v) => { const exist = results.find((v) => {
...@@ -265,7 +266,8 @@ console.log('tasks', tasks) ...@@ -265,7 +266,8 @@ console.log('tasks', tasks)
{addTaskForm ? ( {addTaskForm ? (
<NewTaskForm <NewTaskForm
projects={uniqueProjects} projects={projects}
setCurrentProject={setCurrentProject}
currentProject={currentProject} currentProject={currentProject}
setAddTaskForm={()=>setAddTaskForm(false)} setAddTaskForm={()=>setAddTaskForm(false)}
/> />
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
DELETE_DATETIMETASK_FAILURE, DELETE_DATETIMETASK_FAILURE,
DELETE_DATETIMETASK_SUCCESS, DELETE_DATETIMETASK_SUCCESS,
DELETE_DATETIMETASK_REQUEST, DELETE_DATETIMETASK_REQUEST,
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS
} from "../actionTypes/tasksTypes"; } from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner' import axios from '../../axiosPlanner'
...@@ -64,17 +65,12 @@ export const fetchAllTasks = () => { ...@@ -64,17 +65,12 @@ export const fetchAllTasks = () => {
//**fetch tasks for table UsersTasks, start*/ //**fetch tasks for table UsersTasks, start*/
const fetchAllTasksByMembershipSuccess = (tasks) => { const fetchAllTasksByMembershipSuccess = (tasks) => {
return {type: FETCH_ALL_TASKS_SUCCESS, tasks} return {type: FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS, tasks}
}; };
const fetchUsersTasksFailure = (error) => { export const fetchAllTasksByMembership = () => {
return {type: FETCH_CALENDAR_TASKS_FAILURE, error}
};
export const fetcAllTasksByMembership = () => {
return async (dispatch) => { return async (dispatch) => {
dispatch(fetchCalendarTasksRequest()); dispatch(fetchCalendarTasksRequest());
try { try {
......
...@@ -17,7 +17,8 @@ import { ...@@ -17,7 +17,8 @@ import {
FETCH_TASKS_BY_PROJECT_FAILURE, FETCH_TASKS_BY_PROJECT_FAILURE,
DELETE_DATETIMETASK_FAILURE, DELETE_DATETIMETASK_FAILURE,
DELETE_DATETIMETASK_SUCCESS, DELETE_DATETIMETASK_SUCCESS,
DELETE_DATETIMETASK_REQUEST DELETE_DATETIMETASK_REQUEST,
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS
} from "../actionTypes/tasksTypes"; } from "../actionTypes/tasksTypes";
const initialState = { const initialState = {
...@@ -78,6 +79,8 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -78,6 +79,8 @@ const tasksReduсer = (state = initialState, action) => {
return {...state, loading: false, calendarTasks: newTasksWithInfoForCell}; 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_ALL_TASKS_BY_MEMBERSHIP_SUCCESS:
return {...state, loading: false, tasks: action.tasks, projects:action.projects};
case FETCH_CALENDAR_TASKS_FAILURE: case FETCH_CALENDAR_TASKS_FAILURE:
return {...state, loading: false, error: action.error}; return {...state, loading: false, error: action.error};
case ADD_NEW_TASK_SUCCESS: case ADD_NEW_TASK_SUCCESS:
......
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