Commit 4a49a5f9 authored by “Yevgeniy's avatar “Yevgeniy

ticket#23 added simple router to task and added project model to app-data-source and server fix

parent f94eb2ec
import { DataSource } from "typeorm"; import { DataSource } from "typeorm";
import {User} from './models/User'; import {User} from './models/User';
import {Task} from './models/Task'; import {Task} from './models/Task';
import { Project } from "./models/Project";
export const myDataSource = new DataSource({ export const myDataSource = new DataSource({
type: "postgres", type: "postgres",
...@@ -9,7 +10,7 @@ export const myDataSource = new DataSource({ ...@@ -9,7 +10,7 @@ export const myDataSource = new DataSource({
username: "pluser", username: "pluser",
password: "pluser", password: "pluser",
database: "planner", database: "planner",
entities: [User,Task], entities: [User,Task,Project],
logging: true, logging: true,
synchronize: true, // in build switch to false synchronize: true, // in build switch to false
migrationsRun: false migrationsRun: false
......
...@@ -53,6 +53,6 @@ import { ...@@ -53,6 +53,6 @@ import {
@ManyToMany(() => User, (user: { tasks: Task[]; }) => user.tasks) @ManyToMany(() => User, (user: { tasks: Task[]; }) => user.tasks)
assignedTo!: User[]; assignedTo!: User[];
@ManyToOne(()=>Project,(task: {project:Project}) => task.project) @ManyToOne(()=>Project,(project:{tasks: Task[]}) => project.tasks)
project!: Project | null; project!: Project | null;
} }
import express,{Router, Request, Response} from 'express';
// import {User} from '../models/User';
// import {Project} from '../models/Project';
import {Task} from '../models/Task';
import {myDataSource} from '../app-data-source';
// import { nanoid } from 'nanoid';
const router:Router = express.Router();
const dataSource = myDataSource;
router.get('/', async(req:Request, res:Response):Promise<Response> => {
const tasks = await dataSource.manager.find(Task)
return res.send({tasks})
})
export default router;
import express, { Express } from 'express'; import express, { Express } from 'express';
import cors from 'cors'; import cors from 'cors';
import users from './routers/users'; import users from './routers/users';
import tasks from './routers/tasks';
import projects from './routers/projects';
import {myDataSource} from './app-data-source'; import {myDataSource} from './app-data-source';
...@@ -19,6 +21,8 @@ app.use(cors()) ...@@ -19,6 +21,8 @@ app.use(cors())
app.use(express.json()); app.use(express.json());
const PORT = 8000; const PORT = 8000;
app.use('/users',users) app.use('/users',users)
app.use('/tasks',tasks)
app.use('/projects',projects)
const run = async() => { const run = async() => {
......
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