#110 raw tasks.my get request

parent c1d5bc88
......@@ -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, Not } from 'typeorm';
import { Equal, In, Not } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfTask, taskFinderById } from '../helpers';
import { Project } from '../models/Project';
......@@ -79,7 +79,11 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
}
newTask.dateTimeDeadLine=dateTimeDeadLine;
newTask.author= user;
if(newTask.project.title==="Личные дела"){
newTask.executor=user;
} else {
newTask.executor= executor;
}
newTask.priority = priority;
await newTask.save();
const newDateTimeTask = new DateTimeTask();
......@@ -181,29 +185,92 @@ 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*/
router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
const user = req.body.user
const tasks = await dataSource
.getRepository(Task)
.find({
// const tasks = await dataSource
// .getRepository(Task)
// .find({
// relations:{
// // project:true,
// executor:true,
// project:{
// members:{
// user:true
// }
// }
// },
// where:
// {
// executor:{
// id:user.id
// },
// project:{
// members:{
// user:user,
// // roleProject:Not(MemberRole.WATCHER)
// }
// }
// }
// }
// )
const projects = await dataSource
.getRepository(Project)
.find({
relations:{
members:{
user:true
}},
where:{
title:Not(Equal("Не определено")),
members:{
user:{
id: user.id
},
roleProject:Not(MemberRole.WATCHER)
}
}
}
)
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:[
{
where:{
executor:{
id:user.id
}
},
]
})
const projects= await dataSource
.getRepository(Project)
.find({where:{
members:{
user:{
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
members:{
user:{
id:user.id
},
project:{
title:Not(Equal("Личные дела"))
}
}
}})
......@@ -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
.getRepository(Project)
.find({
......
......@@ -45,7 +45,10 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN
return (
<div>
<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
labelId="demo-multiple-name-label"
label='Choose Project'
......@@ -59,11 +62,11 @@ export default function MultipleSelect({projects,projectName,onClose,setProjectN
sx={{color:'white' }}
onClose={(e)=>{onClose(projectName)}}
>
{projects?.map((project) => (
{projects?.map((project,index) => (
<MenuItem
key={project.id}
key={index}
value={project.id}
style={getStyles(project, project.title, theme)}
style={getStyles(project.title, projectName, theme)}
>
{project.title}
</MenuItem>
......
......@@ -19,8 +19,8 @@ export default function BasicSelect({value,label,name,onChange,task,items}) {
name={name}
onChange={(e) => onChange(e, task)}
>
{items.map((item) => (
<MenuItem key={item.value} value={item.value}>
{items.map((item,index) => (
<MenuItem key={index} value={item.value}>
{item.title}
</MenuItem>
))}
......
......@@ -12,6 +12,7 @@ const CustomTableCell = ({
onModalOpen,
placeholder,
user,
colSpan
}) => {
const styles = placeholder ? { width: "100%" } : { width: "auto" };
const divStyle = {
......@@ -32,6 +33,7 @@ const CustomTableCell = ({
return (
<>
<TableCell
colSpan={colSpan}
onClick={(e) => (onModalOpen ? onModalOpen(e, task) : null)}
align="left"
// style={styles}
......
......@@ -18,13 +18,13 @@ import moment from "moment";
import CustomTableCell from "./CustomTableCell";
import MaterialUIPickers from "./DateTimePicker/DateTimePicker";
import BasicSelect from "../UI/Select/Select";
import { addTask } from "../../store/actions/tasksActions";
import { addTaskToUserTasksTable } from "../../store/actions/tasksActions";
import TaskModal from "./TaskModal/TaskModal";
export default function NewTaskForm({
projects,
currentProject,
setCurrentProject,
setAddTaskForm,
}) {
const dispatch = useDispatch();
......@@ -48,7 +48,7 @@ export default function NewTaskForm({
executor:null,
isEditMode: true,
});
console.log('NewTaskForm currentProject ', currentProject, 'projects ', projects)
const [modal, setModal] = useState(false);
const onModalOpen = (event, task) => {
......@@ -69,17 +69,19 @@ export default function NewTaskForm({
const onProjectChange = (e, task) => {
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 };
newTask.project = project;
setTask(newTask);
};
const onExecutorChange = (e, task) => {
const value = e.target.value;
const executor = projects.find((e) => e.id === value);
const {value, name} = e.target.value;
const executorMember = currentProject.find((member) => member.user.id === value);
const newTask = { ...task };
newTask.executor = executor;
newTask[{name}] = executorMember.user;
setTask(newTask);
};
......@@ -92,7 +94,7 @@ export default function NewTaskForm({
};
const handleAddTask = () => {
dispatch(addTask(task));
dispatch(addTaskToUserTasksTable(task));
setAddTaskForm();
};
......@@ -115,6 +117,7 @@ export default function NewTaskForm({
key={headCell.id}
align="center"
padding={headCell.disablePadding ? "none" : "normal"}
colSpan={headCell.colSpan}
>
{headCell.label}
</TableCell>
......@@ -139,14 +142,15 @@ export default function NewTaskForm({
/>
</TableCell>
<CustomTableCell
{/* <CustomTableCell
{...{
task,
name: "createdAt",
value: moment(task.createdAt).format("DD-MM-YYYY hh:mm A"),
}}
/>
/> */}
<CustomTableCell
colSpan={2}
{...{
task,
name: "title",
......@@ -159,9 +163,9 @@ export default function NewTaskForm({
<TableCell>
<BasicSelect
items={projects.map((e) => ({
value: e?.id,
title: e?.title,
items={projects?.map((project) => ({
value: project?.id,
title: project?.title,
}))}
task={task}
onChange={onProjectChange}
......@@ -171,14 +175,15 @@ export default function NewTaskForm({
</TableCell>
<TableCell>
<BasicSelect
items={currentProject.members.map((member) => ({
value: member?.id,
title: member?.displayName,
items={currentProject?.members.map((member) => ({
value: member?.user?.id,
title: member?.user?.displayName,
}))}
task={task}
onChange={onExecutorChange}
name="executor"
value={task.executor?.id}
defaultValue={user.id}
/>
</TableCell>
......@@ -235,17 +240,18 @@ export const header = [
disablePadding: true,
label: "Приоритет",
},
{
id: "createdAt",
numeric: true,
disablePadding: false,
label: "Дата создания",
},
// {
// id: "createdAt",
// numeric: true,
// disablePadding: false,
// label: "Дата создания",
// },
{
id: "title",
numeric: false,
disablePadding: false,
label: "Заголовок",
colSpan:2
},
{
id: "projectName",
......
......@@ -27,7 +27,8 @@ export default function UsersTaskToolBar({projects,onClose,projectName,setProjec
<Box sx={{ flexGrow: 1 }}>
<AppBar position="static">
<Toolbar>
<Toolbar
>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
Задачи сотрудников
</Typography>
......
......@@ -22,6 +22,7 @@ export default function EnhancedTable() {
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 [recievedTasks, setRecievedTasks] = useState([]);
const [addTaskForm, setAddTaskForm] = useState(false);
......@@ -33,22 +34,22 @@ export default function EnhancedTable() {
open: false,
task: null,
});
const [projects, setProjects] = useState(["1", "2"]);
// const [projects, setProjects] = useState(["1", "2"]);
useEffect(() => {
dispatch(fetchAllTasks());
filterProjectsNamesFromTasks();
}, [dispatch]);
// useEffect(() => {
// dispatch(fetchAllTasks());
// // filterProjectsNamesFromTasks();
// }, [dispatch]);
useEffect(() => {
if (tasks && tasks?.length > 0) {
setRecievedTasks(tasks);
}
}, [dispatch, tasks?.length]);
}, [ tasks?.length]);
useEffect(() => {
dispatch(fetchAllTasks());
}, [addTaskForm, setAddTaskForm]);
}, [addTaskForm, setAddTaskForm, dispatch]);
......@@ -207,7 +208,7 @@ export default function EnhancedTable() {
}
}
let uniqueTitlesProjects = [...new Set(rawSetProjectNames)];
setProjects(uniqueTitlesProjects);
// setProjects(uniqueTitlesProjects);
}
};
......
......@@ -33,13 +33,12 @@ export default function UsersTasks() {
const [order, setOrder] = useState("asc");
const [orderBy, setOrderBy] = useState("id");
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] =useState(5);
const [rowsPerPage, setRowsPerPage] =useState(25);
const [modal, setModal] = useState({
open: false,
task: null,
});
useEffect(() => {
dispatch(fetchAllTasksByMembership());
if (tasks && tasks?.length > 0) {
......@@ -47,6 +46,7 @@ export default function UsersTasks() {
}
}, [dispatch,
tasks?.length,
// tasks,
addTaskForm, setAddTaskForm]);
// useEffect(() => {
......@@ -75,7 +75,6 @@ export default function UsersTasks() {
const name = e.target.name;
const { id } = task;
const newTasks = recievedTasks.map((task) => {
console.log('recievedTasks.map ',task)
if (task.id === id) {
return { ...task, [name]: value };
}
......@@ -116,12 +115,14 @@ export default function UsersTasks() {
const projectId = e.target.value;
const project = projects.length>0 ?projects.find((uniqueProject) => uniqueProject.id === projectId):null;
setCurrentProject(project)
let executorList=[]
if(project?.members){
for (let member of project.members){
setExecutors([...executors, member.user])
executorList.push(member.user)
}
console.log('executors ', executors)
console.log('executorList ', executorList)
}
setExecutors(executorList)
const { id } = task;
const newTasks = recievedTasks.map((task) => {
......
......@@ -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