#81 fix update

parent d26f6c4f
...@@ -24,37 +24,39 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise ...@@ -24,37 +24,39 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise
export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next:NextFunction):Promise<void | express.Response<Response>>=>{ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next:NextFunction):Promise<void | express.Response<Response>>=>{
const token = req.get('Authorization'); const token = req.get('Authorization');
const {taskId} = req.body const {taskId} = req.body
console.log('taskId ', taskId)
if(!token) return res.status(401).send({Message:'token not exists'}) if(!token) return res.status(401).send({Message:'token not exists'})
req.body={...req.body,executorStatus:false} req.body={...req.body,executorStatus:false}
req.body={...req.body,authorStatus:false} req.body={...req.body,authorStatus:false}
const executor = await dataSource const task = await dataSource
.createQueryBuilder() .getRepository(Task)
.select("user") .findOne({
.from(User, "user") relations:{
.leftJoinAndSelect("user.tasks", "task") executor:true,
.where("user.token = :token", { token: token }) author:true,
.andWhere("task.id =:taskId", {taskId}) },
.getOne(); where:[
console.log('executor', executor) {
if (executor) { id:taskId,
req.body={...req.body,executorStatus:true} executor:{
token:token
} }
const author = await dataSource },
.createQueryBuilder() {
.select("user") id:taskId,
.from(User, "user") author:{
.leftJoinAndSelect("user.createdTasks", "task") token:token
.where("user.token = :token", { token: token }) }
.andWhere("task.id =:taskId", {taskId}) },
.getOne(); ]})
console.log('author', author) if (!task) return res.status(404).send({message:'task with possible user involved is not found'})
if (author) { if (task?.author?.token === token ) {
req.body={...req.body,authorStatus:true} req.body={...req.body,authorStatus:true}
} else if(task?.executor?.token === token) {
req.body={...req.body,executorStatus:true}
} else {
} }
if(!author && !executor)return res.status(401).send({Message:'user is not authorized'})
next() next()
}; };
......
...@@ -7,7 +7,8 @@ import { ...@@ -7,7 +7,8 @@ import {
ManyToOne, ManyToOne,
OneToOne, OneToOne,
JoinTable, JoinTable,
OneToMany OneToMany,
JoinColumn
} from 'typeorm'; } from 'typeorm';
import {User} from './User'; import {User} from './User';
import {Project} from './Project'; import {Project} from './Project';
...@@ -28,9 +29,9 @@ import { DateTimeTask } from './DateTimeTask'; ...@@ -28,9 +29,9 @@ import { DateTimeTask } from './DateTimeTask';
priority: priorityType | null; priority: priorityType | null;
archive:boolean, archive:boolean,
author: User; author: User;
executor:User;
project:Project|null; project:Project|null;
dateTimeTasks:DateTimeTask[]|null; dateTimeTasks:DateTimeTask[]|null;
executor:User;
} }
@Entity({ name: 'Task' }) @Entity({ name: 'Task' })
...@@ -73,8 +74,7 @@ import { DateTimeTask } from './DateTimeTask'; ...@@ -73,8 +74,7 @@ import { DateTimeTask } from './DateTimeTask';
@ManyToOne(() => User, (user: { tasks: Task[]; }) => user.tasks,{eager : true}) @ManyToOne(() => User, (user: { tasks: Task[]; }) => user.tasks,{eager : true})
author!: User; author!: User;
@ManyToOne(() =>User, (user: { tasks: Task[]}) => user.tasks,{eager : true,nullable: true, onUpdate:'CASCADE'}) @ManyToOne(() =>User, (user: { tasks: Task[]}) => user.tasks,{nullable: true,cascade: true, onUpdate:'CASCADE', eager : true,})
@JoinTable()
executor!: User; executor!: User;
@ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true,onUpdate:'CASCADE'}) @ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true,onUpdate:'CASCADE'})
......
...@@ -168,6 +168,12 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> { ...@@ -168,6 +168,12 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
dateTimeTask = dateTimeTaskData dateTimeTask = dateTimeTaskData
} }
if (dateTimeTask!==null) {
dateTimeTask.dateTimeStart = dateTimeStart
dateTimeTask.dateTimeDue = dateTimeDue
await dateTimeTask.save()
}
if (authorStatus){ if (authorStatus){
task.title = title task.title = title
task.description= description task.description= description
...@@ -177,13 +183,9 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> { ...@@ -177,13 +183,9 @@ router.put('/',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
task.executor=executor task.executor=executor
task.priority= priority task.priority= priority
} }
if(executorStatus && dateTimeTask!==null){ if(executorStatus){
dateTimeTask.dateTimeStart = dateTimeStart
dateTimeTask.dateTimeDue = dateTimeDue
await dateTimeTask.save()
task.note = note task.note = note
task.dateTimeFactDeadLine= dateTimeFactDeadLine task.dateTimeFactDeadLine= dateTimeFactDeadLine
} }
task.accomplish= accomplish task.accomplish= accomplish
await task.save() await task.save()
......
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