Skip to content
Snippets Groups Projects
Commit 07421464 authored by chif's avatar chif Committed by Chif Gergő
Browse files

Start using mongodb. [WIP]

parent e0d33218
No related branches found
No related tags found
2 merge requests!10Feature/12 dev auto deploy,!6Feature/news api
import { Request, Response, NextFunction } from 'express';
import { News } from '../../models/News.interface';
import News from '../../models/NewsSchema';
const getNewsListMiddleware = () => {
return (req: Request, res: Response, next: NextFunction) => {
const NewsArray: News[] = [];
NewsArray.push({
author: {
userName: 'Chif',
_id: 0,
},
title: 'Chif news',
text: 'asdasdasdasd',
publishDate: new Date(),
});
res.json({ news: NewsArray});
News.find({}, (err, news) => {
if(!err){
console.log(news);
res.json({ news: news});
}
});
}
}
......
import { Document, Schema, model } from 'mongoose';
interface INews extends Document {
title : string
text : string
/* author : {
// id: IUser["_id"],
userName: string,
},
editedBy?: {
// id: IUser["_id"],
userName: string,
}, */
publishedAt: Date
}
const NewsSchema = new Schema({
title : { type: String, required: true },
text : { type: String, required: true },
/* author : {
id: { type: Schema.Types.ObjectId, required: true },
userName: { type: String, required: true }
},
editedBy: {
id: { type: Schema.Types.ObjectId, required: true },
userName: { type: String, required: true }
}, */
publishedAt: { type: Date, required: true },
});
export default model<INews>('News', NewsSchema);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment