Commit f94eb2ec authored by “Yevgeniy's avatar “Yevgeniy

#23 added router on creation project

parent 8ccdf527
......@@ -11,6 +11,15 @@ import {
import {User} from './User';
import {Task} from './Task';
// type IncomingData={
// title: string | null;
// color: string
// admin:User
// workers?: User[]
// tasks?: Task[]
// dateDue?:Date
// department?:boolean
// }
interface IProject{
id: string;
......@@ -26,9 +35,18 @@ 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 })
// @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
@CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() })
......
......@@ -15,8 +15,8 @@ import {
interface ITask{
id: string;
title: string;
// description: string;
createdAt: Date| undefined;
description: string;
createdAt: Date;
// dateTimeStart:Date| null;
// dateTimeDue:Date| null;
assignedTo: User[];
......@@ -31,10 +31,10 @@ import {
id!: string
@Column({ name: 'title', type: 'varchar', length:50,nullable: false })
title!: string
// @Column({ name: 'description', type: 'varchar', length:50,nullable: false })
// description!: string
@Column({ name: 'description', type: 'varchar', length:50,nullable: true })
description!: string
@CreateDateColumn({ name: 'created_at', type: Date, default: new Date() })
createdAt: Date | undefined;
createdAt!: Date;
// @CreateDateColumn({ name: 'dateTimeStart', type: Date,nullable: true })
// dateTimeStart!: Date | null;
// @CreateDateColumn({ name: 'dateTimeDue', type: Date,nullable: true })
......
......@@ -6,12 +6,12 @@ const router:Router = express.Router();
const dataSource = myDataSource;
router.get('/',async (req:Request, res:Response) => {
const projects:Project[]|undefined = await dataSource.manager.find(Project)
router.get('/',async (req:Request, res:Response): Promise<Response>=> {
const projects:Project[] = await dataSource.manager.find(Project)
return res.send({projects})
})
router.get("/:project_id",async (req:Request, res:Response) => {
router.get("/:project_id",async (req:Request, res:Response): Promise<Response> => {
const project : Project|null= await dataSource.manager.findOneBy(Project, {
id: req.params.project_id
})
......@@ -19,4 +19,18 @@ router.get("/:project_id",async (req:Request, res:Response) => {
return res.send({project})
})
router.post('/', async (req:Request, res:Response): Promise<Response> => {
if (!req.body) return res.status(400).send({Message:'problem in incoming req.body'})
const {title, dateDue,department, admin,workers,tasks}= req.body
const project : Project= new Project()
project.title = title;
project.dateDue = dateDue || null;
project.department = department|| null;
project.workers = workers|| null;
project.tasks = tasks || null;
project.admin = admin|| null;
await project.save()
return res.send({project})
})
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