#110 raw tasks.my get request

parent c1d5bc88
...@@ -6,7 +6,7 @@ import { auth, authAdminProject } from '../helpers'; ...@@ -6,7 +6,7 @@ import { auth, authAdminProject } from '../helpers';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
router.get('/',async (req:Request, res:Response): Promise<Response>=> { router.get('/',async (req:Request, res:Response): Promise<Response>=> {
const projects:Project[] = await dataSource.manager.find(Project) const projects:Project[] = await dataSource.manager.find(Project)
......
...@@ -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, Not } from 'typeorm'; import { Equal, 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';
...@@ -79,7 +79,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{ ...@@ -79,7 +79,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
} }
newTask.dateTimeDeadLine=dateTimeDeadLine; newTask.dateTimeDeadLine=dateTimeDeadLine;
newTask.author= user; newTask.author= user;
newTask.executor= executor; if(newTask.project.title==="Личные дела"){
newTask.executor=user;
} else {
newTask.executor= executor;
}
newTask.priority = priority; newTask.priority = priority;
await newTask.save(); await newTask.save();
const newDateTimeTask = new DateTimeTask(); const newDateTimeTask = new DateTimeTask();
...@@ -181,30 +185,93 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response ...@@ -181,30 +185,93 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
/**check tasks of current user where he is executor(works for tbl MyTasks), search by id*/ /**check tasks of current user where he is executor(works for tbl MyTasks), search by id*/
router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
const user = req.body.user const user = req.body.user
const tasks = await dataSource // const tasks = await dataSource
.getRepository(Task) // .getRepository(Task)
.find({ // .find({
relations:{ // relations:{
executor:true, // // project:true,
}, // executor:true,
where:[ // project:{
{ // members:{
executor:{ // user:true
id:user.id // }
} // }
}, // },
] // where:
}) // {
const projects= await dataSource // executor:{
// id:user.id
// },
// project:{
// members:{
// user:user,
// // roleProject:Not(MemberRole.WATCHER)
// }
// }
// }
// }
// )
const projects = await dataSource
.getRepository(Project) .getRepository(Project)
.find({where:{ .find({
members:{ relations:{
user:{ members:{
id:user.id user:true
}},
where:{
title:Not(Equal("Не определено")),
members:{
user:{
id: user.id
},
roleProject:Not(MemberRole.WATCHER)
}
} }
} }
}}) )
return res.send({tasks, projects}) const projectsList= projects.map(project=> {return project.id})
console.log( 'projectsList ', projectsList)
const tasks = await dataSource
.getRepository(Task)
.find(
{relations:{
author:true,
executor:true,
project:true
},
where:{
executor:{
id:user.id
},
// project:{
// id:In(projectsList)
// }
}
}
)
// console.log('tasks ', tasks)
// console.log('projects ', projects)
// const projectsList= tasks.map(task=> {return task.project?.id})
// console.log( 'projectsList ', projectsList)
// const projects= await dataSource
// .getRepository(Project)
// .find({relations:{
// members:{
// user:true
// }
// },
// where:{
// id:In(
// projectsList,
// ),
// title:Not(Equal("Не определено"))
// }
// })
// return res.send({
// projects})
return res.send({tasks, projects})
}) })
...@@ -355,6 +422,9 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp ...@@ -355,6 +422,9 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
members:{ members:{
user:{ user:{
id:user.id id:user.id
},
project:{
title:Not(Equal("Личные дела"))
} }
} }
}}) }})
...@@ -367,7 +437,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp ...@@ -367,7 +437,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
} }
} }
} }
const projectIds= projectsWithTasks.map(project=> {if(project.title!=="Личные дела")return project.id}) const projectIds= projectsWithTasks.map(project=> {return project.id})
const projects = await dataSource const projects = await dataSource
.getRepository(Project) .getRepository(Project)
.find({ .find({
......
...@@ -45,7 +45,10 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN ...@@ -45,7 +45,10 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN
return ( return (
<div> <div>
<FormControl sx={{ m: 1, width: 250,borderColor:'white' }}> <FormControl sx={{ m: 1, width: 250,borderColor:'white' }}>
<InputLabel placeholder='Choose Project' label='I am a really really long green TextField label' id="demo-multiple-name-label" sx={{color:'white', padding:'1' }}>Project</InputLabel> <InputLabel placeholder='Choose Project'
label='I am a really really long green TextField label'
id="demo-multiple-name-label" sx={{color:'white', padding:'1' }}
>Project</InputLabel>
<Select <Select
labelId="demo-multiple-name-label" labelId="demo-multiple-name-label"
label='Choose Project' label='Choose Project'
...@@ -59,11 +62,11 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN ...@@ -59,11 +62,11 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN
sx={{color:'white' }} sx={{color:'white' }}
onClose={(e)=>{onClose(projectName)}} onClose={(e)=>{onClose(projectName)}}
> >
{projects?.map((project) => ( {projects?.map((project,index) => (
<MenuItem <MenuItem
key={project.id} key={index}
value={project.id} value={project.id}
style={getStyles(project, project.title, theme)} style={getStyles(project.title, projectName, theme)}
> >
{project.title} {project.title}
</MenuItem> </MenuItem>
......
...@@ -19,8 +19,8 @@ export default function BasicSelect({value,label,name,onChange,task,items}) { ...@@ -19,8 +19,8 @@ export default function BasicSelect({value,label,name,onChange,task,items}) {
name={name} name={name}
onChange={(e) => onChange(e, task)} onChange={(e) => onChange(e, task)}
> >
{items.map((item) => ( {items.map((item,index) => (
<MenuItem key={item.value} value={item.value}> <MenuItem key={index} value={item.value}>
{item.title} {item.title}
</MenuItem> </MenuItem>
))} ))}
......
...@@ -12,6 +12,7 @@ const CustomTableCell = ({ ...@@ -12,6 +12,7 @@ const CustomTableCell = ({
onModalOpen, onModalOpen,
placeholder, placeholder,
user, user,
colSpan
}) => { }) => {
const styles = placeholder ? { width: "100%" } : { width: "auto" }; const styles = placeholder ? { width: "100%" } : { width: "auto" };
const divStyle = { const divStyle = {
...@@ -32,6 +33,7 @@ const CustomTableCell = ({ ...@@ -32,6 +33,7 @@ const CustomTableCell = ({
return ( return (
<> <>
<TableCell <TableCell
colSpan={colSpan}
onClick={(e) => (onModalOpen ? onModalOpen(e, task) : null)} onClick={(e) => (onModalOpen ? onModalOpen(e, task) : null)}
align="left" align="left"
// style={styles} // style={styles}
......
...@@ -18,13 +18,13 @@ import moment from "moment"; ...@@ -18,13 +18,13 @@ import moment from "moment";
import CustomTableCell from "./CustomTableCell"; import CustomTableCell from "./CustomTableCell";
import MaterialUIPickers from "./DateTimePicker/DateTimePicker"; import MaterialUIPickers from "./DateTimePicker/DateTimePicker";
import BasicSelect from "../UI/Select/Select"; import BasicSelect from "../UI/Select/Select";
import { addTask } from "../../store/actions/tasksActions"; import { addTaskToUserTasksTable } from "../../store/actions/tasksActions";
import TaskModal from "./TaskModal/TaskModal"; import TaskModal from "./TaskModal/TaskModal";
export default function NewTaskForm({ export default function NewTaskForm({
projects, projects,
currentProject, currentProject,
setCurrentProject,
setAddTaskForm, setAddTaskForm,
}) { }) {
const dispatch = useDispatch(); const dispatch = useDispatch();
...@@ -48,7 +48,7 @@ export default function NewTaskForm({ ...@@ -48,7 +48,7 @@ export default function NewTaskForm({
executor:null, executor:null,
isEditMode: true, isEditMode: true,
}); });
console.log('NewTaskForm currentProject ', currentProject, 'projects ', projects)
const [modal, setModal] = useState(false); const [modal, setModal] = useState(false);
const onModalOpen = (event, task) => { const onModalOpen = (event, task) => {
...@@ -69,17 +69,19 @@ export default function NewTaskForm({ ...@@ -69,17 +69,19 @@ export default function NewTaskForm({
const onProjectChange = (e, task) => { const onProjectChange = (e, task) => {
const value = e.target.value; const value = e.target.value;
const project = projects.find((e) => e.id === value); console.log(' onProjectChange value ', value, 'task ', task)
const project = projects.find((project) => project.id === value);
setCurrentProject(project)
const newTask = { ...task }; const newTask = { ...task };
newTask.project = project; newTask.project = project;
setTask(newTask); setTask(newTask);
}; };
const onExecutorChange = (e, task) => { const onExecutorChange = (e, task) => {
const value = e.target.value; const {value, name} = e.target.value;
const executor = projects.find((e) => e.id === value); const executorMember = currentProject.find((member) => member.user.id === value);
const newTask = { ...task }; const newTask = { ...task };
newTask.executor = executor; newTask[{name}] = executorMember.user;
setTask(newTask); setTask(newTask);
}; };
...@@ -92,7 +94,7 @@ export default function NewTaskForm({ ...@@ -92,7 +94,7 @@ export default function NewTaskForm({
}; };
const handleAddTask = () => { const handleAddTask = () => {
dispatch(addTask(task)); dispatch(addTaskToUserTasksTable(task));
setAddTaskForm(); setAddTaskForm();
}; };
...@@ -115,6 +117,7 @@ export default function NewTaskForm({ ...@@ -115,6 +117,7 @@ export default function NewTaskForm({
key={headCell.id} key={headCell.id}
align="center" align="center"
padding={headCell.disablePadding ? "none" : "normal"} padding={headCell.disablePadding ? "none" : "normal"}
colSpan={headCell.colSpan}
> >
{headCell.label} {headCell.label}
</TableCell> </TableCell>
...@@ -139,14 +142,15 @@ export default function NewTaskForm({ ...@@ -139,14 +142,15 @@ export default function NewTaskForm({
/> />
</TableCell> </TableCell>
<CustomTableCell {/* <CustomTableCell
{...{ {...{
task, task,
name: "createdAt", name: "createdAt",
value: moment(task.createdAt).format("DD-MM-YYYY hh:mm A"), value: moment(task.createdAt).format("DD-MM-YYYY hh:mm A"),
}} }}
/> /> */}
<CustomTableCell <CustomTableCell
colSpan={2}
{...{ {...{
task, task,
name: "title", name: "title",
...@@ -159,9 +163,9 @@ export default function NewTaskForm({ ...@@ -159,9 +163,9 @@ export default function NewTaskForm({
<TableCell> <TableCell>
<BasicSelect <BasicSelect
items={projects.map((e) => ({ items={projects?.map((project) => ({
value: e?.id, value: project?.id,
title: e?.title, title: project?.title,
}))} }))}
task={task} task={task}
onChange={onProjectChange} onChange={onProjectChange}
...@@ -171,14 +175,15 @@ export default function NewTaskForm({ ...@@ -171,14 +175,15 @@ export default function NewTaskForm({
</TableCell> </TableCell>
<TableCell> <TableCell>
<BasicSelect <BasicSelect
items={currentProject.members.map((member) => ({ items={currentProject?.members.map((member) => ({
value: member?.id, value: member?.user?.id,
title: member?.displayName, title: member?.user?.displayName,
}))} }))}
task={task} task={task}
onChange={onExecutorChange} onChange={onExecutorChange}
name="executor" name="executor"
value={task.executor?.id} value={task.executor?.id}
defaultValue={user.id}
/> />
</TableCell> </TableCell>
...@@ -235,17 +240,18 @@ export const header = [ ...@@ -235,17 +240,18 @@ export const header = [
disablePadding: true, disablePadding: true,
label: "Приоритет", label: "Приоритет",
}, },
{ // {
id: "createdAt", // id: "createdAt",
numeric: true, // numeric: true,
disablePadding: false, // disablePadding: false,
label: "Дата создания", // label: "Дата создания",
}, // },
{ {
id: "title", id: "title",
numeric: false, numeric: false,
disablePadding: false, disablePadding: false,
label: "Заголовок", label: "Заголовок",
colSpan:2
}, },
{ {
id: "projectName", id: "projectName",
......
...@@ -27,7 +27,8 @@ export default function UsersTaskToolBar({projects,onClose,projectName,setProjec ...@@ -27,7 +27,8 @@ export default function UsersTaskToolBar({projects,onClose,projectName,setProjec
<Box sx={{ flexGrow: 1 }}> <Box sx={{ flexGrow: 1 }}>
<AppBar position="static"> <AppBar position="static">
<Toolbar> <Toolbar
>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}> <Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
Задачи сотрудников Задачи сотрудников
</Typography> </Typography>
......
...@@ -22,6 +22,7 @@ export default function EnhancedTable() { ...@@ -22,6 +22,7 @@ export default function EnhancedTable() {
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 [recievedTasks, setRecievedTasks] = useState([]); const [recievedTasks, setRecievedTasks] = useState([]);
const [addTaskForm, setAddTaskForm] = useState(false); const [addTaskForm, setAddTaskForm] = useState(false);
...@@ -33,22 +34,22 @@ export default function EnhancedTable() { ...@@ -33,22 +34,22 @@ export default function EnhancedTable() {
open: false, open: false,
task: null, task: null,
}); });
const [projects, setProjects] = useState(["1", "2"]); // const [projects, setProjects] = useState(["1", "2"]);
useEffect(() => { // useEffect(() => {
dispatch(fetchAllTasks()); // dispatch(fetchAllTasks());
filterProjectsNamesFromTasks(); // // filterProjectsNamesFromTasks();
}, [dispatch]); // }, [dispatch]);
useEffect(() => { useEffect(() => {
if (tasks && tasks?.length > 0) { if (tasks && tasks?.length > 0) {
setRecievedTasks(tasks); setRecievedTasks(tasks);
} }
}, [dispatch, tasks?.length]); }, [ tasks?.length]);
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasks()); dispatch(fetchAllTasks());
}, [addTaskForm, setAddTaskForm]); }, [addTaskForm, setAddTaskForm, dispatch]);
...@@ -207,7 +208,7 @@ export default function EnhancedTable() { ...@@ -207,7 +208,7 @@ export default function EnhancedTable() {
} }
} }
let uniqueTitlesProjects = [...new Set(rawSetProjectNames)]; let uniqueTitlesProjects = [...new Set(rawSetProjectNames)];
setProjects(uniqueTitlesProjects); // setProjects(uniqueTitlesProjects);
} }
}; };
......
...@@ -33,12 +33,11 @@ export default function UsersTasks() { ...@@ -33,12 +33,11 @@ export default function UsersTasks() {
const [order, setOrder] = useState("asc"); const [order, setOrder] = useState("asc");
const [orderBy, setOrderBy] = useState("id"); const [orderBy, setOrderBy] = useState("id");
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] =useState(5); const [rowsPerPage, setRowsPerPage] =useState(25);
const [modal, setModal] = useState({ const [modal, setModal] = useState({
open: false, open: false,
task: null, task: null,
}); });
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasksByMembership()); dispatch(fetchAllTasksByMembership());
...@@ -47,6 +46,7 @@ export default function UsersTasks() { ...@@ -47,6 +46,7 @@ export default function UsersTasks() {
} }
}, [dispatch, }, [dispatch,
tasks?.length, tasks?.length,
// tasks,
addTaskForm, setAddTaskForm]); addTaskForm, setAddTaskForm]);
// useEffect(() => { // useEffect(() => {
...@@ -75,7 +75,6 @@ export default function UsersTasks() { ...@@ -75,7 +75,6 @@ export default function UsersTasks() {
const name = e.target.name; const name = e.target.name;
const { id } = task; const { id } = task;
const newTasks = recievedTasks.map((task) => { const newTasks = recievedTasks.map((task) => {
console.log('recievedTasks.map ',task)
if (task.id === id) { if (task.id === id) {
return { ...task, [name]: value }; return { ...task, [name]: value };
} }
...@@ -116,12 +115,14 @@ export default function UsersTasks() { ...@@ -116,12 +115,14 @@ export default function UsersTasks() {
const projectId = e.target.value; const projectId = e.target.value;
const project = projects.length>0 ?projects.find((uniqueProject) => uniqueProject.id === projectId):null; const project = projects.length>0 ?projects.find((uniqueProject) => uniqueProject.id === projectId):null;
setCurrentProject(project) setCurrentProject(project)
let executorList=[]
if(project?.members){ if(project?.members){
for (let member of project.members){ for (let member of project.members){
setExecutors([...executors, member.user]) executorList.push(member.user)
}
console.log('executorList ', executorList)
} }
console.log('executors ', executors) setExecutors(executorList)
}
const { id } = task; const { id } = task;
const newTasks = recievedTasks.map((task) => { const newTasks = recievedTasks.map((task) => {
......
...@@ -77,7 +77,7 @@ export const fetchAllTasksByMembership = () => { ...@@ -77,7 +77,7 @@ export const fetchAllTasksByMembership = () => {
const response = await axios.get("/tasks/users-tasks"); const response = await axios.get("/tasks/users-tasks");
dispatch(fetchAllTasksByMembershipSuccess(response.data.tasks, response.data.projects)) dispatch(fetchAllTasksByMembershipSuccess(response.data.tasks, response.data.projects))
} catch (error) { } catch (error) {
dispatch(fetchCalendarTasksFailure(error.response.data)); dispatch(fetchCalendarTasksFailure(error.response.data));
} }
} }
}; };
...@@ -265,3 +265,33 @@ export const deleteDateTimeTask = (dateTimeTaskId) => { ...@@ -265,3 +265,33 @@ export const deleteDateTimeTask = (dateTimeTaskId) => {
} }
} }
} }
/** add new task in UserTaslks Table */
const addTaskToUserTasksTableRequest = () => {
return {type: ADD_NEW_TASK_REQUEST}
};
const addTaskToUserTasksTableSuccess = () => {
return {type: ADD_NEW_TASK_SUCCESS}
};
const addTaskToUserTasksTableFailure = (error) => {
return {type: ADD_NEW_TASK_FAILURE, error}
};
export const addTaskToUserTasksTable = (task) => {
return async (dispatch) => {
dispatch(addTaskToUserTasksTableRequest());
try {
await axios.post("/tasks/users", task);
dispatch(addTaskToUserTasksTableSuccess())
dispatch(fetchAllTasksByMembership())
} catch (error) {
dispatch(addTaskToUserTasksTableFailure(error.response.data));
}
}
}
/** end */
\ No newline at end of file
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