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

parent 0f1d3b06
......@@ -3,7 +3,7 @@ import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source';
import { User } from '../models/User';
import { Member, MemberRole } from '../models/Member';
import { In } from 'typeorm';
import { In, Not } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfTask, taskFinderById } from '../helpers';
import { Project } from '../models/Project';
......@@ -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*/
router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Response>=>{
const {user} = req.body
const projects = await dataSource
const projectsWithTasks = await dataSource
.getRepository(Project)
.find(
{ relations:{
......@@ -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[] = []
if (projects.length>0) {
for (let project of projects){
if (projectsWithTasks.length>0) {
for (let project of projectsWithTasks){
if (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})
})
......
......@@ -12,7 +12,7 @@ import { useDispatch, useSelector } from "react-redux";
import TaskModal from "../../components/UsersTasksCompoments/TaskModal/TaskModal";
import moment from "moment";
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 TableRowTask from "../../components/UsersTasksCompoments/TableRowTask/TableRowTask";
import UsersTasksHeader from "./UsersTasksHeader/UsersTasksHeader";
......@@ -23,9 +23,10 @@ export default function UsersTasks() {
const dispatch = useDispatch();
const tasks = useSelector((state) => state.tasks.tasks);
const projects = useSelector((state) => state.tasks.projects);
const user = useSelector((state) => state.users.user);
const [executors, setExecutors]=useState([])
const [projects,setProjects]=useState([])
const [currentProject, setCurrentProject] = useState(null);
const [recievedTasks, setRecievedTasks] = useState([]);
const [addTaskForm, setAddTaskForm] = useState(false);
......@@ -40,15 +41,14 @@ export default function UsersTasks() {
useEffect(() => {
dispatch(fetchAllTasks());
filterProjectsNamesFromTasks()
dispatch(fetchAllTasksByMembership());
if (tasks && tasks?.length > 0) {
setRecievedTasks(tasks);
}
}, [dispatch, tasks?.length]);
useEffect(() => {
dispatch(fetchAllTasks());
dispatch(fetchAllTasksByMembership());
}, [addTaskForm, setAddTaskForm]);
......@@ -112,7 +112,8 @@ useEffect(() => {
const onProjectChange = (e, task) => {
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 newTasks = recievedTasks.map((task) => {
if (task.id === id) {
......@@ -218,20 +219,20 @@ useEffect(() => {
const rawProjects= tasks?.map(task=>task.project)
const filterProjectsNamesFromTasks = ()=>{
if (tasks && tasks?.length > 0) {
// const filterProjectsNamesFromTasks = ()=>{
// if (tasks && tasks?.length > 0) {
let rawSetProjectNames = []
for (let project of rawProjects){
if (project===null){
} else{
rawSetProjectNames.push(project.title)
}
}
let uniqueTitlesProjects = [...new Set(rawSetProjectNames)];
setProjects(uniqueTitlesProjects)
}
}
// let rawSetProjectNames = []
// for (let project of rawProjects){
// if (project===null){
// } else{
// rawSetProjectNames.push(project.title)
// }
// }
// let uniqueTitlesProjects = [...new Set(rawSetProjectNames)];
// setProjects(uniqueTitlesProjects)
// }
// }
const uniqueProjects = rawProjects?.reduce((results, value, index) => {
const exist = results.find((v) => {
......@@ -265,7 +266,8 @@ console.log('tasks', tasks)
{addTaskForm ? (
<NewTaskForm
projects={uniqueProjects}
projects={projects}
setCurrentProject={setCurrentProject}
currentProject={currentProject}
setAddTaskForm={()=>setAddTaskForm(false)}
/>
......
......@@ -18,6 +18,7 @@ import {
DELETE_DATETIMETASK_FAILURE,
DELETE_DATETIMETASK_SUCCESS,
DELETE_DATETIMETASK_REQUEST,
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS
} from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner'
......@@ -64,17 +65,12 @@ export const fetchAllTasks = () => {
//**fetch tasks for table UsersTasks, start*/
const fetchAllTasksByMembershipSuccess = (tasks) => {
return {type: FETCH_ALL_TASKS_SUCCESS, tasks}
return {type: FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS, tasks}
};
const fetchUsersTasksFailure = (error) => {
return {type: FETCH_CALENDAR_TASKS_FAILURE, error}
};
export const fetcAllTasksByMembership = () => {
export const fetchAllTasksByMembership = () => {
return async (dispatch) => {
dispatch(fetchCalendarTasksRequest());
try {
......
......@@ -17,7 +17,8 @@ import {
FETCH_TASKS_BY_PROJECT_FAILURE,
DELETE_DATETIMETASK_FAILURE,
DELETE_DATETIMETASK_SUCCESS,
DELETE_DATETIMETASK_REQUEST
DELETE_DATETIMETASK_REQUEST,
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS
} from "../actionTypes/tasksTypes";
const initialState = {
......@@ -78,6 +79,8 @@ const tasksReduсer = (state = initialState, action) => {
return {...state, loading: false, calendarTasks: newTasksWithInfoForCell};
case FETCH_ALL_TASKS_SUCCESS:
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:
return {...state, loading: false, error: action.error};
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