Revert "Merge branch 'task-74-enhance/watcher_rights' into 'development'"

This reverts merge request !80
parent 808b2857
......@@ -4,8 +4,12 @@ import {
PrimaryGeneratedColumn,
CreateDateColumn,
BaseEntity,
ManyToOne,
ManyToMany,
OneToMany,
JoinTable
} from 'typeorm';
// import {User} from './User';
import {Task} from './Task';
import {Member} from './Member';
......
......@@ -2,21 +2,24 @@ import express,{Router, Request, Response } from 'express';
import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source';
import { DateTimeTask } from '../models/DateTimeTask';
import { authAuthorOrExecutorOfDateTimeTask, authAuthorOrExecutorOfTask } from '../helpers';
import { auth, authAuthorOrExecutorOfDateTimeTask, authAuthorOrExecutorOfTask,taskFinderById } from '../helpers';
import { info } from 'console';
const router:Router = express.Router();
const dataSource = myDataSource;
/** make copy of task in calendar view */
router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Response):Promise<Response>=>{
const {taskId, dateTimeDue, dateTimeStart, authorStatus, executorStatus, task} = req.body;
const {taskId, dateTimeDue, dateTimeStart} = req.body;
const task = await taskFinderById(taskId);
if(!task) return res.status(401).send({message:'task with possible user involved is not found'})
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStart;
newDateTimeTask.dateTimeDue = dateTimeDue;
newDateTimeTask.task = taskId;
await newDateTimeTask.save();
return res.send({task, message:"copyTask created!"})
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStart;
newDateTimeTask.dateTimeDue = dateTimeDue;
newDateTimeTask.task = taskId;
await newDateTimeTask.save();
return res.send({task})
} )
/** change date time of copy of task in calendar view */
......
......@@ -117,6 +117,11 @@ router.get('/user/:userId', async (req : Request, res : Response): Promise<Respo
return res.send({userProjects})
})
/** Add user to specific project */
router.post('/add-user/', authAdminProject, async (req: Request, res: Response):Promise<Response>=>{
......
......@@ -2,11 +2,10 @@ import express,{Router, Request, Response } from 'express';
import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source';
import { User } from '../models/User';
import { Member, MemberRole } from '../models/Member';
import { Member } from '../models/Member';
import { In } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfTask, taskFinderById } from '../helpers';
import { Project } from '../models/Project';
const router:Router = express.Router();
const dataSource = myDataSource;
......@@ -30,56 +29,7 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
const newTask = new Task();
newTask.title = title;
newTask.description = description;
if (project) {
const watcherOfProject = await dataSource
.getRepository(Project)
.findOne({
relations:{
members:true,
},
where:
{
id:project.id,
members:
{
user:{id:user.id},
roleProject:MemberRole.WATCHER,
},
}
})
console.log ('watcherOfProject ', watcherOfProject)
if (watcherOfProject) return res.send({message:"watcher could nt make tasks"})
newTask.project = project;
} else {
const personalProject = await dataSource
.getRepository(Project)
.findOne({
where:{
members:{
user:{id:user.id},
},
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();
console.log ('newPersonalProject ', newPersonalProject)
}
}
newTask.dateTimeDeadLine=dateTimeDeadLine;
newTask.author= user;
newTask.executor= executor;
......
......@@ -62,24 +62,8 @@ router.get('/all-fields/', async (req : Request, res : Response):Promise<object>
},
}
})
console.log('all fields users ', users)
return res.send({users})
})
//** return displayName of user, requested by userId */
router.get('/display-name/:userId',auth, async (req : Request, res : Response):Promise<object> => {
const {userId} =req.params
const displayName = await dataSource
.createQueryBuilder()
.select(['user.displayName'])
.from(User, "user")
.where("user.id = :userId", { userId })
.getOne()
if (!displayName) return res.status(404).send({message:'displayName not found'})
return res.send({displayName})
})
})
/**create new user*/
router.post('/', upload.single("avatar"), async (req : Request, res : Response):Promise<object> => {
......
......@@ -30,6 +30,7 @@ const ProfileBlock = () => {
}
const switchUser=()=>{
dispatch(fetchUsersAllFields());
// dispatch(fetchUsers())
handleClose()
handleOpenSwitchUser()
}
......
......@@ -17,20 +17,19 @@ const SwitchUserForm=({submitFormHandler, users})=> {
useEffect(()=>{
if(currentUser?.members.length>0) {
let dataArray=[]
for (let member of currentUser.members ) {
const newProjectRole = {
"projectName":member.project.title,
"roleName":member.roleProject
}
dataArray.push(newProjectRole)
setProjectsRole([...projectsRoles, newProjectRole ])
}
setProjectsRole(dataArray)
}
},[ currentUser])
return (
<>
{/* <Box sx={style}> */}
{users?
<form onSubmit={(e)=>submitFormHandler(e,currentUser)}>
<Grid container direction="column" spacing={2}>
......@@ -67,7 +66,15 @@ const SwitchUserForm=({submitFormHandler, users})=> {
</Button>
</Grid>
{/* <Grid item>
<Button
onClick={()=>console.log('cancel form')}
color="primary"
variant="contained"
>
Отмена
</Button>
</Grid> */}
</Grid>
</Grid>
......@@ -75,6 +82,7 @@ const SwitchUserForm=({submitFormHandler, users})=> {
: <></>}
{/* </Box> */}
</>
)
}
......
......@@ -9,6 +9,7 @@ import Paper from '@mui/material/Paper';
const SwitchUserTable=({projectsRoles})=>{
return (
<TableContainer component={Paper}>
......@@ -30,8 +31,7 @@ const SwitchUserTable=({projectsRoles})=>{
</TableRow>
</TableHead>
<TableBody>
{projectsRoles.map((projectRole,index) =>{ return (
{projectsRoles.map((projectRole,index) => (
<TableRow
key={index}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
......@@ -41,7 +41,7 @@ const SwitchUserTable=({projectsRoles})=>{
</TableCell>
<TableCell align="right">{projectRole.roleName}</TableCell>
</TableRow>
)})}
))}
</TableBody>
</Table>
</TableContainer>
......
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