Skip to content
Snippets Groups Projects
Commit 04208431 authored by GustafWallstrom's avatar GustafWallstrom
Browse files

Added todays date on the post. Date also added to Post schema.

parent ab149fda
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@
<form>
<div class="form-group">
<label for="exampleInputEmail1">Course</label>
<input name="title" type="text" [(ngModel)]="post.title" class="form-control" aria-describedby="emailHelp" placeholder="Enter the name of the course">
<input name="title" type="text" [(ngModel)]="post.title" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter the name of the course">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Number of throws</label>
......
......@@ -26,7 +26,7 @@ export class AddPostComponent {
this.commonService.notifyPostAddition();
});
} else {
alert('Title and Description required');
alert('Enter course and number of strokes!');
}
}
......
......@@ -10,9 +10,17 @@ export class AddPostService {
}
addPost(post: Post){
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
var todayString = String(dd + '-' + mm + '-' + yyyy);
return this.http.post('/api/post/createPost',{
title : post.title,
description : post.description
description : post.description,
date: todayString
})
}
......
......@@ -3,8 +3,10 @@ export class Post {
this.id = '';
this.title = '';
this.description = '';
this.date = '';
}
public id;
public title;
public description;
public date;
}
\ No newline at end of file
......@@ -3,7 +3,7 @@
<a *ngFor="let post of posts" href="#" class="list-group-item list-group-item-action flex-column align-items-start">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">Course: <span style="color:#850505">{{post.title}}</span></h5>
<small>3 days ago</small>
<small>{{post.date}}</small>
</div>
<p class="mb-1">Number of strokes: <span style="color:#850505">{{post.description}}</span></p>
<small>Click for more details</small>
......
......@@ -45,7 +45,8 @@ app.post('/api/user/create', (req, res) => {
const user = new User({
name: req.body.name,
username: req.body.username,
password: req.body.password
password: req.body.password,
date: req.body.date
})
user.save((err, res) => {
if (err) throw err;
......@@ -65,7 +66,8 @@ app.post('/api/post/createPost', (req, res) => {
if (err) throw err;
const post = new Post({
title: req.body.title,
description: req.body.description
description: req.body.description,
date: req.body.date
})
post.save((err, doc) => {
if (err) throw err;
......
......@@ -3,9 +3,22 @@ const Schema = mongoose.Schema;
// create a schema
const postSchema = new Schema({
title: { type: String, required: true },
description: { type: String, required: true }
}, { collection : 'post' });
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
date: {
type: String,
required: true
}
}, {
collection: 'post',
versionKey: false
});
const Post = mongoose.model('Post', postSchema);
module.exports = Post;
\ No newline at end of file
......@@ -3,10 +3,22 @@ const Schema = mongoose.Schema;
// create a schema
const userSchema = new Schema({
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
name: { type: String }
}, { collection : 'user' });
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
name: {
type: String
}
}, {
collection: 'user',
versionKey: false
});
const User = mongoose.model('User', userSchema);
......
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