Merge branch 'task-167-enhance/projects_non_watcher' into 'development'

Task 167 enhance/projects non watcher

See merge request !135
parents cabc6242 f1324776
......@@ -17,6 +17,10 @@ router.get('/',async (req:Request, res:Response): Promise<Response>=> {
}
})
/**get projects were user is member, by user token */
router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
try{
......@@ -26,7 +30,6 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
.from(Project, "project")
.select(["project.id"])
.leftJoinAndSelect('project.members', 'member')
.loadRelationCountAndMap('project.tasks', 'project.tasks')
.leftJoinAndSelect('member.user', 'user' )
.where('member.userId = :userId',{userId:user.id})
.getMany()
......@@ -34,9 +37,7 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
if (rawProjects.length>0){
for(let project of rawProjects){
projectIds.push(project.id
)
}
}
)}}
const projects = await dataSource
.createQueryBuilder()
.from(Project, "project")
......@@ -53,27 +54,25 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
})
/**create new project */
router.post('/',auth, async (req:Request, res:Response): Promise<Response> => {
try{
if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'})
const {user, title,color}= req.body;
const titleTrimed = title.trim()
const projectCheck = await dataSource
.getRepository(Project)
.find({
where:{
title:title
}
})
if(projectCheck.length>0) {return res.status(400).send({message:"suchc Project already exists"})}
title:titleTrimed
}})
if(projectCheck.length>0) {return res.status(400).send({message:"such Project already exists"})}
const member:Member = new Member;
member.user= user;
member.roleProject= MemberRole.ADMIN;
await member.save();
const project : Project= new Project()
project.title = title;
project.title = titleTrimed;
project.color = color;
project.members=[member]
await project.save()
......@@ -105,10 +104,7 @@ try{
where:{
project:{
id:req.params.id
}
}
}
)
}}})
return res.send({project, tasks})
} catch(e) {
return res.status(502).send({message:(e as Error).message})
......@@ -188,8 +184,7 @@ router.delete('/remove-user/:userId', authAdminProject,async (req: Request, res:
project:{
id:projectId
}
}
})
}})
if(!projectMember) return res.status(404).send({message:"this member is not present"})
await Member.delete({id:projectMember.id})
return res.send({message:"User removed from project successfully" })
......@@ -225,4 +220,27 @@ router.put('/change-project-role/:userId',authAdminProject, async (req: Request
})
/** return projects where user's member.role not equal 'watcher' */
router.get('/task_create/:userId', async (req : Request, res : Response): Promise<Response>=>{
try{
const userId = req.params.userId
const userProjects = await dataSource
.createQueryBuilder()
.select('project')
.from(Project, "project")
.leftJoinAndSelect('project.members', 'member')
.leftJoinAndSelect('member.user', 'user' )
.where("user.id = :id", { id: userId })
.andWhere("member.roleProject != :role", {role:MemberRole.WATCHER})
.getMany();
return res.send({userProjects})
} catch(e) {
return res.status(502).send({message:(e as Error).message})
}
})
export default router;
......@@ -40,23 +40,6 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
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,
},
}
})
if (watcherOfProject) return res.send({message:"watcher could nt make tasks"})
newTask.project = project;
} else {
const personalProject = await dataSource
......@@ -71,14 +54,9 @@ router.post('/', auth, async(req:Request, res:Response):Promise<Response>=>{
})
if (personalProject) newTask.project = personalProject;
}
newTask.dateTimeDeadLine= dateTimeDeadlineFinal;
newTask.author= user;
if(newTask.project.title==="Личные дела"){
newTask.executor=user;
} else {
newTask.executor= executor;
}
newTask.project.title==="Личные дела"? newTask.executor=user: newTask.executor= executor;
newTask.priority = priority;
await newTask.save();
if (calendar) {
......@@ -104,23 +82,6 @@ router.post('/users', auth, async(req:Request, res:Response):Promise<Response>=>
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,
},
}
})
if (watcherOfProject) return res.send({message:"watcher could nt make tasks"})
newTask.project = project;
} else {
const personalProject = await dataSource
......@@ -396,19 +357,15 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
tasks:{
author:true,
executor:true
}
},
}},
where:{
members:{
roleProject:Not(Equal(MemberRole.WATCHER)),
user:{
id:user.id
},
project:{
title:Not(Equal("Личные дела"))
}
}
}})
}}}})
if (!projectsWithTasks) return res.status(404).send({Message:'projects not found'})
let tasks:Task[] = []
......@@ -416,10 +373,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
for (const project of projectsWithTasks){
if (project?.tasks) {
tasks=tasks.concat(project.tasks)
}
}
}
}}}
const projectIds= projectsWithTasks.map(project=> {return project.id})
const projects = await dataSource
.getRepository(Project)
......@@ -432,9 +386,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
id:In(projectIds),
members:{
roleProject: Not(MemberRole.WATCHER)
}
},
})
}},})
return res.send({projects, tasks})
} catch(e){
console.log('Error: ',(e as Error).message);
......
......@@ -5,7 +5,7 @@ import MyTasksTableContainer from '../../components/MyTasksCompoments/MyTasksTab
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';
import { fetchAllUserProjects, fetchProjects } from '../../store/actions/projectsActions';
import { fetchAllUserProjects, fetchProjects,fetchProjectsNonWatcherForTaskCreate } from '../../store/actions/projectsActions';
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
......@@ -17,7 +17,6 @@ export default function MyTasks() {
const { user } = useSelector((state) => state.users);
const { tasks, sortedTasks } = useSelector((state) => state.tasks, shallowEqual);
const { allUserProjectsForModalTask, projects } = useSelector(state => state.projects, shallowEqual)
const [newTask, setNewTask] = useState({
priority: '',
title: '',
......@@ -118,8 +117,11 @@ export default function MyTasks() {
dateTimeDeadLine: null
})
}
dispatch(fetchProjectsNonWatcherForTaskCreate(user.id))
setAddFormStatus((prevState) => { return !prevState })
}, [addFormStatus])
}, [])
const createNewTaskHandler = useCallback(() => {
const task = {
......
......@@ -5,15 +5,10 @@ import UsersTasksTableContainer from '../../components/UsersTasksCompoments/User
import { activateCreateCopyTasksMode, addTaskToUserTasksTable, deleteDateTimeTaskUsers, deleteTaskUsers, editTaskUsers, fetchAllTasksByMembership, sortTaskByProjects } from '../../store/actions/tasksActions';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useCallback, useEffect, useState } from 'react';
import { fetchAllUserProjects, fetchProjects } from '../../store/actions/projectsActions';
import { fetchAllUserProjects, fetchProjects, fetchProjectsNonWatcherForTaskCreate } from '../../store/actions/projectsActions';
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
import { lazy } from "react";
// const UsersTasksTableToolbar = lazy(() => import("../../components/UsersTasksCompoments/UsersTasksTableToolbar/UsersTasksTableToolbar"));
// const UsersTasksTablePagination = lazy(() => import("../../components/UsersTasksCompoments/UsersTasksTablePagination/UsersTasksTablePagination"));
// const UsersTasksTableContainer = lazy(() => import("../../components/UsersTasksCompoments/UsersTasksTableContainer/UsersTasksTableContainer"));
export default function UsersTasks() {
const dispatch = useDispatch();
......@@ -21,6 +16,7 @@ export default function UsersTasks() {
const { tasks, sortedTasks } = useSelector((state) => state.tasks, shallowEqual);
const { allUserProjectsForModalTask, projects } = useSelector(state => state.projects, shallowEqual)
const { user } = useSelector((state) => state.users);
const [newTask, setNewTask] = useState({
priority: '',
......@@ -125,8 +121,9 @@ export default function UsersTasks() {
dateTimeDeadLine: null
})
}
dispatch(fetchProjectsNonWatcherForTaskCreate(user.id))
setAddFormStatus((prevState) => { return !prevState })
}, [addFormStatus])
}, [])
const createNewTaskHandler = useCallback(() => {
if (newTask.priority === '' || newTask.project === '' || newTask.executor === '') {
......
......@@ -19,4 +19,10 @@ export const DELETE_PROJECT_FAILURE = "DELETE_PROJECT_FAILURE";
export const CHANGE_MEMBER_ROLE_REQUEST = "CHANGE_MEMBER_ROLE_REQUEST";
export const CHANGE_MEMBER_ROLE_SUCCESS = "CHANGE_MEMBER_ROLE_SUCCESS";
export const CHANGE_MEMBER_ROLE_FAILURE = "CHANGE_MEMBER_ROLE_FAILURE";
\ No newline at end of file
export const CHANGE_MEMBER_ROLE_FAILURE = "CHANGE_MEMBER_ROLE_FAILURE";
export const FETCH_PROJECTS_NON_WATCHER_REQUEST = "FETCH_PROJECTS_NON_WATCHER_REQUEST";
export const FETCH_PROJECTS_NON_WATCHER_SUCCESS = "FETCH_PROJECTS_NON_WATCHER_SUCCESS";
export const FETCH_PROJECTS_NON_WATCHER_FAILURE = "FETCH_PROJECTS_NON_WATCHER_FAILURE";
......@@ -33,4 +33,9 @@ export const FETCH_ALL_TASKS_BY_MEMBERSHIP_FAILURE = "FETCH_ALL_TASKS_BY_MEMBERS
export const ACTIVATE_CREATE_COPY_TASKS_MODE = "ACTIVATE_CREATE_COPY_TASKS_MODE"
export const DEACTIVATE_CREATE_COPY_TASKS_MODE = "DEACTIVATE_CREATE_COPY_TASKS_MODE"
export const SORT_TASKS = "SORT_TASKS"
\ No newline at end of file
import axios from "../../axiosPlanner";
import { CHANGE_MEMBER_ROLE_FAILURE, CHANGE_MEMBER_ROLE_REQUEST, CHANGE_MEMBER_ROLE_SUCCESS, CREATE_MEMBER_SUCCESS, CREATE_PROJECT_SUCCESS, DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, DELETE_PROJECT_FAILURE, DELETE_PROJECT_REQUEST, DELETE_PROJECT_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
import { CHANGE_MEMBER_ROLE_FAILURE,
CHANGE_MEMBER_ROLE_REQUEST,
CHANGE_MEMBER_ROLE_SUCCESS,
CREATE_MEMBER_SUCCESS,
CREATE_PROJECT_SUCCESS,
DELETE_MEMBER_FAILURE,
DELETE_MEMBER_REQUEST,
DELETE_MEMBER_SUCCESS,
DELETE_PROJECT_FAILURE,
DELETE_PROJECT_REQUEST,
DELETE_PROJECT_SUCCESS,
FETCH_ALL_USER_PROJECTS_SUCCESS,
FETCH_PROJECTS_ERROR,
FETCH_PROJECTS_REQUEST,
FETCH_PROJECTS_SUCCESS,
FETCH_PROJECT_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_REQUEST,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_FAILURE
} from "../actionTypes/projectsActionTypes";
import { showNotification } from "./commonActions";
const fetchProjectsRequest = () => {
......@@ -164,3 +184,26 @@ export const changeMemberRole = (userId, data) => {
}
}
const fetchProjectsNonWatcherRequest = () => {
return { type: FETCH_PROJECTS_NON_WATCHER_REQUEST }
};
const fetchProjectsNonWatcherSuccess = (projects) => {
return { type: FETCH_PROJECTS_NON_WATCHER_SUCCESS, projects }
};
const fetchProjectsNonWatcherFailure = (error) => {
return { type: FETCH_PROJECTS_NON_WATCHER_FAILURE, error }
};
export const fetchProjectsNonWatcherForTaskCreate = (userId) => {
return async (dispatch) => {
dispatch(fetchProjectsNonWatcherRequest());
try {
const response = await axios.get(`/projects/task_create/${userId}`);
dispatch(fetchProjectsNonWatcherSuccess(response.data.projects))
} catch (error) {
dispatch(fetchProjectsNonWatcherFailure(error));
}
}
};
\ No newline at end of file
......@@ -21,7 +21,9 @@ import {
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
DEACTIVATE_CREATE_COPY_TASKS_MODE,
ACTIVATE_CREATE_COPY_TASKS_MODE,
SORT_TASKS
SORT_TASKS,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_FAILURE,
} from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner'
......@@ -54,6 +56,7 @@ export const fetchCalendarTasks = (userId) => {
}
};
export const fetchAllTasks = () => {
return async (dispatch) => {
dispatch(fetchCalendarTasksRequest());
......
import { CHANGE_MEMBER_ROLE_FAILURE, CHANGE_MEMBER_ROLE_REQUEST, CHANGE_MEMBER_ROLE_SUCCESS, DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, DELETE_PROJECT_FAILURE, DELETE_PROJECT_REQUEST, DELETE_PROJECT_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
import { CHANGE_MEMBER_ROLE_FAILURE,
CHANGE_MEMBER_ROLE_REQUEST,
CHANGE_MEMBER_ROLE_SUCCESS,
DELETE_MEMBER_FAILURE,
DELETE_MEMBER_REQUEST,
DELETE_MEMBER_SUCCESS,
DELETE_PROJECT_FAILURE,
DELETE_PROJECT_REQUEST,
DELETE_PROJECT_SUCCESS,
FETCH_ALL_USER_PROJECTS_SUCCESS,
FETCH_PROJECTS_ERROR,
FETCH_PROJECTS_REQUEST,
FETCH_PROJECTS_SUCCESS,
FETCH_PROJECT_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_REQUEST,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_FAILURE
} from "../actionTypes/projectsActionTypes";
const initialState = {
allUserProjectsForModalTask: [],
......@@ -42,6 +59,13 @@ const projectsReducer = (state = initialState, action) => {
return { ...state, loading: true };
case CHANGE_MEMBER_ROLE_FAILURE:
return { ...state, loading: false, error: action.error };
case FETCH_PROJECTS_NON_WATCHER_REQUEST:
return { ...state, loading: true };
case FETCH_PROJECTS_NON_WATCHER_SUCCESS:
const projectsNonWatcher = action.projects.map((project) => {return{value: project.id, text: project.title}})
return { ...state, loading: false, allUserProjectsForModalTask:projectsNonWatcher };
case FETCH_PROJECTS_NON_WATCHER_FAILURE:
return { ...state, loading: false, error: action.error };
default:
return state;
}
......
......@@ -22,7 +22,8 @@ import {
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
ACTIVATE_CREATE_COPY_TASKS_MODE,
DEACTIVATE_CREATE_COPY_TASKS_MODE,
SORT_TASKS
SORT_TASKS,
} from "../actionTypes/tasksTypes";
const initialState = {
......@@ -168,6 +169,7 @@ const tasksReduсer = (state = initialState, action) => {
}
}
return { ...state, loading: false, sortedTasks: filteredTasks };
default:
return state;
}
......
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