#45 fix of projects fixtures and task model

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