added alias status and check for duplicate
This commit is contained in:
parent
7ff0c87c48
commit
478d4e577b
|
@ -1,6 +1,7 @@
|
||||||
const Minfy = require('../models/minifed_urls')
|
const Minfy = require('../models/minifed_urls')
|
||||||
const base_url = 'https://minfy.xyz/'
|
const base_url = 'https://minfy.xyz/'
|
||||||
const { nanoid } = require('nanoid')
|
const { nanoid } = require('nanoid')
|
||||||
|
const minifed_urls = require('../models/minifed_urls')
|
||||||
|
|
||||||
module.exports.getAllData = async (req, res) => {
|
module.exports.getAllData = async (req, res) => {
|
||||||
Minfy.find({})
|
Minfy.find({})
|
||||||
|
@ -41,9 +42,34 @@ module.exports.findUrlById = async (req, res) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.getAliasStatus = async (req, res) => {
|
||||||
|
try{
|
||||||
|
const alias = req.body.alias;
|
||||||
|
const aliasStatus = await minifed_urls.findOne({ alias });
|
||||||
|
|
||||||
|
if(!aliasStatus){
|
||||||
|
return res.status(200).json("success: true");
|
||||||
|
}else{
|
||||||
|
return res.status(400).json("success: false")
|
||||||
|
}
|
||||||
|
}catch (error){
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.addURL = async (req, res) => {
|
module.exports.addURL = async (req, res) => {
|
||||||
const alias = nanoid(5)
|
const alias = nanoid(5)
|
||||||
const minifiedUrl = base_url + alias
|
const minifiedUrl = base_url + alias
|
||||||
|
|
||||||
|
try{
|
||||||
|
const aliasPresent = await minifed_urls.findOne({ alias });
|
||||||
|
if(aliasPresent){
|
||||||
|
return res.status(400).json("success: false");
|
||||||
|
}
|
||||||
|
}catch (error){
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
|
||||||
Minfy.create({
|
Minfy.create({
|
||||||
originalUrl: req.body.originalUrl,
|
originalUrl: req.body.originalUrl,
|
||||||
alias: alias,
|
alias: alias,
|
||||||
|
@ -56,6 +82,7 @@ module.exports.addURL = async (req, res) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
res.sendStatus(500)
|
res.sendStatus(500)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.deleteUrlData = async (req, res) => {
|
module.exports.deleteUrlData = async (req, res) => {
|
||||||
|
|
|
@ -10,6 +10,7 @@ router.get('/alias/:alias', controller.getURLData)
|
||||||
|
|
||||||
router.post('/add', controller.addURL)
|
router.post('/add', controller.addURL)
|
||||||
router.post('/add/custom', auth, controller.addURLAuthed)
|
router.post('/add/custom', auth, controller.addURLAuthed)
|
||||||
|
router.post('/alias/:alias/status', controller.getAliasStatus)
|
||||||
|
|
||||||
router.patch('/edit/:id', auth, controller.updateUrlData)
|
router.patch('/edit/:id', auth, controller.updateUrlData)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue