Merge branch 'task-36-fix/fix_back_put_task' into 'development'

Task 36 fix/fix back put task

See merge request !24
parents 354ab632 ec3efe63
......@@ -68,7 +68,7 @@ import {
@OneToMany(() => Task, (task: { project: Project; })=>task.project,{eager : true})
tasks!:Task[]|null;
@ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
@ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true,cascade: true, onUpdate:'CASCADE',onDelete: 'CASCADE'})
@JoinTable()
workers!: User[];
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ import {
priority: priorityType | null;
author: User;
project:Project|null;
executors:User[]
executors:User[];
}
@Entity({ name: 'Task' })
......@@ -64,13 +64,10 @@ import {
@ManyToOne(() => User, (user: { tasks: Task[]; }) => user.tasks,{eager : true})
author!: User;
@ManyToMany(() => User,{eager : true})
@ManyToMany(() => User,{eager : true, cascade: true, onUpdate:'CASCADE',onDelete: 'CASCADE'})
@JoinTable()
executors!: User[];
@ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks)
project!: Project | null;
}
......@@ -68,14 +68,6 @@ router.get('/my', async (req: Request, res: Response):Promise<Response>=>{
})
router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>{
// const token = req.get('Authorization');
// const user = await dataSource
// .createQueryBuilder()
// .select("user")
// .from(User, "user")
// .where("user.token = :token", { token: token })
// .getOne()
// if(!user) return res.status(404).send({Message:'user not found'})
const taskId = req.params.taskId;
await myDataSource
.createQueryBuilder()
......@@ -96,24 +88,23 @@ router.put('/',async(req:Request, res:Response)=> {
.where("user.token = :token", { token: token })
.getOne()
if (!user) return res.status(404).send({Message:'user not found'})
const {id,title,description,project,dateTimeDue,dateTimeStart,accomplish,priority} = req.body;
await dataSource
const {id,title,description,project,dateTimeDue,dateTimeStart,executors,accomplish,priority} = req.body;
const task = await dataSource
.createQueryBuilder()
.update(Task)
.set({
title: title,
description: description,
project: project,
dateTimeDue: dateTimeDue,
dateTimeStart: dateTimeStart,
author:user,
accomplish: accomplish,
priority: priority
})
.where("id = :id", { id: id })
.execute()
.select("task")
.from(Task, "task")
.where("task.id = :id", { id })
.getOne()
if (!task) return res.status(404).send({Message:'task not found'})
task.title= title
task.description= description
task.project= project
task.dateTimeDue= dateTimeDue
task.dateTimeStart= dateTimeStart
task.author=user
task.executors=executors
task.accomplish= accomplish
task.priority= priority
await task.save()
res.send({message:'update task successfully'})
// res.send({task})
})
......@@ -60,7 +60,6 @@ router.post('/', upload.single("avatar"), async (req : Request, res : Response):
router.post('/sessions/', async (req : Request, res : Response):Promise<object> => {
const {email, password} = req.body;
console.log("email" + email, "password" + password )
const user = await dataSource
.createQueryBuilder()
.select("user")
......@@ -70,7 +69,6 @@ router.post('/sessions/', async (req : Request, res : Response):Promise<object>
.getOne()
if(!user) return res.status(404).send({Message:'user not found'})
const isMatch:boolean = await user.checkPassword(password);
console.log("123")
if (!isMatch) return res.status(400).send({
error: "Wrong Password"
})
......
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