Merge pull request #28 from para-docx/main
This commit is contained in:
commit
bed33abe05
|
@ -14,8 +14,12 @@ module.exports.getAllData = async (req, res) => {
|
|||
|
||||
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) {
|
||||
|
@ -24,6 +28,17 @@ module.exports.getURLData = async (req, res) => {
|
|||
}
|
||||
}
|
||||
|
||||
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.addURL = async (req, res) => {
|
||||
req.body.minifiedUrl = base_url + req.body.alias
|
||||
Minfy.create(req.body)
|
||||
|
@ -36,27 +51,13 @@ module.exports.addURL = async (req, res) => {
|
|||
})
|
||||
}
|
||||
|
||||
module.exports.deleteUrlData = async (req,res) =>{
|
||||
module.exports.deleteUrlData = async (req, res) => {
|
||||
Minfy.findByIdAndRemove(req.params.id)
|
||||
.then((data)=>{
|
||||
res.send("Successfully Deleted")
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.error(err)
|
||||
res.sendStatus(500)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.updateUrlData = async (req,res) =>{
|
||||
//find a data object with url's id and update the alias
|
||||
Minfy.findByIdAndUpdate(req.params.id, {'alias': req.body.alias})
|
||||
.then((data)=>{
|
||||
//send back the updated data object
|
||||
res.send(data);
|
||||
})
|
||||
.catch((err)=>{
|
||||
//found error
|
||||
console.error(err)
|
||||
res.sendStatus(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,
|
||||
|
|
|
@ -9,6 +9,8 @@ router.get("/alias/:alias", controller.getURLData)
|
|||
|
||||
router.post("/add",controller.addURL)
|
||||
|
||||
router.get("/id/:id", controller.findUrlById)
|
||||
|
||||
router.delete('/delete/:id',controller.deleteUrlData)
|
||||
|
||||
router.patch('/edit/:id', controller.updateUrlData)
|
||||
|
|
Loading…
Reference in New Issue