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

@ -0,0 +1,17 @@
meta {
name: GetAllExperiences
type: http
seq: 5
}
get {
url: http://localhost:3000/api/experiences/
body: json
auth: inherit
}
body:json {
{
"personId": 1
}
}

View File

@ -3,5 +3,5 @@ auth {
}
auth:bearer {
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTc0OTcxNTI1MCwiZXhwIjoxNzQ5NzQ0MDUwfQ.s1Fn9-Ju5XayFq89MBaQ9AGVm7CIrVvUaDWbnfiBA54
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTc0OTcxNjg4MiwiZXhwIjoxNzQ5NzQ1NjgyfQ.fcvogRFGJtQLX3FKR_fylQRsJE-zhuLwn94J1TgwwkA
}

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);