Skip to content

Commit 9d45fc0

Browse files
committed
Remove global ApiRouter & update everything else
1 parent 35c88a9 commit 9d45fc0

File tree

7 files changed

+49
-262
lines changed

7 files changed

+49
-262
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"main": "index.js",
55
"license": "MIT",
66
"scripts": {
7-
"server:dev": "tsc && nodemon ./build/server/index.js",
8-
"server:prod": "node ./build/server/index.js"
7+
"server": "tsc && nodemon ./build/server/index.js",
8+
"start": "node ./build/server/index.js"
99
},
1010
"dependencies": {
1111
"bcrypt-nodejs": "^0.0.3",
@@ -19,8 +19,8 @@
1919
"handlebars": "^4.0.6",
2020
"helmet": "^3.5.0",
2121
"lodash": "^4.17.4",
22-
"mongoose": "^4.9.4",
2322
"morgan": "^1.8.1",
23+
"rethinkdb": "^2.3.3",
2424
"rxjs": "^5.3.0",
2525
"socket.io": "^1.7.3",
2626
"socket.io-client": "^1.7.3"

src/controllers/PostController.ts

-52
This file was deleted.

src/models/Post.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as mongoose from 'mongoose';
2-
const Schema = mongoose.Schema;
1+
import { Schema, model } from 'mongoose';
32

4-
const PostSchema = new Schema({
3+
4+
let PostSchema: Schema = new Schema({
55
timestamp: {
66
type: Date,
77
default: Date.now
@@ -24,10 +24,19 @@ const PostSchema = new Schema({
2424
required: true,
2525
unique: true
2626
},
27-
author: {
28-
type: Schema.Types.ObjectId,
29-
ref: 'User'
27+
featuredImage: {
28+
type: String,
29+
default: ''
30+
},
31+
category: {
32+
type: String,
33+
default: '',
34+
required: true
35+
},
36+
published: {
37+
type: Boolean,
38+
default: false
3039
}
3140
});
3241

33-
export default mongoose.model('Post', PostSchema);
42+
export default model('Post', PostSchema);

src/router/ApiRouter.ts

-82
This file was deleted.

src/router/PostRouter.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class PostRouter {
2222
}
2323

2424
public getPostBySlug(req: Request, res: Response, next: NextFunction) {
25-
const slug = req.params.slug;
25+
const slug: string = req.params.slug;
2626

2727
Post.findOne({slug})
2828
.then((post) => {
@@ -36,9 +36,12 @@ export class PostRouter {
3636

3737
// create post
3838
public createPost(req: Request, res: Response, next: NextFunction): void {
39-
const title = req.body.title;
40-
const slug = req.body.slug;
41-
const content = req.body.content;
39+
const title: string = req.body.title;
40+
const slug: string = req.body.slug;
41+
const content: string = req.body.content;
42+
const featuredImage: string = req.body.featuredImage;
43+
const category: string = req.body.category;
44+
const published: boolean = req.body.published;
4245

4346
if (!title || !slug || !content) {
4447
res.status(422).json({ message: 'All Fields Required.' });
@@ -47,7 +50,10 @@ export class PostRouter {
4750
const post = new Post({
4851
title,
4952
slug,
50-
content
53+
content,
54+
featuredImage,
55+
category,
56+
published
5157
});
5258

5359
post.save()
@@ -62,7 +68,7 @@ export class PostRouter {
6268

6369
// update post by slug
6470
public updatePost(req: Request, res: Response, next: NextFunction): void {
65-
const slug = req.body.slug;
71+
const slug: string = req.body.slug;
6672

6773
Post.findOneAndUpdate({slug}, req.body)
6874
.then((post) => {
@@ -76,7 +82,7 @@ export class PostRouter {
7682

7783
// delete post by slug
7884
public deletePost(req: Request, res: Response, next: NextFunction): void {
79-
const slug = req.body.slug;
85+
const slug: string = req.body.slug;
8086

8187
Post.findOneAndRemove({slug})
8288
.then((post) => {

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"outDir": "./build/server/",
3+
"outDir": "./build/",
44
"module": "commonjs",
55
"target": "es5",
66
"sourceMap": true

0 commit comments

Comments
 (0)