Merge branch 'task-166-enhance/optimize_router_tasks_requests' into 'development'

Task 166 enhance/optimize router tasks requests

See merge request !134
parents d0b9e49f b60d8caf
......@@ -14,7 +14,6 @@ function randomIntFromInterval(min:number, max:number) {
return Math.floor(Math.random() * (max - min) + min);
}
let countMembers =0
let countRolesProject=0
const cycleThroughObject=(countKey:number,objectObserve:any):MemberRole=>{
......@@ -27,14 +26,8 @@ const cycleThroughObject=(countKey:number,objectObserve:any):MemberRole=>{
}
return valueOfKey
}
const cycleArrayOfMembers=(countIndex:number, members:Member[]):Member=>{
let member = members[countIndex]
countIndex++
if (countIndex ===members.length-1){
countIndex=0
}
return member
}
const loadFixtures = async () => {
......@@ -103,7 +96,6 @@ const loadFixtures = async () => {
let currentTime = new Date()
let startdateOfMonth = randomIntFromInterval(20, 24)
let enddateOfMonth = randomIntFromInterval(25, 29)
let deadLineDateOfMonth = randomIntFromInterval(1, 10)
let startDateTime = new Date(currentTime.getFullYear(), currentTime.getMonth()+1,startdateOfMonth , randomIntFromInterval(11, 18), 0, 0);
let dueDateTime = new Date(currentTime.getFullYear(), currentTime.getMonth()+1,startdateOfMonth, randomIntFromInterval(19, 20), 0, 0);
let deadLine = new Date(currentTime.getFullYear(), currentTime.getMonth()+2, enddateOfMonth, randomIntFromInterval(20, 22), 0, 0);
......
......@@ -11,7 +11,6 @@ import { Project } from '../models/Project';
const router:Router = express.Router();
const dataSource = myDataSource;
/**get all tasks */
router.get('/', async(req:Request, res:Response):Promise<Response> => {
try{
......@@ -33,19 +32,14 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
try{
const {user,title,description,project,executor,dateTimeStart,dateTimeDue, dateTimeDeadLine,priority, calendar} = req.body;
let dateTimeDueFinal = dateTimeDue
let dateTimeStartFinal = dateTimeStart
const dateTimeDeadlineFinal= dateTimeDeadLine
if (!dateTimeDue && dateTimeDeadLine) {
dateTimeDueFinal = dateTimeDeadLine
dateTimeStartFinal = subtractHours(dateTimeDueFinal, 1)
}
let dateTimeDueFinal = dateTimeDue ?? dateTimeDeadLine;
let dateTimeStartFinal = dateTimeStart ?? subtractHours(dateTimeDueFinal, 1);
const newTask = new Task();
newTask.title = title;
newTask.description = description;
if (project) {
const watcherOfProject = await dataSource
.getRepository(Project)
.findOne({
......@@ -75,22 +69,9 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
title:"Личные дела"
}
})
if(personalProject){
newTask.project = personalProject;
} else {
const newPersonalProject = new Project();
newPersonalProject.title="Личные дела";
newPersonalProject.color="green";
await newPersonalProject.save()
newTask.project = newPersonalProject;
const newMember = new Member();
newMember.user= user;
newMember.project=newPersonalProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
}
if (personalProject) newTask.project = personalProject;
}
newTask.dateTimeDeadLine= dateTimeDeadlineFinal;
newTask.author= user;
if(newTask.project.title==="Личные дела"){
......@@ -152,20 +133,7 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=>
title:"Не определено"
}
})
if(personalProject){
newTask.project = personalProject;
} else {
const newPersonalProject = new Project();
newPersonalProject.title="Не определено";
newPersonalProject.color="green";
await newPersonalProject.save()
newTask.project = newPersonalProject;
const newMember = new Member();
newMember.user= user;
newMember.project=newPersonalProject;
newMember.roleProject = MemberRole.ADMIN;
await newMember.save();
}
if(personalProject) newTask.project = personalProject;
}
newTask.dateTimeDeadLine=dateTimeDeadLine;
......@@ -202,8 +170,7 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
{
executor:{
id:userId
}
},
}},
})
return res.send({tasks})
} catch(e){
......@@ -230,9 +197,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
id: user.id
},
roleProject:Not(MemberRole.WATCHER)
}
}
}
}}}
)
const projectsList= projectsRawId.map(project=> {return project.id})
......@@ -250,9 +215,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
},
project:{
id:In(projectsList)
}
}
}
}}}
)
const projects = await dataSource
.getRepository(Project)
......@@ -262,8 +225,7 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
},
where:{
id:In(projectsList)
}
})
}})
return res.send({tasks, projects})
} catch(e){
return res.status(502).send({message:(e as Error).message})
......@@ -307,9 +269,7 @@ router.get('/related', auth,async (req: Request, res: Response):Promise<Response
members:
{project:In(
projectsIdArray
)}
}
})
)}}})
}
return res.send({tasks, users})
} catch(e){
......@@ -424,7 +384,6 @@ 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
......
import { useEffect, useCallback, useState, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
// import CalendarModalWorkerContent from '../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent';
// import MonthCalendarBody from '../../components/Calendars/MonthCalendar/MonthCalendarBody/MonthCalendarBody';
// import MonthCalendarHeader from '../../components/Calendars/MonthCalendar/MonthCalendarHeader/MonthCalendarHeader';
// import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import CalendarModalWorkerContent from '../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent';
import MonthCalendarBody from '../../components/Calendars/MonthCalendar/MonthCalendarBody/MonthCalendarBody';
import MonthCalendarHeader from '../../components/Calendars/MonthCalendar/MonthCalendarHeader/MonthCalendarHeader';
import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import { dateToISOLikeButLocal, getCurrentMonthString, getDaysInMonth } from '../../helpers/CalendarHelpers';
import { fetchAllUserProjects, fetchProject } from '../../store/actions/projectsActions';
import { addCalendarTask, addCopyCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions';
import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions';
import { AllHoursOneHourFormat, AllHoursTwoHourFormat } from '../../constants';
// make components mentioned above in lazy import
import { lazy ,Suspense} from 'react';
const CalendarModalWorkerContent = lazy(() => import('../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent'));
const MonthCalendarBody = lazy(() => import('../../components/Calendars/MonthCalendar/MonthCalendarBody/MonthCalendarBody'));
const MonthCalendarHeader = lazy(() => import('../../components/Calendars/MonthCalendar/MonthCalendarHeader/MonthCalendarHeader'));
const DefaultModal = lazy(() => import('../../components/UI/DefaultModal/DefaultModal'));
function MonthCalendar() {
const dispatch = useDispatch();
......
import Paper from '@mui/material/Paper';
// import MyTasksTableToolbar from '../../components/MyTasksCompoments/MyTasksTableToolbar/MyTasksTableToolbar';
// import MyTasksTablePagination from '../../components/MyTasksCompoments/MyTasksTablePagination/MyTasksTablePagination';
// import MyTasksTableContainer from '../../components/MyTasksCompoments/MyTasksTableContainer/MyTasksTableContainer';
import MyTasksTableToolbar from '../../components/MyTasksCompoments/MyTasksTableToolbar/MyTasksTableToolbar';
import MyTasksTablePagination from '../../components/MyTasksCompoments/MyTasksTablePagination/MyTasksTablePagination';
import MyTasksTableContainer from '../../components/MyTasksCompoments/MyTasksTableContainer/MyTasksTableContainer';
import { activateCreateCopyTasksMode, fetchAllTasks, sortTaskByProjects, addTask, deleteTask, deleteDateTimeTask, editTask } from '../../store/actions/tasksActions';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useCallback, useEffect, useState } from 'react';
......@@ -9,12 +9,6 @@ import { fetchAllUserProjects, fetchProjects } from '../../store/actions/project
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
// make components mentioned above in lazy import
import { lazy , Suspense} from "react";
const MyTasksTableToolbar = lazy(() => import("../../components/MyTasksCompoments/MyTasksTableToolbar/MyTasksTableToolbar"));
const MyTasksTablePagination = lazy(() => import("../../components/MyTasksCompoments/MyTasksTablePagination/MyTasksTablePagination"));
const MyTasksTableContainer = lazy(() => import("../../components/MyTasksCompoments/MyTasksTableContainer/MyTasksTableContainer"));
export default function MyTasks() {
const dispatch = useDispatch();
......
......@@ -2,17 +2,11 @@ import { Grid } from "@mui/material";
import { useCallback, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { createProject, deleteProject, fetchProjects } from "../../store/actions/projectsActions";
// import FullProject from "../FullProject/FullProject";
// import ProjectsWrapper from "../../components/ProjectsComponents/ProjectsWrapper/ProjectsWrapper";
// import DefaultModal from "../../components/UI/DefaultModal/DefaultModal";
import FullProject from "../FullProject/FullProject";
import ProjectsWrapper from "../../components/ProjectsComponents/ProjectsWrapper/ProjectsWrapper";
import DefaultModal from "../../components/UI/DefaultModal/DefaultModal";
import NewProjectModalContent from "../../components/ProjectsComponents/NewProjectModalContent/NewProjectModalContent";
// make components mentioned above in lazy import
import { lazy , Suspense} from "react";
const FullProject = lazy(() => import("../FullProject/FullProject"));
const ProjectsWrapper = lazy(() => import("../../components/ProjectsComponents/ProjectsWrapper/ProjectsWrapper"));
const DefaultModal = lazy(() => import("../../components/UI/DefaultModal/DefaultModal"));
const Projects = () => {
const { projects } = useSelector(state => state.projects.projects);
const { user } = useSelector(state => state.users)
......
......@@ -3,29 +3,18 @@ import { useEffect, useState, useMemo, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
// import CreateCopyTasksModeBlock from '../../components/Calendars/CreateCopyTasksModeBlock/CreateCopyTasksModeBlock';
// import CalendarModalWorkerContent from '../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent';
// import WeekCalendarBody from '../../components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody';
// import WeekCalendarHeader from '../../components/Calendars/WeekCalendar/WeekCalendarHeader/WeekCalendarHeader';
// import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import CreateCopyTasksModeBlock from '../../components/Calendars/CreateCopyTasksModeBlock/CreateCopyTasksModeBlock';
import CalendarModalWorkerContent from '../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent';
import WeekCalendarBody from '../../components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody';
import WeekCalendarHeader from '../../components/Calendars/WeekCalendar/WeekCalendarHeader/WeekCalendarHeader';
import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import { AllHoursOneHourFormat, AllHoursTwoHourFormat } from '../../constants';
import { getWeekInfoString, getWeekFromCurrentDate, dateToISOLikeButLocal } from '../../helpers/CalendarHelpers';
import { fetchAllUserProjects } from '../../store/actions/projectsActions';
import { addCalendarTask, addCopyCalendarTask, deactivateCreateCopyTasksMode, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions';
import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions';
// make components mentioned above in lazy import
import { lazy, Suspense } from 'react';
const WeekCalendarBody = lazy(() => import('../../components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody'));
const WeekCalendarHeader = lazy(() => import('../../components/Calendars/WeekCalendar/WeekCalendarHeader/WeekCalendarHeader'));
const CreateCopyTasksModeBlock = lazy(() => import('../../components/Calendars/CreateCopyTasksModeBlock/CreateCopyTasksModeBlock'));
const CalendarModalWorkerContent = lazy(() => import('../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent'));
const DefaultModal = lazy(() => import('../../components/UI/DefaultModal/DefaultModal'));
function WeekCalendar() {
const dispatch = useDispatch();
const navigate = useNavigate()
......
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