mirror of https://github.com/xfarrow/blink
add delete method in contactinfo
This commit is contained in:
parent
7378c85d50
commit
338e314613
|
@ -29,7 +29,15 @@ async function getInfoByPerson(personId) {
|
|||
.where('person_id', personId);
|
||||
}
|
||||
|
||||
async function remove(contactInfoId, personId) {
|
||||
return (await knex('PersonContactInfo')
|
||||
.where('id', contactInfoId)
|
||||
.where('person_id', personId)
|
||||
.del() === 1)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
insert,
|
||||
remove,
|
||||
getInfoByPerson
|
||||
}
|
|
@ -40,13 +40,26 @@ async function findByPerson(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
async function remove(req, res){
|
||||
|
||||
async function remove(req, res) {
|
||||
try {
|
||||
const success = await PersonContactInfo.remove(req.params.contactInfoId, req.jwt.person_id);
|
||||
if (success) {
|
||||
return res.status(200).send();
|
||||
} else {
|
||||
return res.status(400).send();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${insert.name}: ${error}`);
|
||||
res.status(500).json({
|
||||
error: 'Internal server error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const routes = express.Router();
|
||||
routes.post('/myself/contactinfos', jwtUtils.extractToken, insert);
|
||||
routes.get('/:personId/contactinfos', jwtUtils.extractToken, findByPerson)
|
||||
routes.delete('/contactinfos/:contactInfoId', jwtUtils.extractToken, remove)
|
||||
module.exports = {
|
||||
routes
|
||||
};
|
Loading…
Reference in New Issue