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