diff --git a/backend/apis/nodejs/src/models/person_contact_info_model.js b/backend/apis/nodejs/src/models/person_contact_info_model.js index 0fcda98..219fe25 100644 --- a/backend/apis/nodejs/src/models/person_contact_info_model.js +++ b/backend/apis/nodejs/src/models/person_contact_info_model.js @@ -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 } \ No newline at end of file diff --git a/backend/apis/nodejs/src/routes/person_contact_info_routes.js b/backend/apis/nodejs/src/routes/person_contact_info_routes.js index 99ba575..3036da7 100644 --- a/backend/apis/nodejs/src/routes/person_contact_info_routes.js +++ b/backend/apis/nodejs/src/routes/person_contact_info_routes.js @@ -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 }; \ No newline at end of file