From fef02480d6640666675ec7bbd7bfe00be8db3422 Mon Sep 17 00:00:00 2001 From: xfarrow <49845537+xfarrow@users.noreply.github.com> Date: Thu, 12 Jun 2025 10:30:41 +0200 Subject: [PATCH] GetAllExperiences --- .../Experience/GetAllExperiences.bru | 17 +++++++++++++++++ backend/apis/BlinkApiCollection/collection.bru | 2 +- backend/apis/nodejs/src/.env | 2 +- .../apis/nodejs/src/models/experience_model.js | 8 +++++++- .../apis/nodejs/src/routes/experience_routes.js | 13 +++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 backend/apis/BlinkApiCollection/Experience/GetAllExperiences.bru diff --git a/backend/apis/BlinkApiCollection/Experience/GetAllExperiences.bru b/backend/apis/BlinkApiCollection/Experience/GetAllExperiences.bru new file mode 100644 index 0000000..2a4f8cc --- /dev/null +++ b/backend/apis/BlinkApiCollection/Experience/GetAllExperiences.bru @@ -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 + } +} diff --git a/backend/apis/BlinkApiCollection/collection.bru b/backend/apis/BlinkApiCollection/collection.bru index d1bfba2..4ae162b 100644 --- a/backend/apis/BlinkApiCollection/collection.bru +++ b/backend/apis/BlinkApiCollection/collection.bru @@ -3,5 +3,5 @@ auth { } auth:bearer { - token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTc0OTcxNTI1MCwiZXhwIjoxNzQ5NzQ0MDUwfQ.s1Fn9-Ju5XayFq89MBaQ9AGVm7CIrVvUaDWbnfiBA54 + token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwZXJzb25faWQiOjEsImlhdCI6MTc0OTcxNjg4MiwiZXhwIjoxNzQ5NzQ1NjgyfQ.fcvogRFGJtQLX3FKR_fylQRsJE-zhuLwn94J1TgwwkA } diff --git a/backend/apis/nodejs/src/.env b/backend/apis/nodejs/src/.env index bd790b9..0ad54bb 100644 --- a/backend/apis/nodejs/src/.env +++ b/backend/apis/nodejs/src/.env @@ -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 diff --git a/backend/apis/nodejs/src/models/experience_model.js b/backend/apis/nodejs/src/models/experience_model.js index 35c8d48..31d6147 100644 --- a/backend/apis/nodejs/src/models/experience_model.js +++ b/backend/apis/nodejs/src/models/experience_model.js @@ -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 }; \ No newline at end of file diff --git a/backend/apis/nodejs/src/routes/experience_routes.js b/backend/apis/nodejs/src/routes/experience_routes.js index f15e57c..0578592 100644 --- a/backend/apis/nodejs/src/routes/experience_routes.js +++ b/backend/apis/nodejs/src/routes/experience_routes.js @@ -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);