diff --git a/backend/apis/nodejs/src/models/organization_admin_model.js b/backend/apis/nodejs/src/models/organization_admin_model.js index 90c2c83..936384d 100644 --- a/backend/apis/nodejs/src/models/organization_admin_model.js +++ b/backend/apis/nodejs/src/models/organization_admin_model.js @@ -20,7 +20,7 @@ const knex = require('../utils/knex_config'); * @param {*} organizationId * @returns true if administrator, false otherwise */ -async function isPersonOrganizationAdministrator(personId, organizationId) { +async function isAdmin(personId, organizationId) { const isPersonAdmin = await knex('OrganizationAdministrator') .where('id_person', personId) .where('id_organization', organizationId) @@ -36,10 +36,10 @@ async function isPersonOrganizationAdministrator(personId, organizationId) { * @param {*} organizationId * @param {*} requester Id of the person requesting the addition */ -async function addOrganizationAdministrator(personId, organizationId, requester) { +async function insert(personId, organizationId, requester) { - const isRequesterAdmin = await isPersonOrganizationAdministrator(requester, organizationId); - const isPersonAdmin = await isPersonOrganizationAdministrator(personId, organizationId); + const isRequesterAdmin = await isAdmin(requester, organizationId); + const isPersonAdmin = await isAdmin(personId, organizationId); // avoid database exception // Unexploitable TOCTOU if (isRequesterAdmin && !isPersonAdmin) { await knex('OrganizationAdministrator') @@ -58,7 +58,7 @@ async function addOrganizationAdministrator(personId, organizationId, requester) * @param {*} personId * @param {*} organizationId */ -async function removeOrganizationAdmin(personId, organizationId) { +async function remove(personId, organizationId) { const transaction = await knex.transaction(); // We lock the table to ensure that we won't have concurrency issues @@ -88,7 +88,7 @@ async function removeOrganizationAdmin(personId, organizationId) { } module.exports = { - isPersonOrganizationAdministrator, - addOrganizationAdministrator, - removeOrganizationAdmin + isOrganizationAdmin: isAdmin, + insert, + remove }; \ No newline at end of file diff --git a/backend/apis/nodejs/src/models/organization_model.js b/backend/apis/nodejs/src/models/organization_model.js index f0f0e07..4cb84e0 100644 --- a/backend/apis/nodejs/src/models/organization_model.js +++ b/backend/apis/nodejs/src/models/organization_model.js @@ -36,7 +36,7 @@ function createOrganization(name, location, description, isHiring) { * @param {*} id * @returns the Organization */ -async function getOrganizationById(id) { +async function findById(id) { const organization = await knex('Organization') .where('id', id) .select('*') @@ -50,7 +50,7 @@ async function getOrganizationById(id) { * * @returns The inserted Organization */ -async function insertOrganization(organization, organizationAdministratorId) { +async function insert(organization, organizationAdministratorId) { return await knex.transaction(async (trx) => { // We have to insert either both in Organization and in OrganizationAdministrator // or in neither @@ -76,7 +76,7 @@ async function insertOrganization(organization, organizationAdministratorId) { * @param {*} requester * @returns true if the row was updated, false otherwise */ -async function updateOrganization(organization, organizationId, requester) { +async function update(organization, organizationId, requester) { const numberOfUpdatedRows = await knex('Organization') .where('id', organizationId) .whereExists(function () { @@ -96,7 +96,7 @@ async function updateOrganization(organization, organizationId, requester) { * @param {*} requester PersonId of the supposedly administrator * @returns true if the Organization was successfully deleted, false otherwise */ -async function deleteOrganization(organizationId, requester) { +async function remove(organizationId, requester) { const numberOfDeletedRows = await knex('Organization') .where({ id: organizationId @@ -115,9 +115,9 @@ async function deleteOrganization(organizationId, requester) { // means making a JavaScript function defined in one // module available for use in another module. module.exports = { - getOrganizationById, + findById, createOrganization, - insertOrganization, - updateOrganization, - deleteOrganization + insert, + update, + deleteOrganization: remove }; \ No newline at end of file diff --git a/backend/apis/nodejs/src/models/organization_post_model.js b/backend/apis/nodejs/src/models/organization_post_model.js index e501c4a..91ed93b 100644 --- a/backend/apis/nodejs/src/models/organization_post_model.js +++ b/backend/apis/nodejs/src/models/organization_post_model.js @@ -11,6 +11,19 @@ IN THE SOFTWARE. */ +/****************************************************************************** + * ⚠ WARNING ⚠ + * + * + * Posts are now scheduled to be developed at a later stage in the development + * process, with the possibility that it may not be developed at all. + * I am unsure whether it is a good thing or it'll only be used to + * flood timelines with low-effort content, like other competing platforms. + * + * + * + ******************************************************************************/ + const knex = require('../utils/knex_config'); /** diff --git a/backend/apis/nodejs/src/routes/organization_admin_routes.js b/backend/apis/nodejs/src/routes/organization_admin_routes.js index 961dfee..1e95b35 100644 --- a/backend/apis/nodejs/src/routes/organization_admin_routes.js +++ b/backend/apis/nodejs/src/routes/organization_admin_routes.js @@ -11,7 +11,7 @@ IN THE SOFTWARE. */ -const organizationAdminModel = require('../models/organization_admin_model'); +const organizationAdmin = require('../models/organization_admin_model'); const express = require('express'); const jwtUtils = require('../utils/jwt_utils'); const organizationAdminValidator = require('../utils/validators/organization_admin_validator'); @@ -32,7 +32,7 @@ async function addOrganizationAdmin(req, res) { errors: errors.array() }); } - const success = await organizationAdminModel.addOrganizationAdministrator(req.body.person_id, req.params.organizationId, req.jwt.person_id); + const success = await organizationAdmin.insert(req.body.person_id, req.params.organizationId, req.jwt.person_id); if (success) { return res.status(204).send(); } @@ -64,7 +64,7 @@ async function removeOrganizationAdmin(req, res) { errors: errors.array() }); } - const success = await organizationAdminModel.removeOrganizationAdmin(req.jwt.person_id, req.params.organizationId); + const success = await organizationAdmin.remove(req.jwt.person_id, req.params.organizationId); if(success){ return res.status(204).send(); } diff --git a/backend/apis/nodejs/src/routes/organization_routes.js b/backend/apis/nodejs/src/routes/organization_routes.js index 77088c0..fb4d657 100644 --- a/backend/apis/nodejs/src/routes/organization_routes.js +++ b/backend/apis/nodejs/src/routes/organization_routes.js @@ -11,7 +11,7 @@ IN THE SOFTWARE. */ -const organizationModel = require('../models/organization_model'); +const Organization = require('../models/organization_model'); const express = require('express'); const jwtUtils = require('../utils/jwt_utils'); const organizationValidator = require('../utils/validators/organization_validator'); @@ -34,8 +34,8 @@ async function createOrganization(req, res) { errors: errors.array() }); } - const organization = organizationModel.createOrganization(req.body.name, req.body.location, req.body.description, req.body.is_hiring); - const insertedOrganization = await organizationModel.insertOrganization(organization, req.jwt.person_id); + const organization = Organization.createOrganization(req.body.name, req.body.location, req.body.description, req.body.is_hiring); + const insertedOrganization = await Organization.insert(organization, req.jwt.person_id); res.set('Location', `/api/organizations/${insertedOrganization.id}`); return res.status(201).json(insertedOrganization); } catch (error) { @@ -85,7 +85,7 @@ async function updateOrganization(req, res) { } try { - const isUpdateSuccessful = organizationModel.updateOrganization(updateOrganization, req.params.id, req.jwt.person_id); + const isUpdateSuccessful = Organization.update(updateOrganization, req.params.id, req.jwt.person_id); if (isUpdateSuccessful) { return res.status(204).send(); } else { @@ -115,7 +115,7 @@ async function deleteOrganization(req, res) { errors: errors.array() }); } - const isDeleteSuccessful = await organizationModel.deleteOrganization(req.params.id, req.jwt.person_id); + const isDeleteSuccessful = await Organization.remove(req.params.id, req.jwt.person_id); if (isDeleteSuccessful) { return res.status(204).send(); } @@ -147,7 +147,7 @@ async function getOrganization(req, res) { errors: errors.array() }); } - const organization = await organizationModel.getOrganizationById(req.params.id); + const organization = await Organization.findById(req.params.id); if (organization) { return res.status(200).json(organization); } else {