add personcontactinfo routes

This commit is contained in:
xfarrow 2024-10-31 09:44:25 +01:00
parent 7f45379ebc
commit a29a8877d5
3 changed files with 65 additions and 0 deletions

View File

@ -27,6 +27,7 @@ const jobOffersRoutes = require('./routes/job_offer_routes.js');
const serverRoutes = require('./routes/server_routes.js'); const serverRoutes = require('./routes/server_routes.js');
const resetPasswordRoutes = require('./routes/reset_password_routes.js'); const resetPasswordRoutes = require('./routes/reset_password_routes.js');
const applicationRoutes = require('./routes/job_application_routes.js'); const applicationRoutes = require('./routes/job_application_routes.js');
const personContactInfosRoutes = require('./routes/person_contact_info_routes.js');
/* /*
===== END IMPORTING MODULES ===== ===== END IMPORTING MODULES =====
@ -57,6 +58,7 @@ app.use('/api/organizations', jobOffersRoutes.routes);
app.use('/api/organizations', organizationAdminRoutes.routes); app.use('/api/organizations', organizationAdminRoutes.routes);
app.use('/api/resetpassword', resetPasswordRoutes.routes); app.use('/api/resetpassword', resetPasswordRoutes.routes);
app.use('/api/organizations', applicationRoutes.routes); app.use('/api/organizations', applicationRoutes.routes);
app.use('/api/persons', personContactInfosRoutes.routes);
/* /*
===== END ROUTE HANDLING ===== ===== END ROUTE HANDLING =====

View File

@ -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
}

View File

@ -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
};