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
.findOne({
relations:{
executor:true,
author:true,
author:true,
dateTimeTasks: true,
},
where:[
{
......@@ -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'})
req.body={...req.body, task:task}
if(task?.executor?.token === token) {
req.body={...req.body,executorStatus:true}
}
......@@ -83,23 +85,30 @@ export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Respon
} else if (req.params?.dateTimeTaskId){
dateTimeTaskId = req.params.dateTimeTaskId
} else return res.send({vessage:"there are no dateTimeTaskId found"})
const task = await dataSource
.createQueryBuilder()
.select(["task"])
.from(Task,"task")
.leftJoinAndSelect("task.executor","user")
.leftJoinAndSelect("task.dateTimeTasks","dateTimeTask")
.leftJoinAndSelect("task.author","users")
.where("dateTimeTask.id = :dateTimeTaskId", {dateTimeTaskId})
.getOne()
const task =await dataSource
.getRepository(Task)
.findOne({
relations:
{
dateTimeTasks: true,
executor:true,
author:true,
},
where:{
dateTimeTasks:
{
id:dateTimeTaskId
}
}})
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) {
req.body={...req.body,executorStatus:true}
}
if (task?.author?.token === token ) {
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()
}
......@@ -146,6 +155,25 @@ export const taskFinderById = async (taskId:string):Promise<null | 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 */
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({
service:'Yandex',
// host: "smtp.yandex.ru",
......@@ -182,7 +208,8 @@ export let transporter = nodemailer.createTransport({
pass: "newPlannerProject123" // generated ethereal password
}
})
export const FRONTEND_URL = 'localhost:3000'
\ No newline at end of file
export const FRONTEND_URL = 'localhost:3000';
import express,{Router, Request, Response,NextFunction } from 'express';
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 } from '../models/Member';
import { In } from 'typeorm';
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 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 */
router.post("/make-copy", async(req:Request, res:Response):Promise<Response>=>{
const {taskId, dateTimeDue, dateTimeStart} = req.body
router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Response):Promise<Response>=>{
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()
const task = taskFinderById(taskId)
newDateTimeTask.dateTimeStart = dateTimeStart;
newDateTimeTask.dateTimeDue = dateTimeDue;
newDateTimeTask.task = taskId;
await newDateTimeTask.save();
return res.send({task})
} )
......@@ -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 */
router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
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
.createQueryBuilder()
.select('dateTimeTask')
......@@ -51,11 +33,40 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
.where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId})
.getOne()
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.dateTimeDue=dateTimeDue
await dateTimeTask.save()
const task = await taskFinderById(taskId)
if (!task) return res.status(404).send({Message:'task not found'})
task.title = title;
task.description = description;
task.priority = priority;
......@@ -65,17 +76,44 @@ router.put("/change-copy/:dateTimeTaskId", authAuthorOrExecutorOfTask, async(req
/**delete copyTask by dateTimeTaskId */
router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:Request, res:Response):Promise<Response|void>=>{
const {executorStatus} = req.body
if(executorStatus){
const {authorStatus, executorStatus, task} = req.body
const {dateTimeTaskId} = req.params
await myDataSource
.createQueryBuilder()
.delete()
.from(DateTimeTask)
.where("id = :dateTimeTaskId", { dateTimeTaskId })
.execute()
return res.send({message:"copyTask delete succesfully"})
if (!task) return res.status(404).send({message:'task with possible copytask involved is not found'})
let dateTimeTasks = task?.dateTimeTasks
if (authorStatus || executorStatus) {
if (dateTimeTasks.length>1) {
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})=> {
const usersAllFields = useSelector(state => state.users.usersAllFields)
const navigate= useNavigate();
const submitFormHandler=(e, currentUser)=>{
dispatch(logoutUser(navigate))
e.preventDefault();
dispatch(logoutUser(navigate))
e.preventDefault();
e.preventDefault();
dispatch(loginUser({
"email": currentUser.email,
"password": "123"
......
......@@ -14,15 +14,15 @@ const usersReducer = (state = initialState, action) => {
case REGISTER_USER_REQUEST:
return {...state, loading: true};
case REGISTER_USER_SUCCESS:
console.log("register.user " + action)
console.log("register.user " , action)
return {...state, loading: false};
case REGISTER_USER_FAILURE:
return {...state, loading: false, registerError: action.error};
case LOGIN_USER_SUCCESS:
console.log("action.user " + action)
console.log("action.user " , action)
return {...state, user: action.user};
case LOGIN_USER_FAILURE:
console.log("action.error" + action.error)
console.log("action.error" , action.error)
return {...state, loginError: action.error};
case LOGOUT_USER_SUCCESS:
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