Merge branch 'main' of https://github.com/BRAVO68WEB/url-minify into bug/model

This commit is contained in:
chirag 2022-02-01 20:49:08 +05:30
commit 559a847d33
6 changed files with 1189 additions and 1200 deletions

View File

@ -7,6 +7,7 @@ on:
jobs:
first-job:
runs-on: ubuntu-latest
if: ${{ github.actor != github.repository_owner }}
steps:
- name: Checkout code
uses: actions/checkout@main
@ -16,4 +17,4 @@ jobs:
token: '${{ secrets.GITHUB_TOKEN }}'
author: '${{github.actor}}'
repo: BRAVO68WEB/url-minify
maxIssue: 2
maxIssue: 2

View File

@ -1,13 +1,37 @@
const Minfy = require("../models/minifed_urls")
const base_url = 'https://minfy.xyz/'
module.exports.getURLData = async (req,res) => {
try {
const {alias} = req.params;
const data = await Minfy.findOne({minifiedUrl: alias});
module.exports.getURLData = async (req, res) => {
try {
const { alias } = req.params
const data = await Minfy.findOne({ alias: alias })
data.minifiedUrl = base_url + data.alias
return res.send(data)
} catch (err) {
console.error(err)
res.sendStatus(500)
}
}
return res.send( data);
}catch(err){
console.error(err)
res.sendStatus(500)
}
module.exports.addURL = async (req, res) => {
req.body.minifiedUrl = base_url + req.body.alias
Minfy.create(req.body)
.then((data)=>{
res.send(data)
})
.catch((err)=>{
console.error(err)
res.sendStaus(500)
})
}
module.exports.deleteUrlData = async (req,res) =>{
Minfy.findByIdAndRemove(req.params.id)
.then((data)=>{
res.send("Successfully Deleted")
})
.catch((err)=>{
console.error(err)
res.sendStaus(500)
})
}

View File

@ -1,22 +1,26 @@
import mongoose from 'mongoose';
const { Schema } = mongoose;
const mongoose = require('mongoose')
const { Schema } = mongoose
//build a schema
const minifiedUrlSchema = new Schema({
originalUrl: {
type: String,
required: true
},
minifiedUrl: {
type: String,
required: true
},
views: {
type: Number
},
createdAt: Number,
updatedAt: Number
});
const minifiedUrlSchema = new Schema(
{
originalUrl: {
type: String,
required: true,
},
alias: {
type: String,
required: true,
},
minifiedUrl: {
type: String,
required: true,
},
views: {
type: Number,
},
},
{ timestamp: true }
)
//make a model using this schema and export it
exports.default = mongoose.model('minified_url_model', minifiedUrlSchema);
module.exports = mongoose.model('minified_url_model', minifiedUrlSchema)

View File

@ -5,4 +5,8 @@ const router = Router();
router.get("/alias/:alias", controller.getURLData)
router.post("/add",controller.addURL)
router.delete('/delete/:id',controller.deleteUrlData)
module.exports = router;

File diff suppressed because it is too large Load Diff

3
package-lock.json generated Normal file
View File

@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}