#110 create of task in MyTask fixed

parent e82c76a8
......@@ -176,7 +176,7 @@ export const taskFinderByDateTimeTaskId = async (dateTimeTaskId:string):Promise<
/**member finder by userId and projectId, return one task */
export const memberFinderById = async (userId:string, projectId:string)=>{
export const memberFinderById = async (userId:string, projectId:string):Promise<Member|null>=>{
const member = await dataSource
.getRepository(Member)
.findOne({
......@@ -210,6 +210,17 @@ export let transporter = nodemailer.createTransport({
})
export const subtractHours= (date:Date, hours:number)=> {
const dateCopy = new Date(date);
console.log('dateCopy ', dateCopy)
dateCopy.setHours(dateCopy.getHours() - hours);
console.log('dateCopy afterset ', dateCopy)
return dateCopy;
}
export const FRONTEND_URL = 'localhost:3000';
......@@ -83,6 +83,8 @@ export class User extends BaseEntity implements IUser {
@OneToMany(() => Member, (member: { user: User }) => member.user, {onDelete: 'CASCADE'})
members!: Member[];
// @OneToOne(()=>PasswordRecovery,)
@BeforeInsert()
......
......@@ -5,7 +5,7 @@ import { User } from '../models/User';
import { Member, MemberRole } from '../models/Member';
import { Equal, In, Not } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfTask, taskFinderById } from '../helpers';
import { auth, authAuthorOrExecutorOfTask, subtractHours, taskFinderById } from '../helpers';
import { Project } from '../models/Project';
const router:Router = express.Router();
const dataSource = myDataSource;
......@@ -27,6 +27,17 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
/**create new task for table MyTask*/
router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
const {user,title,description,project,executor,dateTimeStart,dateTimeDue, dateTimeDeadLine,priority} = req.body;
console.log('dateTimeStart ', dateTimeStart, 'dateTimeDue ', dateTimeDue, 'dateTimeDeadLine ', dateTimeDeadLine)
//** if dateTimeDue is null , then dateTimeDeadLine copied to dateTimeDue and dateTimeStart = dateTimeDue - 1 hour*/
let dateTimeDueFinal = dateTimeDue
let dateTimeStartFinal = dateTimeStart
let dateTimeDeadlineFinal= dateTimeDeadLine
if (!dateTimeDue && dateTimeDeadLine) {
dateTimeDueFinal = dateTimeDeadLine
dateTimeStartFinal = subtractHours(dateTimeDueFinal, 1)
}
console.log('dateTimeDueFinal ', dateTimeDueFinal, 'dateTimeStartFinal ', dateTimeStartFinal, 'dateTimeDeadLine ', dateTimeDeadLine,' dateTimeDeadlineFinal ', dateTimeDeadlineFinal)
const newTask = new Task();
newTask.title = title;
newTask.description = description;
......@@ -77,7 +88,7 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
await newMember.save();
}
}
newTask.dateTimeDeadLine=dateTimeDeadLine;
newTask.dateTimeDeadLine= dateTimeDeadlineFinal;
newTask.author= user;
if(newTask.project.title==="Личные дела"){
newTask.executor=user;
......@@ -86,11 +97,13 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
}
newTask.priority = priority;
await newTask.save();
if (dateTimeDeadlineFinal) {
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStart
newDateTimeTask.dateTimeDue = dateTimeDue
newDateTimeTask.dateTimeStart = dateTimeStartFinal
newDateTimeTask.dateTimeDue = dateTimeDueFinal
newDateTimeTask.task = newTask
await newDateTimeTask.save()
}
return res.send({newTask});
})
......@@ -170,13 +183,12 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
relations:{
executor:true,
},
where:[
where:
{
executor:{
id:userId
}
},
]
})
return res.send({tasks})
})
......@@ -185,94 +197,54 @@ 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({
// relations:{
// // project:true,
// executor:true,
// project:{
// members:{
// user:true
// }
// }
// },
// where:
// {
// executor:{
// id:user.id
// },
// project:{
// members:{
// user:user,
// // roleProject:Not(MemberRole.WATCHER)
// }
// }
// }
// }
// )
const projectsRawId = await dataSource
.getRepository(Project)
.find({
select:{
id:true
},
where:{
title:Not(Equal("Не определено")),
members:{
user:{
id: user.id
},
roleProject:Not(MemberRole.WATCHER)
}
}
}
)
const projects = await dataSource
.getRepository(Project)
.find({
relations:{
members:{
user:true
}},
const projectsList= projectsRawId.map(project=> {return project.id})
const tasks = await dataSource
.getRepository(Task)
.find(
{relations:{
author:true,
executor:true,
project:true
},
where:{
title:Not(Equal("Не определено")),
members:{
user:{
id: user.id
executor:{
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:{
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})
})
)
const projects = await dataSource
.getRepository(Project)
.find({
relations:{
members:true
},
where:{
id:In(projectsList)
}
})
return res.send({tasks, projects})
})
/**return tasks & users of projects in which current user is involved, search by token*/
......@@ -336,7 +308,9 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
/**change of task by task id */
router.put('/:taskId',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
const {taskId} = req.params
const {authorStatus,executorStatus,title,description,note, archive,project,dateTimeTaskId,dateTimeStart,dateTimeDue,executor,accomplish,dateTimeDeadLine, dateTimeFactDeadLine,priority} = req.body;
const {authorStatus,executorStatus,title,description,note, archive,project,dateTimeTaskId,dateTimeStart,
dateTimeDue,executor,accomplish,dateTimeDeadLine, dateTimeFactDeadLine,priority} = req.body;
console.log('dateTimeTaskId ', dateTimeTaskId)
const task = await taskFinderById(taskId)
if (!task) return res.status(404).send({Message:'task not found'})
let dateTimeTask = null;
......
......@@ -8,18 +8,18 @@ import MultipleSelect from '../../components/UI/MultipleSelect/MultipleSelect';
import Add from "@mui/icons-material/Add";
import Close from "@mui/icons-material/Close";
export default function MyTaskToolBar({projects,onClose,projectName,setProjectName,formStatus,onClick}) {
export default function MyTaskToolBar({projects,onClose,projectIdListForTaskSelect,setProjectIdListForTaskSelect,formStatus,onClick}) {
let projectsFilter =
<></>
if (projects) {
if (Array.isArray(projects)) {
projectsFilter=
<MultipleSelect
projects={projects}
onClose={onClose}
projectName={projectName}
setProjectName={setProjectName}
projectName={projectIdListForTaskSelect}
setProjectName={setProjectIdListForTaskSelect}
/>
}
......
......@@ -35,7 +35,7 @@ export default function NewTaskForm({ projects, setAddTaskForm }) {
dateTimeDeadLine: null,
dateTimeTasks: [],
dateTimeDue: null,
project: projects[0],
project: null,
accomplish: "opened",
priority: "B",
author: { id: user.id },
......
......@@ -6,7 +6,12 @@ import FormControl from "@mui/material/FormControl";
import Select from "@mui/material/Select";
export default function BasicSelect({value,label,name,onChange,task,items}) {
console.log('select value ', value)
console.log('select label ', label)
console.log('select name ', name)
console.log('select task ', task)
console.log('select items ', items)
// console.log('select value ', value)
return (
<Box sx={{ minWidth: 60, m: 0}}>
<FormControl fullWidth>
......@@ -19,11 +24,11 @@ export default function BasicSelect({value,label,name,onChange,task,items}) {
name={name}
onChange={(e) => onChange(e, task)}
>
{items.map((item,index) => (
{items ?items.map((item,index) => (
<MenuItem key={index} value={item.value}>
{item.title}
</MenuItem>
))}
)):<></>}
</Select>
</FormControl>
</Box>
......
......@@ -40,7 +40,7 @@ export default function NewTaskForm({
dateTimeDeadLine: null,
dateTimeTasks: [],
dateTimeDue: null,
project: projects[0],
project: [],
accomplish: "opened",
priority: "B",
author: { id: user.id },
......@@ -240,13 +240,7 @@ export const header = [
disablePadding: true,
label: "Приоритет",
},
// {
// id: "createdAt",
// numeric: true,
// disablePadding: false,
// label: "Дата создания",
// },
{
{
id: "title",
numeric: false,
disablePadding: false,
......@@ -266,7 +260,7 @@ export const header = [
label: "Исполнитель",
},
{
id: "dateTimeDue",
id: "dateTimeDeadLine",
numeric: true,
disablePadding: false,
label: "Дедлайн",
......
......@@ -8,7 +8,7 @@ import MultipleSelect from '../UI/MultipleSelect/MultipleSelect';
import Add from "@mui/icons-material/Add";
import Close from "@mui/icons-material/Close";
export default function UsersTaskToolBar({projects,onClose,projectName,setProjectName,formStatus,onClick}) {
export default function UsersTaskToolBar({projects,onClose,projectIdListForTaskSelect,setProjectIdListForTaskSelect,formStatus,onClick}) {
let projectsFilter =
<></>
......@@ -18,8 +18,8 @@ export default function UsersTaskToolBar({projects,onClose,projectName,setProjec
<MultipleSelect
projects={projects}
onClose={onClose}
projectName={projectName}
setProjectName={setProjectName}
projectName={projectIdListForTaskSelect}
setProjectName={setProjectIdListForTaskSelect}
/>
}
......
......@@ -7,6 +7,7 @@ import PersonIcon from '@mui/icons-material/Person';
import styled from "@emotion/styled";
import { Alert, Avatar, Container, Typography } from "@mui/material";
import ResetPasswordForm from "../../components/UserForm/ResetPasswordForm";
import axios from "axios";
const StyledContainer = styled(Container)`
padding-top: 30px;
......
......@@ -34,7 +34,6 @@ export default function EnhancedTable() {
open: false,
task: null,
});
// const [projects, setProjects] = useState(["1", "2"]);
// useEffect(() => {
// dispatch(fetchAllTasks());
......@@ -42,14 +41,15 @@ export default function EnhancedTable() {
// }, [dispatch]);
useEffect(() => {
dispatch(fetchAllTasks());
if (tasks && tasks?.length > 0) {
setRecievedTasks(tasks);
}
}, [ tasks?.length]);
useEffect(() => {
dispatch(fetchAllTasks());
}, [addTaskForm, setAddTaskForm, dispatch]);
}, [ tasks?.length,addTaskForm, setAddTaskForm, dispatch]);
console.log('tasks ', tasks, 'projects ', projects)
// useEffect(() => {
// dispatch(fetchAllTasks());
// }, [addTaskForm, setAddTaskForm, dispatch]);
......@@ -112,7 +112,7 @@ export default function EnhancedTable() {
const onProjectChange = (e, task) => {
const value = e.target.value;
const project = uniqueProjects.find((e) => e.id === value);
const project = projects.find((e) => e.id === value);
const { id } = task;
const newTasks = recievedTasks.map((task) => {
if (task.id === id) {
......@@ -183,46 +183,33 @@ export default function EnhancedTable() {
};
// ++++++++фильтрация по проектам+++++++++++++++
const [projectName, setProjectName] = React.useState([]);
const [filterProjectTumbler, setFilterProjectTumbler] = React.useState(false);
const onClose = (projectName) => {
let tasksFilteredByProject = tasks;
if (projectName.length > 0) {
tasksFilteredByProject = tasks.filter((task) =>
projectName.includes(task.project?.title)
);
}
setRecievedTasks(tasksFilteredByProject);
setFilterProjectTumbler(true);
};
const rawProjects = tasks?.map((task) => task.project);
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);
}
};
const uniqueProjects = rawProjects?.reduce((results, value, index) => {
const exist = results.find((v) => {
return v !== null && v.id === value?.id;
});
if (!exist && value !== null) {
results.push(value);
}
return results;
}, []);
console.log('tasks', tasks)
const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = React.useState([]);
const [filterProjectTumbler, setFilterProjectTumbler] = React.useState(false);
const onClose=(projectIdListForTaskSelect)=>{
console.log('projectIdListForTaskSelect ', projectIdListForTaskSelect)
let tasksFilteredByProject = tasks
if (projectIdListForTaskSelect.length>0) {
tasksFilteredByProject = tasks.filter(task=>projectIdListForTaskSelect.includes(task.project?.id))
}
console.log('tasksFilteredByProject ', tasksFilteredByProject)
setRecievedTasks(tasksFilteredByProject)
setFilterProjectTumbler(true)
}
// const rawProjects = tasks?.map((task) => task.project);
// const uniqueProjects = rawProjects?.reduce((results, value, index) => {
// const exist = results.find((v) => {
// return v !== null && v.id === value?.id;
// });
// if (!exist && value !== null) {
// results.push(value);
// }
// return results;
// }, []);
// console.log('tasks', tasks)
if (
tasks &&
......@@ -238,13 +225,13 @@ console.log('tasks', tasks)
formStatus={addTaskForm}
projects={projects}
onClose={onClose}
projectName={projectName}
setProjectName={setProjectName}
projectIdListForTaskSelect={projectIdListForTaskSelect}
setProjectIdListForTaskSelect={setProjectIdListForTaskSelect}
/>
{addTaskForm ? (
<NewTaskForm
projects={uniqueProjects}
projects={projects}
setAddTaskForm={() => setAddTaskForm(false)}
/>
) : null}
......@@ -273,8 +260,7 @@ console.log('tasks', tasks)
onChange={onChange}
onModalOpen={onModalOpen}
onProjectChange={onProjectChange}
uniqueProjects={uniqueProjects}
onAuthorChange={onAuthorChange}
uniqueProjects={projects}
onDateChange={onDateChange}
onToggleEditMode={onToggleEditMode}
onToggleEditModeDone={onToggleEditModeDone}
......
......@@ -12,7 +12,7 @@ import { useDispatch, useSelector } from "react-redux";
import TaskModal from "../../components/UsersTasksCompoments/TaskModal/TaskModal";
import moment from "moment";
import UsersTaskToolBar from "../../components/UsersTasksCompoments/UsersTaskToolBar";
import { fetchAllTasks, deleteTask,editTask, deleteDateTimeTask , fetchAllTasksByMembership} from "../../store/actions/tasksActions";
import { 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";
......@@ -198,12 +198,6 @@ export default function UsersTasks() {
dispatch(deleteDateTimeTask(dateTimeTaskId))
}
const handleEditDateTimeTask=(dateTimeTask)=>{
console.log('edit by dateTImeTask')
// dispatch(handleEditDateTimeTask(dateTimeTask))
}
const onModalOpen = (event, task) => {
event.stopPropagation();
setModal({ ...modal, open: true, id: task.id });
......@@ -214,49 +208,21 @@ export default function UsersTasks() {
};
// ++++++++фильтрация по проектам+++++++++++++++
const [projectName, setProjectName] = React.useState([]);
const [projectIdListForTaskSelect, setProjectIdListForTaskSelect] = React.useState([]);
const [filterProjectTumbler, setFilterProjectTumbler] = React.useState(false);
const onClose=(projectName)=>{
console.log('projectName ', projectName)
const onClose=(projectIdListForTaskSelect)=>{
console.log('projectIdListForTaskSelect ', projectIdListForTaskSelect)
let tasksFilteredByProject = tasks
if (projectName.length>0) {
tasksFilteredByProject = tasks.filter(task=>projectName.includes(task.project?.id))
if (projectIdListForTaskSelect.length>0) {
tasksFilteredByProject = tasks.filter(task=>projectIdListForTaskSelect.includes(task.project?.id))
}
console.log('tasksFilteredByProject ', tasksFilteredByProject)
setRecievedTasks(tasksFilteredByProject)
setFilterProjectTumbler(true)
}
const rawProjects= tasks?.map(task=>task.project)
// 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)
// }
// }
const uniqueProjects = rawProjects?.reduce((results, value, index) => {
const exist = results.find((v) => {
return v !== null && v.id === value?.id
});
if (!exist && value !== null) {
results.push(value);
}
return results;
}, []);
if (
tasks &&
tasks?.length > 0 &&
......@@ -271,8 +237,8 @@ export default function UsersTasks() {
formStatus={addTaskForm}
projects={projects}
onClose={onClose}
projectName={projectName}
setProjectName={setProjectName}
projectIdListForTaskSelect={projectIdListForTaskSelect}
setProjectIdListForTaskSelect={setProjectIdListForTaskSelect}
/>
{addTaskForm ? (
......@@ -311,8 +277,7 @@ export default function UsersTasks() {
onProjectChange={onProjectChange}
executors={executors}
onExecutorChange={onExecutorChange}
uniqueProjects={uniqueProjects}
// onAuthorChange={onAuthorChange}
uniqueProjects={projects}
onDateChange={onDateChange}
onToggleEditMode={onToggleEditMode}
onToggleEditModeDone={onToggleEditModeDone}
......
......@@ -30,8 +30,8 @@ const fetchCalendarTasksSuccess = (tasks) => {
return {type: FETCH_CALENDAR_TASKS_SUCCESS, tasks}
};
const fetchAllTasksSuccess = (tasks) => {
return {type: FETCH_ALL_TASKS_SUCCESS, tasks}
const fetchAllTasksSuccess = (tasks,projects) => {
return {type: FETCH_ALL_TASKS_SUCCESS, tasks, projects}
};
......@@ -55,8 +55,8 @@ export const fetchAllTasks = () => {
return async (dispatch) => {
dispatch(fetchCalendarTasksRequest());
try {
const response = await axios.get("/tasks");
dispatch(fetchAllTasksSuccess(response.data.tasks))
const response = await axios.get("/tasks/my");
dispatch(fetchAllTasksSuccess(response.data.tasks,response.data.projects))
} catch (error) {
dispatch(fetchCalendarTasksFailure(error.response.data));
}
......
......@@ -78,8 +78,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_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};
......
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