From a29a8877d52b77d836d0381a0f787ae3127b1de7 Mon Sep 17 00:00:00 2001 From: xfarrow <49845537+xfarrow@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:44:25 +0100 Subject: [PATCH] add personcontactinfo routes --- backend/apis/nodejs/src/app.js | 2 ++ .../nodejs/src/models/person_contact_info.js | 28 +++++++++++++++ .../src/routes/person_contact_info_routes.js | 35 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 backend/apis/nodejs/src/models/person_contact_info.js create mode 100644 backend/apis/nodejs/src/routes/person_contact_info_routes.js diff --git a/backend/apis/nodejs/src/app.js b/backend/apis/nodejs/src/app.js index 53e0126..6eb4d44 100644 --- a/backend/apis/nodejs/src/app.js +++ b/backend/apis/nodejs/src/app.js @@ -27,6 +27,7 @@ const jobOffersRoutes = require('./routes/job_offer_routes.js'); const serverRoutes = require('./routes/server_routes.js'); const resetPasswordRoutes = require('./routes/reset_password_routes.js'); const applicationRoutes = require('./routes/job_application_routes.js'); +const personContactInfosRoutes = require('./routes/person_contact_info_routes.js'); /* ===== END IMPORTING MODULES ===== @@ -57,6 +58,7 @@ app.use('/api/organizations', jobOffersRoutes.routes); app.use('/api/organizations', organizationAdminRoutes.routes); app.use('/api/resetpassword', resetPasswordRoutes.routes); app.use('/api/organizations', applicationRoutes.routes); +app.use('/api/persons', personContactInfosRoutes.routes); /* ===== END ROUTE HANDLING ===== diff --git a/backend/apis/nodejs/src/models/person_contact_info.js b/backend/apis/nodejs/src/models/person_contact_info.js new file mode 100644 index 0000000..8894ed1 --- /dev/null +++ b/backend/apis/nodejs/src/models/person_contact_info.js @@ -0,0 +1,28 @@ +/* + This code is part of Blink + licensed under GPLv3 + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +const knex = require('../utils/knex_config'); + +async function insert(personId, infoContent, infoType) { + return await knex('PersonContactInfo') + .insert({ + person_id: personId, + info: infoContent, + info_type: infoType + }) + .returning("*"); +} + +module.exports = { + insert +} \ No newline at end of file diff --git a/backend/apis/nodejs/src/routes/person_contact_info_routes.js b/backend/apis/nodejs/src/routes/person_contact_info_routes.js new file mode 100644 index 0000000..c09f249 --- /dev/null +++ b/backend/apis/nodejs/src/routes/person_contact_info_routes.js @@ -0,0 +1,35 @@ +/* + This code is part of Blink + licensed under GPLv3 + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +const express = require('express'); +const jwtUtils = require('../utils/jwt_utils'); +const PersonContactInfo = require('../models/person_contact_info'); + +async function insert(req, res) { + try { + const contactInfo = PersonContactInfo.insert(req.jwt.person_id, req.body.content, req.body.info_type); + res.set('Location', `/api/persons/${req.jwt.person_id}/contactinfos/${contactInfo.id}`); + return res.status(201).json(application); + } catch (error) { + console.error(`Error in function ${insert.name}: ${error}`); + res.status(500).json({ + error: 'Internal server error' + }); + } +} + +const routes = express.Router(); +routes.post('/myself/contactinfos', jwtUtils.extractToken, insert); +module.exports = { + routes +}; \ No newline at end of file