#68 inplement dateTimeTask approach in put request for task edit

parent a1c61e19
...@@ -2,7 +2,7 @@ import { myDataSource } from "./app-data-source"; ...@@ -2,7 +2,7 @@ import { myDataSource } from "./app-data-source";
import { User, UserRole } from "./models/User"; import { User, UserRole } from "./models/User";
import { faker } from '@faker-js/faker'; import { faker } from '@faker-js/faker';
import { Task } from "./models/Task"; import { priorityType, Task, taskFinishType } from "./models/Task";
import { Project } from "./models/Project"; import { Project } from "./models/Project";
import { Member, MemberRole } from "./models/Member"; import { Member, MemberRole } from "./models/Member";
...@@ -45,10 +45,8 @@ const loadFixtures = async () => { ...@@ -45,10 +45,8 @@ const loadFixtures = async () => {
} }
const tasks:Task[] = [] const tasks:Task[] = []
type taskFinishType = "opened" | "done" |"failed";
type priorityType = "A" | "B" |"C";
const priorities:priorityType[] = ["A", "B" , "C"] const priorities:priorityType[] = ["A", "B" , "C"]
const accomplish:taskFinishType[] = ["opened", "done" , "failed"] const accomplish:taskFinishType[] = ["opened","in-progress", "done" , "failed"]
for (let i = 0; i < 20; i++) { for (let i = 0; i < 20; i++) {
if (i <= 15) { if (i <= 15) {
const newTask = new Task(); const newTask = new Task();
......
...@@ -13,8 +13,8 @@ import { ...@@ -13,8 +13,8 @@ import {
import {Project} from './Project'; import {Project} from './Project';
import { DateTimeTask } from './DateTimeTask'; import { DateTimeTask } from './DateTimeTask';
type taskFinishType = "opened" | "done" |"failed"; export type taskFinishType = "opened"| "in-progress" | "done" |"failed";
type priorityType = "A" | "B" |"C"; export type priorityType = "A" | "B" |"C";
interface ITask{ interface ITask{
id: string; id: string;
......
...@@ -184,7 +184,6 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=> ...@@ -184,7 +184,6 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
/**modification of task by task id */ /**modification of task by task id */
router.put('/',async(req:Request, res:Response)=> { router.put('/',async(req:Request, res:Response)=> {
const token = req.get('Authorization'); const token = req.get('Authorization');
const user = await dataSource const user = await dataSource
.createQueryBuilder() .createQueryBuilder()
.select("user") .select("user")
...@@ -192,22 +191,31 @@ router.put('/',async(req:Request, res:Response)=> { ...@@ -192,22 +191,31 @@ 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,dateTimeTaskArray,executor,accomplish,dateTimeDeadLine,priority} = req.body;
const task = await dataSource const task = await dataSource
.createQueryBuilder() .createQueryBuilder()
.select("task") .select("task")
.from(Task, "task") .from(Task, "task")
.where("task.id = :id", { id }) .where("task.id = :id", { id })
.getOne() .getOne()
if (!task) return res.status(404).send({Message:'task not found'}) if (!task) return res.status(404).send({Message:'task 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);
}
}
task.title= title task.title= title
task.description= description task.description= description
task.project= project task.project= project
task.dateTimeDue= dateTimeDue task.dateTimeTasks=dateTimeArray;
task.dateTimeStart= dateTimeStart task.dateTimeDeadLine=dateTimeDeadLine;
task.author=user task.author=user
// task.executors=executors task.executor=executor
task.accomplish= accomplish task.accomplish= accomplish
task.priority= priority task.priority= priority
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