#68 inplement dateTimeTask approach in put request for task edit

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