#45 fix of projects fixtures and task model

parent 50266906
......@@ -39,16 +39,7 @@ const loadFixtures = async () => {
await user.save();
users.push(user)
}
const projects:Project[] = []
for (let i = 0; i < 5; i++) {
const newProject = new Project();
newProject.title = `Project ${faker.random.words(1)}`;
newProject.color = faker.random.words(4);
newProject.admin = faker.helpers.arrayElement(users);
newProject.workers = faker.helpers.arrayElements(users, randomIntFromInterval(1, 3));
await newProject.save();
projects.push(newProject)
}
const tasks:Task[] = []
type taskFinishType = "opened" | "done" |"failed";
type priorityType = "A" | "B" |"C";
......@@ -63,7 +54,6 @@ const loadFixtures = async () => {
newTask.dateTimeDue = faker.date.soon(randomIntFromInterval(1, 15));
newTask.dateTimeStart = faker.date.recent((randomIntFromInterval(0, 8)));
newTask.author = faker.helpers.arrayElement(users);
newTask.project = faker.helpers.arrayElement(projects);
newTask.accomplish = faker.helpers.arrayElement(accomplish);
newTask.priority = faker.helpers.arrayElement(priorities);
await newTask.save();
......@@ -75,7 +65,6 @@ const loadFixtures = async () => {
newTask.executors = faker.helpers.arrayElements(users, randomIntFromInterval(0, 3));
newTask.dateTimeDue = null;
newTask.dateTimeStart = null;
newTask.project = faker.helpers.arrayElement(projects);
newTask.author = faker.helpers.arrayElement(users);
newTask.accomplish = accomplish[0];
newTask.priority = faker.helpers.arrayElement(priorities);
......@@ -83,6 +72,22 @@ const loadFixtures = async () => {
tasks.push(newTask)
}
}
const projects:Project[] = []
for (let i = 0; i < 5; i++) {
const newProject = new Project();
newProject.title = `Project ${faker.random.words(1)}`;
newProject.color = faker.random.words(1);
newProject.admin = faker.helpers.arrayElement(users);
newProject.tasks= faker.helpers.arrayElements(tasks, randomIntFromInterval(1, 3));
newProject.workers = faker.helpers.arrayElements(users, randomIntFromInterval(1, 3));
await newProject.save();
projects.push(newProject)
}
console.log('========================== ' + '\n' + 'Fixtures done!' +'\n' + '==========================')
})
......
......@@ -28,17 +28,10 @@ import {
@Entity({ name: 'Project' })
export class Project extends BaseEntity implements IProject{
// data: IncomingData;
// constructor(data:IncomingData){
// super();
// this.data = data
// }
@PrimaryGeneratedColumn('uuid')
id!: string
// @Column({ name: 'title', type: 'varchar', length:100,nullable: false, default: this.data.title })
// title!: string
@Column({ name: 'title', type: 'varchar', length:100,nullable: false})
title!: string
......
......@@ -68,6 +68,6 @@ import {
@JoinTable()
executors!: User[];
@ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true})
project!: Project | null;
@ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true,onUpdate:'CASCADE'})
project!: Project;
}
......@@ -12,7 +12,6 @@ router.get('/', async(req:Request, res:Response):Promise<Response> => {
.find()
return res.send({tasks})
})
export default router;
router.post('/', async(req:Request, res:Response):Promise<Response>=>{
const token = req.get('Authorization');
......@@ -108,3 +107,6 @@ router.put('/',async(req:Request, res:Response)=> {
await task.save()
res.send({message:'update task successfully'})
})
export default router;
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