GetAllExperiences

This commit is contained in:
xfarrow
2025-06-12 10:30:41 +02:00
parent fd10337d14
commit fef02480d6
5 changed files with 39 additions and 3 deletions

View File

@ -3,7 +3,7 @@
# API server settings
API_SERVER_PORT = 3000
JWT_SECRET_KEY = jwt-secret # Change this in production
JWT_SECRET_KEY = CHANGE_ME # Change this in production
LIMITER_WINDOW = 3600000 # Milliseconds in limiter window
LIMITER_MAXIMUM_PER_WINDOW = 5000 # Requests for each limiter window

View File

@ -60,6 +60,11 @@ async function update(experience) {
.update(experience);
}
async function getAllExperiences(person_id){
return await knex('Experience')
.where('person_id', person_id);
}
// Exporting a function
// means making a JavaScript function defined in one
// module available for use in another module.
@ -68,5 +73,6 @@ module.exports = {
insert,
find,
remove,
update
update,
getAllExperiences
};

View File

@ -110,9 +110,22 @@ async function update(req, res) {
}
}
async function allExperiences(req, res){
try {
const experiences = await Experience.getAllExperiences(req.body.personId);
return res.status(200).json(experiences);
} 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.get('/', jwtUtils.extractToken, allExperiences);
routes.delete('/:experienceId', jwtUtils.extractToken, remove);
routes.patch('/:experienceId', jwtUtils.extractToken, update);