GetExperience, RemoveExperience

This commit is contained in:
xfarrow
2025-06-10 12:52:19 +02:00
parent 443b9d826b
commit 784a9bd5bb
3 changed files with 30 additions and 5 deletions

View File

@ -0,0 +1,11 @@
meta {
name: DeleteExperience
type: http
seq: 3
}
delete {
url: http://localhost:3000/api/experiences/2
body: none
auth: inherit
}

View File

@ -33,16 +33,17 @@ async function insert(experience) {
return insertedExperience[0]; return insertedExperience[0];
} }
async function findById(experienceId) { async function find(experienceId) {
return await knex('Experience').where({ return await knex('Experience').where({
id: experienceId id: experienceId
}).select().first(); }).select().first();
} }
async function remove(experienceId) { async function remove(experienceId, personId) {
await knex('Experience') await knex('Experience')
.where({ .where({
id: experienceId id: experienceId,
person_id: personId
}) })
.del(); .del();
} }
@ -59,7 +60,7 @@ async function update(experience) {
module.exports = { module.exports = {
createExperience, createExperience,
insert, insert,
findById, find,
remove, remove,
update update
}; };

View File

@ -42,7 +42,7 @@ async function find(req, res) {
if (experience == null) { if (experience == null) {
return res.status(404).send(); return res.status(404).send();
} }
return res.status(200).json(jobApplication); return res.status(200).json(experience);
} catch (error) { } catch (error) {
console.error(`Error in function ${find.name}: ${error}`); console.error(`Error in function ${find.name}: ${error}`);
res.status(500).json({ res.status(500).json({
@ -51,9 +51,22 @@ async function find(req, res) {
} }
} }
async function remove(req, res) {
try {
await Experience.remove(req.params.experienceId, req.jwt.person_id);
return res.status(204).send();
} catch (error) {
console.error(`Error in function ${remove.name}: ${error}`);
res.status(500).json({
error: 'Internal server error'
});
}
}
const routes = express.Router(); const routes = express.Router();
routes.post('/', jwtUtils.extractToken, insert); routes.post('/', jwtUtils.extractToken, insert);
routes.get('/:experienceId', jwtUtils.extractToken, find); routes.get('/:experienceId', jwtUtils.extractToken, find);
routes.delete('/:experienceId', jwtUtils.extractToken, remove);
module.exports = { module.exports = {
routes routes