error throw package added

parent d56c1f40
......@@ -18,6 +18,7 @@
"class-validator": "^0.13.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"mongoose": "^6.7.0",
"multer": "^1.4.5-lts.1",
"nanoid": "^3.3.4",
......@@ -3329,6 +3330,14 @@
"node": ">= 0.10.0"
}
},
"node_modules/express-async-errors": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/express-async-errors/-/express-async-errors-3.1.1.tgz",
"integrity": "sha512-h6aK1da4tpqWSbyCa3FxB/V6Ehd4EEB15zyQq9qe75OZBp0krinNKuH4rAY+S/U/2I36vdLAUFSjQJ+TFmODng==",
"peerDependencies": {
"express": "^4.16.2"
}
},
"node_modules/express/node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
......@@ -8887,6 +8896,12 @@
}
}
},
"express-async-errors": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/express-async-errors/-/express-async-errors-3.1.1.tgz",
"integrity": "sha512-h6aK1da4tpqWSbyCa3FxB/V6Ehd4EEB15zyQq9qe75OZBp0krinNKuH4rAY+S/U/2I36vdLAUFSjQJ+TFmODng==",
"requires": {}
},
"fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
......
......@@ -35,6 +35,7 @@
"class-validator": "^0.13.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"mongoose": "^6.7.0",
"multer": "^1.4.5-lts.1",
"nanoid": "^3.3.4",
......
import 'express-async-errors';
import express, { NextFunction, Request, Response, Router } from "express";
import { myDataSource } from "./app-data-source";
import { Task } from "./models/Task";
......@@ -59,7 +60,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
}
const {executorStatus, authorStatus} = req.body
if (!executorStatus && !authorStatus) {
res.status(403).send({message:'user is not authorized'})
return res.status(403).send({message:'user is not authorized'})
}
req.body={...req.body, task:task}
next()
......
import 'express-async-errors';
import express,{Router, Request, Response } from 'express';
import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source';
......@@ -196,8 +197,11 @@ 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>=>{
let projectsRawId =[]
try{
const user = req.body.user
const projectsRawId = await dataSource
projectsRawId = await dataSource
.getRepository(Project)
.find({
select:{
......@@ -245,7 +249,13 @@ router.get('/my',auth, async (req: Request, res: Response):Promise<Response>=>{
id:In(projectsList)
}
})
return res.send({tasks, projects})
} catch(e){
return res.status(502).send({message:(e as Error).message})
}
})
......@@ -386,6 +396,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
try{
const projectsWithTasks = await dataSource
.getRepository(Project)
.find(
......@@ -407,6 +418,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
}
}
}})
if (!projectsWithTasks) return res.status(404).send({Message:'projects not found'})
let tasks:Task[] = []
if (projectsWithTasks.length>0) {
......@@ -416,6 +428,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
}
}
}
const projectIds= projectsWithTasks.map(project=> {return project.id})
const projects = await dataSource
.getRepository(Project)
......@@ -430,9 +443,12 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
roleProject: Not(MemberRole.WATCHER)
}
},
})
return res.send({projects, tasks})
} catch(e){
console.log('Error: ',(e as Error).message);
return res.status(502).send({message:(e as Error).message})
}
})
......
......@@ -6,11 +6,6 @@ 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)
return (
<Box sx={{ minWidth: 60, m: 0}}>
<FormControl fullWidth>
......@@ -20,7 +15,6 @@ export default function BasicSelect({value,label,name,onChange,task,items}) {
id="demo-simple-select"
value={value}
defaultValue=''
// displayEmpty={true}
label={label}
name={name}
onChange={(e) => onChange(e, task)}
......
......@@ -178,7 +178,7 @@ export default function NewTaskForm({
task={task}
onChange={onExecutorChange}
name="executor"
value={task.executor?.id}
value={task?.executor?.id}
defaultValue={user.id}
/>
</TableCell>
......
import * as React from "react";
import React,{useState} from "react";
import {
TableCell,
TableRow,
......@@ -33,17 +33,20 @@ const TableRowTask= ({
deleteDateTimeTask,
onChange,
onModalOpen,
onProjectChange,
onExecutorChange,
// onProjectChange,
// onExecutorChange,
uniqueProjects,
executors,
onAuthorChange,
// executors,
onDateChange,
onToggleEditMode,
onToggleEditModeDone,
})=>{
const [open, setOpen] = React.useState(false);
const [open, setOpen] = useState(false);
const [defaultExecutor, setDefaultExecutor] = useState(task.executor?.id)
const [executors, setExecutors]=useState([])
const [currentProject, setCurrentProject] = useState(null);
const [recievedTasks, setRecievedTasks] = useState([]);
const roudHourUp =(dateIso)=>{
let m = moment(dateIso);
......@@ -61,6 +64,64 @@ const TableRowTask= ({
return weekDays[date.day()];
}
const onProjectChange = (e, task) => {
e.preventDefault()
setDefaultExecutor(user)
const projectId = e.target.value;
const project = uniqueProjects.length>0 ?uniqueProjects.find((uniqueProject) => uniqueProject.id === projectId):null;
console.log('change project ', project)
setCurrentProject(project)
let executorList=[]
if(project?.members){
for (let member of project.members){
executorList.push(member.user)
}
}
setExecutors(executorList)
// const { id } = task;
// const newTasks = recievedTasks.map((task) => {
// if (task.id === id) {
// const updated = { ...task };
// updated.project = project;
// updated.projectName =project.title? project.title:null;
// return updated;
// }
task.project = project;
task.projectName=project.title? project.title:null;
return task;
// });
// setRecievedTasks(newTasks);
};
const onExecutorChange = (e, task) => {
const executorId = e.target.value;
const executor = executors.find((executor) => executor.id === executorId);
// const { id } = task;
// const newTasks = recievedTasks.map((task) => {
// if (task.id === id) {
// const updated = { ...task };
// updated.executor = executor;
// updated.executorName = executor.displayName;
// return updated;
// }
// return task;
// });
// setRecievedTasks(newTasks);
task.executor = executor;
task.executorName = executor.displayName;
return task;
};
return (
<>
<TableRow hover key={task.id}>
......@@ -159,7 +220,7 @@ const TableRowTask= ({
task={task}
onChange={onExecutorChange}
name="executor"
value={task.executor?.id}
defaultValue={defaultExecutor?.id}
/>
</TableCell>
) : (
......@@ -180,19 +241,11 @@ const TableRowTask= ({
task,
name: "author",
value: task.author.displayName,
// onChange: onAuthorChange,
user:user
}}
/>
{task.isEditMode && task.author.id===user.id ? (
<TableCell>
{/* <MaterialUIPickers
task={task}
name="dateTimeStart"
onChange={onDateChange}
user={user}
/> */}
{/* <TableCell> */}
<Tooltip title="Перейти в календарь">
<IconButton
onClick={(id) => { deleteHandle(task.id);}}
......@@ -200,7 +253,6 @@ const TableRowTask= ({
<CalendarMonthIcon />
</IconButton>
</Tooltip>
{/* </TableCell> */}
</TableCell>
) : (
......@@ -236,15 +288,6 @@ const TableRowTask= ({
)}
{/* <TableCell>
<MaterialUIPickers
task={task}
name="dateTimeStart"
onChange={onDateChange}
user={user}
/>
</TableCell> */}
{task.isEditMode && task.author.id===user.id ? (
<TableCell>
<MaterialUIPickers
......@@ -373,26 +416,7 @@ const TableRowTask= ({
<TableCell
// style={{width:'0%'}}
>
{/* <Tooltip title="Редактировать Копию">
{task.isEditMode ? (
<IconButton
aria-label="done"
onClick={() => {
onToggleEditModeDone(dateTimeTask.id);
handleEditDateTimeTask(dateTimeTask);
}}
>
<Done />
</IconButton>
) : (
<IconButton
aria-label="edit"
onClick={() => onToggleEditMode(dateTimeTask.id)}
>
<Edit />
</IconButton>
)}
</Tooltip> */}
</TableCell >
{/* delete option datetimeTask */}
......
......@@ -27,6 +27,7 @@ export default function UsersTasks() {
const user = useSelector((state) => state.users.user);
const [executors, setExecutors]=useState([])
// const [currentExecutor, setCurrentExecutor]= useState(task.executor.id?task.executor:'')
const [currentProject, setCurrentProject] = useState(null);
const [recievedTasks, setRecievedTasks] = useState([]);
const [addTaskForm, setAddTaskForm] = useState(false);
......@@ -39,6 +40,7 @@ export default function UsersTasks() {
task: null,
});
useEffect(() => {
dispatch(fetchAllTasksByMembership());
if (tasks && tasks?.length > 0) {
......@@ -152,6 +154,7 @@ export default function UsersTasks() {
const onToggleEditModeDone = (id) => {
const newTasks = recievedTasks.map((task) => {
if (task.id === id) {
console.log('toggledDone task ', task)
return {
...task,
isEditMode: false,
......
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