mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
GetExperience, RemoveExperience
This commit is contained in:
@ -33,16 +33,17 @@ async function insert(experience) {
|
||||
return insertedExperience[0];
|
||||
}
|
||||
|
||||
async function findById(experienceId) {
|
||||
async function find(experienceId) {
|
||||
return await knex('Experience').where({
|
||||
id: experienceId
|
||||
}).select().first();
|
||||
}
|
||||
|
||||
async function remove(experienceId) {
|
||||
async function remove(experienceId, personId) {
|
||||
await knex('Experience')
|
||||
.where({
|
||||
id: experienceId
|
||||
id: experienceId,
|
||||
person_id: personId
|
||||
})
|
||||
.del();
|
||||
}
|
||||
@ -59,7 +60,7 @@ async function update(experience) {
|
||||
module.exports = {
|
||||
createExperience,
|
||||
insert,
|
||||
findById,
|
||||
find,
|
||||
remove,
|
||||
update
|
||||
};
|
@ -42,7 +42,7 @@ async function find(req, res) {
|
||||
if (experience == null) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
return res.status(200).json(jobApplication);
|
||||
return res.status(200).json(experience);
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${find.name}: ${error}`);
|
||||
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();
|
||||
routes.post('/', jwtUtils.extractToken, insert);
|
||||
routes.get('/:experienceId', jwtUtils.extractToken, find);
|
||||
routes.delete('/:experienceId', jwtUtils.extractToken, remove);
|
||||
|
||||
module.exports = {
|
||||
routes
|
||||
|
Reference in New Issue
Block a user