add delete method in contactinfo

This commit is contained in:
xfarrow 2024-10-31 15:35:41 +01:00
parent 7378c85d50
commit 338e314613
2 changed files with 23 additions and 2 deletions

View File

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

View File

@ -41,12 +41,25 @@ async function findByPerson(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
};