Skip to content

Commit

Permalink
Merge pull request #1 from HancilSequeira/develop
Browse files Browse the repository at this point in the history
Project setup of url shortening and intial code for saving shortend url
  • Loading branch information
HancilSequeira authored Mar 16, 2020
2 parents 4672965 + 42a969c commit c4fdf8b
Show file tree
Hide file tree
Showing 6 changed files with 692 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
38 changes: 38 additions & 0 deletions models/urlShortner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const shortId = require('shortid');

const urlShortner = new Schema({
actualUrl:{
type: String,
required: true
},
shortUrl:{
type: String,
required: true,
default: shortId.generate()
},
created_at : Date,
updated_at: Date

});


/**
* to save date and time
*/
urlShortner.pre('save', function(next) {
const currentDate = new Date();

this.updated_at = currentDate;

if (!this.created_at) {
this.created_at = currentDate;
}
next();
});


const urlShortnerModel = mongoose.model('urlShortner', urlShortner);

module.exports = urlShortnerModel;
Loading

0 comments on commit c4fdf8b

Please sign in to comment.