Commit a43800ac authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'development' of…

Merge branch 'development' of ssh://git.attractor-school.com:30022/apollo64/crm-team-one into task-100-feature/create_logic_for_tasks
parents ef153cfe 6b73c9c8
...@@ -44,7 +44,8 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next ...@@ -44,7 +44,8 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
.findOne({ .findOne({
relations:{ relations:{
executor:true, executor:true,
author:true, author:true,
dateTimeTasks: true,
}, },
where:[ where:[
{ {
...@@ -61,6 +62,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next ...@@ -61,6 +62,7 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
}, },
]}) ]})
if (!task) return res.status(404).send({message:'task with possible user involved is not found'}) if (!task) return res.status(404).send({message:'task with possible user involved is not found'})
req.body={...req.body, task:task}
if(task?.executor?.token === token) { if(task?.executor?.token === token) {
req.body={...req.body,executorStatus:true} req.body={...req.body,executorStatus:true}
} }
...@@ -83,23 +85,30 @@ export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Respon ...@@ -83,23 +85,30 @@ export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Respon
} else if (req.params?.dateTimeTaskId){ } else if (req.params?.dateTimeTaskId){
dateTimeTaskId = req.params.dateTimeTaskId dateTimeTaskId = req.params.dateTimeTaskId
} else return res.send({vessage:"there are no dateTimeTaskId found"}) } else return res.send({vessage:"there are no dateTimeTaskId found"})
const task = await dataSource const task =await dataSource
.createQueryBuilder() .getRepository(Task)
.select(["task"]) .findOne({
.from(Task,"task") relations:
.leftJoinAndSelect("task.executor","user") {
.leftJoinAndSelect("task.dateTimeTasks","dateTimeTask") dateTimeTasks: true,
.leftJoinAndSelect("task.author","users") executor:true,
.where("dateTimeTask.id = :dateTimeTaskId", {dateTimeTaskId}) author:true,
.getOne() },
where:{
dateTimeTasks:
{
id:dateTimeTaskId
}
}})
if (!task) return res.status(404).send({message:'task with possible user involved is not found'}) if (!task) return res.status(404).send({message:'task with possible user involved is not found'})
req.body={...req.body, task:task}
if(task?.executor?.token === token) { if(task?.executor?.token === token) {
req.body={...req.body,executorStatus:true} req.body={...req.body,executorStatus:true}
} }
if (task?.author?.token === token ) { if (task?.author?.token === token ) {
req.body={...req.body,authorStatus:true} req.body={...req.body,authorStatus:true}
} }
if (req.body.authorStatus ===false && req.body.executorStatus===false) return res.status(403).send({Message:'user is not uathorized'})
next() next()
} }
...@@ -146,6 +155,25 @@ export const taskFinderById = async (taskId:string):Promise<null | Task>=>{ ...@@ -146,6 +155,25 @@ export const taskFinderById = async (taskId:string):Promise<null | Task>=>{
return task return task
} }
/** find task by dateTimeTaskId */
export const taskFinderByDateTimeTaskId = async (dateTimeTaskId:string):Promise<null | Task>=>{
const task =await dataSource
.getRepository(Task)
.findOne({
relations:
{
dateTimeTasks: true
},
where:{
dateTimeTasks:
{
id:dateTimeTaskId
}
}})
return task
}
/**member finder by userId and projectId, return one task */ /**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)=>{
...@@ -170,8 +198,6 @@ export const memberFinderById = async (userId:string, projectId:string)=>{ ...@@ -170,8 +198,6 @@ export const memberFinderById = async (userId:string, projectId:string)=>{
} }
export let transporter = nodemailer.createTransport({ export let transporter = nodemailer.createTransport({
service:'Yandex', service:'Yandex',
// host: "smtp.yandex.ru", // host: "smtp.yandex.ru",
...@@ -182,7 +208,8 @@ export let transporter = nodemailer.createTransport({ ...@@ -182,7 +208,8 @@ export let transporter = nodemailer.createTransport({
pass: "newPlannerProject123" // generated ethereal password pass: "newPlannerProject123" // generated ethereal password
} }
}) })
export const FRONTEND_URL = 'localhost:3000' export const FRONTEND_URL = 'localhost:3000';
\ No newline at end of file
import express,{Router, Request, Response,NextFunction } from 'express'; import express,{Router, Request, Response } from 'express';
import {Task} from '../models/Task'; import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source'; import {myDataSource} from '../app-data-source';
import { User } from '../models/User';
import { Member } from '../models/Member';
import { In } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask'; import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfDateTimeTask, authAuthorOrExecutorOfTask } from '../helpers'; import { auth, authAuthorOrExecutorOfDateTimeTask, authAuthorOrExecutorOfTask,taskFinderById } from '../helpers';
import { info } from 'console';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
/**task finder by id, return one task */
const taskFinderById = async (taskId:string):Promise<null | Task>=>{
const task = await dataSource
.getRepository(Task)
.findOne({
relations:{
executor:true,
author:true,
dateTimeTasks:true
},
where:{
id:taskId
}
})
return task
}
/** make copy of task in calendar view */ /** make copy of task in calendar view */
router.post("/make-copy", async(req:Request, res:Response):Promise<Response>=>{ router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Response):Promise<Response>=>{
const {taskId, dateTimeDue, dateTimeStart} = 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(); const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStart newDateTimeTask.dateTimeStart = dateTimeStart;
newDateTimeTask.dateTimeDue = dateTimeDue newDateTimeTask.dateTimeDue = dateTimeDue;
newDateTimeTask.task = taskId newDateTimeTask.task = taskId;
await newDateTimeTask.save() await newDateTimeTask.save();
const task = taskFinderById(taskId)
return res.send({task}) return res.send({task})
} ) } )
...@@ -43,7 +25,7 @@ router.post("/make-copy", async(req:Request, res:Response):Promise<Response>=>{ ...@@ -43,7 +25,7 @@ router.post("/make-copy", async(req:Request, res:Response):Promise<Response>=>{
/** change date time of copy of task in calendar view */ /** change date time of copy of task in calendar view */
router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
const {dateTimeTaskId} = req.params const {dateTimeTaskId} = req.params
const {executorStatus, taskId, dateTimeStart, dateTimeDue, description, title, priority} = req.body const {executorStatus,authorStatus, task, dateTimeStart, dateTimeDue, description, title, priority} = req.body
const dateTimeTask = await dataSource const dateTimeTask = await dataSource
.createQueryBuilder() .createQueryBuilder()
.select('dateTimeTask') .select('dateTimeTask')
...@@ -51,11 +33,40 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req ...@@ -51,11 +33,40 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
.where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId}) .where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId})
.getOne() .getOne()
if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"}) if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"})
let allDateTimeTasks = task.dateTimeTasks
if (allDateTimeTasks.length===1) {
if(executorStatus && !authorStatus) {
if(task.dateTimeDeadLine>dateTimeStart &&
task.dateTimeDeadLine>dateTimeDue)
{
dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue
await dateTimeTask.save()
return res.send({message:"copyTask changed succesfully"})
}
}else if(authorStatus){
dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue
await dateTimeTask.save()
return res.send({message:"copyTask changed succesfully"})
}
} else if (allDateTimeTasks.length>1) {
let dateTimeTasks = task.dateTimeTasks
dateTimeTasks.sort(function(a:DateTimeTask, b:DateTimeTask) {
return (a.dateTimeDue > b.dateTimeDue) ? -1 : ((a.dateTimeDue < b.dateTimeDue) ? 1 : 0);
});
let latestDueDateCopyTask = dateTimeTasks[0]
if (latestDueDateCopyTask.id ===dateTimeTaskId)
if (authorStatus) {
dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue
await dateTimeTask.save()
return res.send({message:"copyTask changed succesfully"})
}
}
dateTimeTask.dateTimeStart=dateTimeStart dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue dateTimeTask.dateTimeDue=dateTimeDue
await dateTimeTask.save() await dateTimeTask.save()
const task = await taskFinderById(taskId)
if (!task) return res.status(404).send({Message:'task not found'})
task.title = title; task.title = title;
task.description = description; task.description = description;
task.priority = priority; task.priority = priority;
...@@ -65,17 +76,44 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req ...@@ -65,17 +76,44 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
/**delete copyTask by dateTimeTaskId */ /**delete copyTask by dateTimeTaskId */
router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:Request, res:Response):Promise<Response|void>=>{ router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:Request, res:Response):Promise<Response|void>=>{
const {executorStatus} = req.body const {authorStatus, executorStatus, task} = req.body
if(executorStatus){
const {dateTimeTaskId} = req.params const {dateTimeTaskId} = req.params
await myDataSource
.createQueryBuilder() if (!task) return res.status(404).send({message:'task with possible copytask involved is not found'})
.delete() let dateTimeTasks = task?.dateTimeTasks
.from(DateTimeTask) if (authorStatus || executorStatus) {
.where("id = :dateTimeTaskId", { dateTimeTaskId })
.execute() if (dateTimeTasks.length>1) {
return res.send({message:"copyTask delete succesfully"}) dateTimeTasks.sort(function(a:DateTimeTask, b:DateTimeTask) {
return (a.dateTimeDue > b.dateTimeDue) ? -1 : ((a.dateTimeDue < b.dateTimeDue) ? 1 : 0);
});
const latestDueDateCopyTask = dateTimeTasks[0]
await myDataSource
.createQueryBuilder()
.delete()
.from(DateTimeTask)
.where("id = :dateTimeTaskId", { dateTimeTaskId })
.execute()
if (latestDueDateCopyTask.id === dateTimeTaskId) {
task.dateTimeDeadLine= dateTimeTasks[1].dateTimeDue
await task.save()
} else {
task.dateTimeDeadLine= dateTimeTasks[0].dateTimeDue
}
return res.send({message:"copyTask delete succesfully"})
}
} }
if (dateTimeTasks.length ===1 ) {
if ( authorStatus) {
Task.remove(task)
return res.send({message:"task delete succesfully"})
} else{
return res.send({message:"not uathorized to delete task"})
}
}
} }
) )
......
...@@ -24,8 +24,9 @@ const SwitchUserModal= ({open, handleClose})=> { ...@@ -24,8 +24,9 @@ const SwitchUserModal= ({open, handleClose})=> {
const usersAllFields = useSelector(state => state.users.usersAllFields) const usersAllFields = useSelector(state => state.users.usersAllFields)
const navigate= useNavigate(); const navigate= useNavigate();
const submitFormHandler=(e, currentUser)=>{ const submitFormHandler=(e, currentUser)=>{
dispatch(logoutUser(navigate)) dispatch(logoutUser(navigate))
e.preventDefault(); e.preventDefault();
e.preventDefault();
dispatch(loginUser({ dispatch(loginUser({
"email": currentUser.email, "email": currentUser.email,
"password": "123" "password": "123"
......
...@@ -14,15 +14,15 @@ const usersReducer = (state = initialState, action) => { ...@@ -14,15 +14,15 @@ const usersReducer = (state = initialState, action) => {
case REGISTER_USER_REQUEST: case REGISTER_USER_REQUEST:
return {...state, loading: true}; return {...state, loading: true};
case REGISTER_USER_SUCCESS: case REGISTER_USER_SUCCESS:
console.log("register.user " + action) console.log("register.user " , action)
return {...state, loading: false}; return {...state, loading: false};
case REGISTER_USER_FAILURE: case REGISTER_USER_FAILURE:
return {...state, loading: false, registerError: action.error}; return {...state, loading: false, registerError: action.error};
case LOGIN_USER_SUCCESS: case LOGIN_USER_SUCCESS:
console.log("action.user " + action) console.log("action.user " , action)
return {...state, user: action.user}; return {...state, user: action.user};
case LOGIN_USER_FAILURE: case LOGIN_USER_FAILURE:
console.log("action.error" + action.error) console.log("action.error" , action.error)
return {...state, loginError: action.error}; return {...state, loginError: action.error};
case LOGOUT_USER_SUCCESS: case LOGOUT_USER_SUCCESS:
return {...state, user: null}; return {...state, user: null};
......
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