Merge pull request #28 from para-docx/main

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2022-02-02 01:32:03 +05:30 committed by GitHub
commit bed33abe05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 24 deletions

View File

@ -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)
})
}

View File

@ -11,6 +11,7 @@ const minifiedUrlSchema = new Schema(
alias: {
type: String,
required: true,
unique: true,
},
minifiedUrl: {
type: String,

View File

@ -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)