added findbyid route
This commit is contained in:
parent
91920bfc8e
commit
c28c4c950b
|
@ -3,8 +3,12 @@ const base_url = 'https://minfy.xyz/'
|
|||
|
||||
module.exports.getURLData = async (req, res) => {
|
||||
try {
|
||||
const { alias } = req.params
|
||||
const data = await Minfy.findOne({ alias: alias })
|
||||
const {
|
||||
alias
|
||||
} = req.params
|
||||
const data = await Minfy.findOne({
|
||||
alias: alias
|
||||
})
|
||||
data.minifiedUrl = base_url + data.alias
|
||||
return res.send(data)
|
||||
} catch (err) {
|
||||
|
@ -13,25 +17,36 @@ module.exports.getURLData = async (req, res) => {
|
|||
}
|
||||
}
|
||||
|
||||
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.findUrlById = async (req, res) => {
|
||||
Minfy.findById(req.params.id).then((data) => {
|
||||
res.send(data)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
res.sendStatus(500)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
module.exports.deleteUrlData = async (req,res) =>{
|
||||
module.exports.addURL = async (req, res) => {
|
||||
req.body.minifiedUrl = base_url + req.body.alias
|
||||
Minfy.create(req.body).select("-__v")
|
||||
.then((data) => {
|
||||
res.send(data)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
res.sendStatus(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)
|
||||
})
|
||||
.then((data) => {
|
||||
res.send("Successfully Deleted")
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
res.sendStaus(500)
|
||||
})
|
||||
}
|
|
@ -11,6 +11,7 @@ const minifiedUrlSchema = new Schema(
|
|||
alias: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
},
|
||||
minifiedUrl: {
|
||||
type: String,
|
||||
|
|
|
@ -7,6 +7,8 @@ router.get("/alias/:alias", controller.getURLData)
|
|||
|
||||
router.post("/add",controller.addURL)
|
||||
|
||||
router.get("/id/:id", controller.findUrlById)
|
||||
|
||||
router.delete('/delete/:id',controller.deleteUrlData)
|
||||
|
||||
module.exports = router;
|
Loading…
Reference in New Issue