mirror of
https://github.com/SrIzan10/YouRL.git
synced 2026-05-01 11:15:09 +00:00
Adding data model/ Schema
| fullurl | shorturl | clicks | + shortid-library to shorten url/get id from url
This commit is contained in:
29
models/shortUrl.js
Normal file
29
models/shortUrl.js
Normal file
@@ -0,0 +1,29 @@
|
||||
//to connect to mongodb
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
// to create short identifier
|
||||
//has .generate() function that we will pass to shorturl as default
|
||||
const shortId = require("shortid");
|
||||
|
||||
//db schema
|
||||
// | fullurl | shorturl | clicks |
|
||||
const shortUrlSchema = new mongoose.Schema({
|
||||
fullurl: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
shorturl: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: shortId.generate,
|
||||
},
|
||||
clicks: {
|
||||
type: Number,
|
||||
required: true,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
//now exporting this to hook model with database
|
||||
// model name, schema name
|
||||
modules.exports = mongoose.model("shortUrl", shortUrlSchema);
|
||||
13
package-lock.json
generated
13
package-lock.json
generated
@@ -991,6 +991,11 @@
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"nanoid": {
|
||||
"version": "2.1.11",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz",
|
||||
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA=="
|
||||
},
|
||||
"negotiator": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
||||
@@ -1342,6 +1347,14 @@
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||
},
|
||||
"shortid": {
|
||||
"version": "2.2.15",
|
||||
"resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.15.tgz",
|
||||
"integrity": "sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==",
|
||||
"requires": {
|
||||
"nanoid": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"sift": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz",
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
"dependencies": {
|
||||
"ejs": "^3.1.5",
|
||||
"express": "^4.17.1",
|
||||
"mongoose": "^5.10.8"
|
||||
"mongoose": "^5.10.8",
|
||||
"shortid": "^2.2.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.4"
|
||||
|
||||
Reference in New Issue
Block a user