mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
new func names
This commit is contained in:
@ -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
|
||||
};
|
@ -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
|
||||
};
|
@ -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');
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user