Commit f94eb2ec authored by “Yevgeniy's avatar “Yevgeniy

#23 added router on creation project

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