Commit c6afdce8 authored by Болатов Ален's avatar Болатов Ален

Merge branch '#7' into 'dev'

posts controllers created

See merge request !8
parents c996fb6d d82c3461
import express, { Router, Request, Response } from 'express'
import multer from 'multer'
import { config } from '../index.config'
const storage = multer.diskStorage({
destination(req, file, callback) {
callback(null,
config.filePath)
},
filename(req, file, callback) {
callback(null,
file.originalname)
},
})
const upload = multer({storage})
export class PostsController {
private router: Router
constructor() {
this.router = express.Router()
}
public getRouter = (): Router => {
return this.router
}
}
\ No newline at end of file
export const enum EStatuses {
OK = 1,
NOT_OK = 0
}
\ No newline at end of file
import path from 'path'
export const config = {
filePath: path.join(__dirname, '../public/uploads')
}
\ No newline at end of file
...@@ -15,3 +15,5 @@ app.use(express.static('public/uploads')); ...@@ -15,3 +15,5 @@ app.use(express.static('public/uploads'));
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}`);
}); });
import { Document, ObjectId } from "mongoose";
export default interface IPost extends Document {
_id: ObjectId
title: string
description: string
image: File | undefined | string
datetime: Date
}
\ No newline at end of file
import IPost from "./IPost"
export default interface IPostDto {
title: IPost['title']
description: IPost['description']
image: File | undefined | string
}
\ No newline at end of file
import mongoose, { Schema } from "mongoose";
import IPost from "../interfaces/IPost";
const PostsSchema: Schema = new Schema<IPost>({
title: {
type: String,
required: true
},
description: {
type: String,
required: false
},
image: String,
datetime: {
type: Date
}
}, {
versionKey: false
})
export const Post = mongoose.model<IPost>('Post', PostsSchema)
\ No newline at end of file
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