mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
beautified
This commit is contained in:
@ -19,11 +19,11 @@ const knex = require('../utils/knex_config');
|
||||
* @returns The Person's ID associated with the identifier if present,
|
||||
* null otherwise
|
||||
*/
|
||||
async function getPersonIdByIdentifier (identifier){
|
||||
async function getPersonIdByIdentifier(identifier) {
|
||||
const tuple = await knex('ActivationLink')
|
||||
.where('identifier', identifier)
|
||||
.first();
|
||||
if(tuple){
|
||||
if (tuple) {
|
||||
return tuple.person_id;
|
||||
}
|
||||
return null;
|
||||
|
@ -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 isPersonOrganizationAdministrator(personId, organizationId) {
|
||||
const isPersonAdmin = await knex('OrganizationAdministrator')
|
||||
.where('id_person', personId)
|
||||
.where('id_organization', organizationId)
|
||||
@ -36,15 +36,15 @@ async function isPersonOrganizationAdministrator (personId, organizationId) {
|
||||
* @param {*} organizationId
|
||||
* @param {*} requester Id of the person requesting the addition
|
||||
*/
|
||||
async function addOrganizationAdministrator (personId, organizationId, requester) {
|
||||
async function addOrganizationAdministrator(personId, organizationId, requester) {
|
||||
|
||||
const isPersonAdmin = await organization_admin_model.isPersonAdmin(requester, organizationId);
|
||||
if(isPersonAdmin){
|
||||
if (isPersonAdmin) {
|
||||
await knex('OrganizationAdministrator')
|
||||
.insert({
|
||||
id_person: personId,
|
||||
id_organization: organizationId
|
||||
});
|
||||
.insert({
|
||||
id_person: personId,
|
||||
id_organization: organizationId
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -56,7 +56,7 @@ async function addOrganizationAdministrator (personId, organizationId, requester
|
||||
* @param {*} personId
|
||||
* @param {*} organizationId
|
||||
*/
|
||||
async function removeOrganizationAdmin (personId, organizationId) {
|
||||
async function removeOrganizationAdmin(personId, organizationId) {
|
||||
const transaction = await knex.transaction();
|
||||
|
||||
// We lock the table to ensure that we won't have concurrency issues
|
||||
@ -71,7 +71,9 @@ async function removeOrganizationAdmin (personId, organizationId) {
|
||||
|
||||
// TODO: If the user instead deletes their entire profile, the organization will not be deleted. Fix. (database schema)
|
||||
const remainingAdministrators = await transaction('OrganizationAdministrator')
|
||||
.where({ id_organization: organizationId });
|
||||
.where({
|
||||
id_organization: organizationId
|
||||
});
|
||||
|
||||
if (remainingAdministrators.length === 0) {
|
||||
// If no more users, delete the organization
|
||||
@ -87,4 +89,4 @@ module.exports = {
|
||||
isPersonOrganizationAdministrator,
|
||||
addOrganizationAdministrator,
|
||||
removeOrganizationAdmin
|
||||
};
|
||||
};
|
@ -21,7 +21,7 @@ const knex = require('../utils/knex_config');
|
||||
* @param {*} isHiring
|
||||
* @returns
|
||||
*/
|
||||
function createOrganization (name, location, description, isHiring) {
|
||||
function createOrganization(name, location, description, isHiring) {
|
||||
const organization = {
|
||||
name: name,
|
||||
location: location,
|
||||
@ -36,7 +36,7 @@ function createOrganization (name, location, description, isHiring) {
|
||||
* @param {*} id
|
||||
* @returns the Organization
|
||||
*/
|
||||
async function getOrganizationById (id) {
|
||||
async function getOrganizationById(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 insertOrganization(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 updateOrganization(organization, organizationId, requester) {
|
||||
const numberOfUpdatedRows = await knex('Organization')
|
||||
.where('id', organizationId)
|
||||
.whereExists(function () {
|
||||
@ -96,9 +96,11 @@ 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 deleteOrganization(organizationId, requester) {
|
||||
const numberOfDeletedRows = await knex('Organization')
|
||||
.where({ id: organizationId })
|
||||
.where({
|
||||
id: organizationId
|
||||
})
|
||||
.whereExists(function () {
|
||||
this.select('*')
|
||||
.from('OrganizationAdministrator')
|
||||
@ -118,4 +120,4 @@ module.exports = {
|
||||
insertOrganization,
|
||||
updateOrganization,
|
||||
deleteOrganization
|
||||
};
|
||||
};
|
@ -19,7 +19,7 @@ const knex = require('../utils/knex_config');
|
||||
* @param {*} content
|
||||
* @param {*} originalAuthor
|
||||
*/
|
||||
function createOrganizationPost (organizationId, content, originalAuthor) {
|
||||
function createOrganizationPost(organizationId, content, originalAuthor) {
|
||||
const organizationPost = {
|
||||
organization_id: organizationId,
|
||||
content,
|
||||
@ -34,7 +34,7 @@ function createOrganizationPost (organizationId, content, originalAuthor) {
|
||||
* @param {*} organization
|
||||
* @returns the inserted OrganizationPost
|
||||
*/
|
||||
async function insertOrganizationPost (organization) {
|
||||
async function insertOrganizationPost(organization) {
|
||||
const isOrganizationAdmin = await knex('OrganizationAdministrator')
|
||||
.where('id_person', organization.original_author)
|
||||
.where('id_organization', organization.organization_id)
|
||||
@ -65,7 +65,7 @@ async function insertOrganizationPost (organization) {
|
||||
* @param {*} personId
|
||||
* @returns true or false
|
||||
*/
|
||||
async function isPersonPostAdministrator (postId, personId) {
|
||||
async function isPersonPostAdministrator(postId, personId) {
|
||||
return await knex('OrganizationPost')
|
||||
.join('OrganizationAdministrator', 'OrganizationPost.organization_id', 'OrganizationAdministrator.id_organization')
|
||||
.where('OrganizationPost.id', postId)
|
||||
@ -80,11 +80,11 @@ async function isPersonPostAdministrator (postId, personId) {
|
||||
* @param {*} postId Id of the Post to delete
|
||||
* @param {*} requester Id of the Person requesting the deletion
|
||||
*/
|
||||
async function deleteOrganizationPost (postId, requester) {
|
||||
if(await isPersonPostAdministrator(postId, requester)){
|
||||
async function deleteOrganizationPost(postId, requester) {
|
||||
if (await isPersonPostAdministrator(postId, requester)) {
|
||||
return await knex('OrganizationPost')
|
||||
.where('id', postId)
|
||||
.del() == 1;
|
||||
.where('id', postId)
|
||||
.del() == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -94,4 +94,4 @@ module.exports = {
|
||||
insertOrganizationPost,
|
||||
isPersonPostAdministrator,
|
||||
deleteOrganizationPost
|
||||
};
|
||||
};
|
@ -25,7 +25,7 @@ const bcrypt = require('bcrypt');
|
||||
* @param {*} placeOfLiving
|
||||
* @returns
|
||||
*/
|
||||
function createPerson (email, password, displayName, dateOfBirth, available, enabled, placeOfLiving, aboutMe, qualification) {
|
||||
function createPerson(email, password, displayName, dateOfBirth, available, enabled, placeOfLiving, aboutMe, qualification) {
|
||||
const person = {
|
||||
email: email.toLowerCase(),
|
||||
password,
|
||||
@ -45,7 +45,7 @@ function createPerson (email, password, displayName, dateOfBirth, available, ena
|
||||
* @param {*} email email to look the Person for
|
||||
* @returns the Person object
|
||||
*/
|
||||
async function getPersonByEmail (email) {
|
||||
async function getPersonByEmail(email) {
|
||||
return await knex('Person')
|
||||
.where('email', email.toLowerCase())
|
||||
.first();
|
||||
@ -56,10 +56,12 @@ async function getPersonByEmail (email) {
|
||||
* @param {*} id - The id to look the person for
|
||||
* @returns
|
||||
*/
|
||||
async function getPersonById (id) {
|
||||
async function getPersonById(id) {
|
||||
return await knex('Person')
|
||||
.select('*')
|
||||
.where({ id })
|
||||
.where({
|
||||
id
|
||||
})
|
||||
.first();
|
||||
}
|
||||
|
||||
@ -69,7 +71,7 @@ async function getPersonById (id) {
|
||||
* @param {*} person A Person object
|
||||
* @param {*} activationLink the activationLink identifier
|
||||
*/
|
||||
async function registerPerson (person, activationLink) {
|
||||
async function registerPerson(person, activationLink) {
|
||||
// We need to insert either both in the "Person" table
|
||||
// and in the "ActivationLink" one, or in neither
|
||||
await knex.transaction(async (tr) => {
|
||||
@ -91,7 +93,7 @@ async function registerPerson (person, activationLink) {
|
||||
* @param {*} password
|
||||
* @returns
|
||||
*/
|
||||
async function getPersonByEmailAndPassword (email, password) {
|
||||
async function getPersonByEmailAndPassword(email, password) {
|
||||
const person = await knex('Person')
|
||||
.where('email', email.toLowerCase())
|
||||
.where('enabled', true)
|
||||
@ -112,7 +114,7 @@ async function getPersonByEmailAndPassword (email, password) {
|
||||
* @param {*} person The Person to update
|
||||
* @param {*} person_id The database id of the Person to update
|
||||
*/
|
||||
async function updatePerson (person, person_id) {
|
||||
async function updatePerson(person, person_id) {
|
||||
await knex('Person')
|
||||
.where('id', person_id)
|
||||
.update(person);
|
||||
@ -122,21 +124,25 @@ async function updatePerson (person, person_id) {
|
||||
* Deletes a Person specified by its database id.
|
||||
* @param {*} person_id
|
||||
*/
|
||||
async function deletePerson (personId) {
|
||||
async function deletePerson(personId) {
|
||||
await knex('Person')
|
||||
.where({ id: personId })
|
||||
.where({
|
||||
id: personId
|
||||
})
|
||||
.del();
|
||||
}
|
||||
|
||||
async function confirmActivation (personId) {
|
||||
async function confirmActivation(personId) {
|
||||
await knex.transaction(async (tr) => {
|
||||
await knex('Person')
|
||||
.where('id', personId)
|
||||
.update({enabled: true});
|
||||
.where('id', personId)
|
||||
.update({
|
||||
enabled: true
|
||||
});
|
||||
|
||||
await tr('ActivationLink')
|
||||
.where('person_id', personId)
|
||||
.del();
|
||||
await tr('ActivationLink')
|
||||
.where('person_id', personId)
|
||||
.del();
|
||||
});
|
||||
|
||||
}
|
||||
@ -153,4 +159,4 @@ module.exports = {
|
||||
updatePerson,
|
||||
deletePerson,
|
||||
confirmActivation
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user