#68 added model DateTimeTask

parent fb898090
import {
Column,
Entity,
PrimaryGeneratedColumn,
CreateDateColumn,
BaseEntity,
ManyToOne,
} from 'typeorm';
import {Task} from './Task';
interface IDateTimeTask{
id: string;
createdAt: Date;
dateTimeStart: Date;
dateTimeDue: Date;
task: Task;
}
@Entity({name:"DateTimeTask"})
export class DateTimeTask extends BaseEntity implements IDateTimeTask{
@PrimaryGeneratedColumn("uuid")
id!: string;
@CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() })
createdAt!: Date;
@CreateDateColumn({ name: 'createdAt', type: Date, nullable:false })
dateTimeStart!: Date;
@CreateDateColumn({ name: 'createdAt', type: Date, nullable:false })
dateTimeDue!: Date;
@ManyToOne(() => Task, (task: { dateTimeTasks: DateTimeTask[]; }) => task.dateTimeTasks,{cascade: true, onUpdate:'CASCADE',nullable:true})
task!: Task;
}
\ No newline at end of file
...@@ -5,9 +5,7 @@ import { ...@@ -5,9 +5,7 @@ import {
CreateDateColumn, CreateDateColumn,
BaseEntity, BaseEntity,
ManyToOne, ManyToOne,
ManyToMany,
OneToMany,
JoinTable
} from 'typeorm'; } from 'typeorm';
import {User} from './User'; import {User} from './User';
import {Project} from './Project'; import {Project} from './Project';
......
...@@ -6,10 +6,12 @@ import { ...@@ -6,10 +6,12 @@ import {
BaseEntity, BaseEntity,
ManyToOne, ManyToOne,
OneToOne, OneToOne,
JoinTable JoinTable,
OneToMany
} from 'typeorm'; } from 'typeorm';
import {User} from './User'; import {User} from './User';
import {Project} from './Project'; import {Project} from './Project';
import { DateTimeTask } from './DateTimeTask';
type taskFinishType = "opened" | "done" |"failed"; type taskFinishType = "opened" | "done" |"failed";
type priorityType = "A" | "B" |"C"; type priorityType = "A" | "B" |"C";
...@@ -27,6 +29,7 @@ import { ...@@ -27,6 +29,7 @@ import {
priority: priorityType | null; priority: priorityType | null;
author: User; author: User;
project:Project|null; project:Project|null;
dateTimeTasks:DateTimeTask[]|null;
executor:User; executor:User;
} }
...@@ -76,4 +79,7 @@ import { ...@@ -76,4 +79,7 @@ import {
@ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true,onUpdate:'CASCADE'}) @ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks,{eager : true,nullable: true,onUpdate:'CASCADE'})
project!: Project; project!: Project;
@OneToMany(() => DateTimeTask, (dateTimeTask: { task: Task }) => dateTimeTask.task)
dateTimeTasks!: DateTimeTask[];
} }
...@@ -37,7 +37,7 @@ interface IUser { ...@@ -37,7 +37,7 @@ interface IUser {
createdTasks:Task[]; createdTasks:Task[];
// workerInProjects:Project[]; // workerInProjects:Project[];
// adminInProjects:Project[]; // adminInProjects:Project[];
membership: Member[]; members: Member[];
} }
...@@ -88,7 +88,7 @@ export class User extends BaseEntity implements IUser { ...@@ -88,7 +88,7 @@ export class User extends BaseEntity implements IUser {
@OneToMany(() => Member, (member: { user: User }) => member.user) @OneToMany(() => Member, (member: { user: User }) => member.user)
membership!: Member[]; members!: Member[];
// @ManyToMany(() => Project,(project: { user: User }) => project.user) // @ManyToMany(() => Project,(project: { user: User }) => project.user)
// @JoinTable() // @JoinTable()
......
import express,{Router, Request, Response} from 'express';
import {myDataSource} from '../app-data-source';
import { Member } from "../models/Member";
const router:Router = express.Router();
const dataSource = myDataSource;
...@@ -166,7 +166,7 @@ router.post('/remove-user', async (req: Request, res: Response):Promise<Response ...@@ -166,7 +166,7 @@ router.post('/remove-user', async (req: Request, res: Response):Promise<Response
.createQueryBuilder() .createQueryBuilder()
.select("user") .select("user")
.from(User, "user") .from(User, "user")
.leftJoinAndSelect("user.membership","member") .leftJoinAndSelect("user.members","member")
.leftJoinAndSelect('member.project', 'project' ) .leftJoinAndSelect('member.project', 'project' )
.where("user.token = :token", { token }) .where("user.token = :token", { token })
.andWhere('project.id=:projectId',{projectId}) .andWhere('project.id=:projectId',{projectId})
......
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