-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from HancilSequeira/develop
Project setup of url shortening and intial code for saving shortend url
- Loading branch information
Showing
6 changed files
with
692 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.