Commit 631cd4b3 authored by Zhanara's avatar Zhanara

добавила контроллеры в app

parent da51e85b
...@@ -36,7 +36,7 @@ export class CommentController { ...@@ -36,7 +36,7 @@ export class CommentController {
} }
private deleteCommentById = async (req: Request, res: Response): Promise<void> => { private deleteCommentById = async (req: Request, res: Response): Promise<void> => {
const user = req.user as IUser; const user = req.body._id;
const id = req.params.id; const id = req.params.id;
const response = await this.service.deleteCommentById(user,id) const response = await this.service.deleteCommentById(user,id)
res.send(response) res.send(response)
......
import express, {Express, json, urlencoded} from 'express'; import express, {Express, json, urlencoded} from 'express';
import 'dotenv/config'; import 'dotenv/config';
import cors from 'cors'; import cors from 'cors';
import {mongoose} from './repository/mongoose'; import {mongo} from './repository/mongoose';
import {UsersRouter} from './routes/user'; import {UsersRouter} from './routes/user';
import { CommentController } from './controllers/comments';
import { PostsController } from './controllers/posts';
mongoose.run(); mongo.run();
const app: Express = express(); const app: Express = express();
app.use(json()); app.use(json());
...@@ -13,6 +15,9 @@ app.use(urlencoded({extended: true})); ...@@ -13,6 +15,9 @@ app.use(urlencoded({extended: true}));
app.use(express.static('public/uploads')); app.use(express.static('public/uploads'));
app.use('/users', UsersRouter); app.use('/users', UsersRouter);
app.use('/posts', new PostsController().getRouter())
app.use('/comments', new CommentController().getRouter())
app.use('/comments', new CommentController().getRouter())
app.listen(process.env.PORT, () => { app.listen(process.env.PORT, () => {
console.log(`App started on port ${process.env.PORT}`); console.log(`App started on port ${process.env.PORT}`);
......
...@@ -7,7 +7,8 @@ const CommentSchema: Schema = new Schema<IComment>({ ...@@ -7,7 +7,8 @@ const CommentSchema: Schema = new Schema<IComment>({
required: true required: true
}, },
datetime: { datetime: {
type: Date type: Date,
default: Date.now,
}, },
user: [ user: [
{ {
......
...@@ -11,6 +11,7 @@ import { Comment } from '../models/Comments'; ...@@ -11,6 +11,7 @@ import { Comment } from '../models/Comments';
import IUser from '../interfaces/IUser'; import IUser from '../interfaces/IUser';
export class Mongo implements IDataBase { export class Mongo implements IDataBase {
[x: string]: any;
private client: Mongoose | null = null private client: Mongoose | null = null
public close = async (): Promise<void> => { public close = async (): Promise<void> => {
......
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