#68 change create task router & added onDelete and eager options in DateTimeTask…

#68 change create task router & added onDelete and eager options in DateTimeTask ans Task models respectfully
parent b2296f46
......@@ -36,6 +36,6 @@ import {
dateTimeDue!: Date;
@ManyToOne(() => Task, (task: { dateTimeTasks: DateTimeTask[]; }) => task.dateTimeTasks,{cascade: true, onUpdate:'CASCADE',nullable:true})
@ManyToOne(() => Task, (task: { dateTimeTasks: DateTimeTask[]; }) => task.dateTimeTasks,{cascade: true, onUpdate:'CASCADE',onDelete:'CASCADE',nullable:true})
task!: Task;
}
\ No newline at end of file
......@@ -80,6 +80,6 @@ import { DateTimeTask } from './DateTimeTask';
@ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true,onUpdate:'CASCADE'})
project!: Project;
@OneToMany(() => DateTimeTask, (dateTimeTask: { task: Task }) => dateTimeTask.task)
@OneToMany(() => DateTimeTask, (dateTimeTask: { task: Task }) => dateTimeTask.task,{eager : true,nullable: true,onUpdate:'CASCADE'})
dateTimeTasks!: DateTimeTask[];
}
......@@ -4,6 +4,7 @@ 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';
const router:Router = express.Router();
const dataSource = myDataSource;
......@@ -23,24 +24,34 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
router.post('/', async(req:Request, res:Response):Promise<Response>=>{
const token = req.get('Authorization');
const newTask = new Task();
const {title,description,project,dateTimeDue,dateTimeStart,accomplish,priority} = req.body;
const {title,description,project,dateTimeTaskArray, dateTimeDeadLine,accomplish,priority} = req.body;
const user = await dataSource
.createQueryBuilder()
.select("user")
.from(User, "user")
.where("user.token = :token", { token: token })
.getOne()
.getOne();
if (!user) return res.status(404).send({Message:'user not found'})
const dateTimeArray=[];
if(dateTimeTaskArray && dateTimeTaskArray.length>0){
for (let dateTimeStartDue of dateTimeTaskArray){
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = dateTimeStartDue.dateTimeStart;
newDateTimeTask.dateTimeDue = dateTimeStartDue.dateTimeDue;
await newDateTimeTask.save();
dateTimeArray.push(newDateTimeTask);
}
}
newTask.title = title;
newTask.description = description;
newTask.project = project;
newTask.dateTimeDue = dateTimeDue;
newTask.dateTimeStart = dateTimeStart;
newTask.dateTimeTasks=dateTimeArray;
newTask.dateTimeDeadLine=dateTimeDeadLine;
newTask.author= user;
newTask.accomplish = accomplish;
newTask.priority = priority;
await newTask.save();
return res.send({newTask})
return res.send({newTask});
})
/**check tasks of specific user by userID */
......
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