From d599c83bd6004d3572b047558ef567d52facbe61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chif.gergo@kszk.bme.hu>
Date: Mon, 24 Feb 2020 21:31:30 +0100
Subject: [PATCH] Configure mongoose connection, replace Date with string in
 NewsSchema

---
 src/index.ts             | 8 ++++++++
 src/models/NewsSchema.ts | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/index.ts b/src/index.ts
index 6d84fb60..ff0948f1 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,10 +1,18 @@
 import "./utils/env"
 import express, { Request, Response, NextFunction, Application } from "express";
+import mongoose from "mongoose";
 import bodyParser from "body-parser";
 import expressSession from "express-session";
 import authRoute from './routes/auth';
 import newsRoute from './routes/news';
 
+mongoose.connect('mongodb://localhost:27017/bodysch', { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true } ).then(
+  () => { console.log("Connected to database") },
+).catch(err => {
+  console.log("MongoDB connection error. Please make sure MongoDB is running. " + err);
+  // process.exit();
+});
+
 const app: Application = express();
 
 app.use(bodyParser.json()); // for parsing application/json
diff --git a/src/models/NewsSchema.ts b/src/models/NewsSchema.ts
index 192d2f32..d49e39df 100644
--- a/src/models/NewsSchema.ts
+++ b/src/models/NewsSchema.ts
@@ -11,7 +11,7 @@ interface INews extends Document {
        // id: IUser["_id"],
         userName: string,
     }, */
-    publishedAt: Date
+    publishedAt: string
 }
 
 const NewsSchema = new Schema({
@@ -25,7 +25,7 @@ const NewsSchema = new Schema({
         id: { type: Schema.Types.ObjectId, required: true },
         userName: { type: String, required: true }
     }, */
-    publishedAt: { type: Date, required: true }, 
+    publishedAt: { type: String, required: true }, 
 });
 
 export default model<INews>('News', NewsSchema);
\ No newline at end of file
-- 
GitLab