mirror of
https://github.com/xfarrow/blink
synced 2025-02-16 08:00:35 +01:00
renaming
This commit is contained in:
parent
eb47953e3a
commit
c917358537
@ -20,7 +20,7 @@ const knex = require('../utils/knex_config');
|
||||
* @param {*} organizationId
|
||||
* @returns true if administrator, false otherwise
|
||||
*/
|
||||
async function isPersonAdmin (personId, organizationId) {
|
||||
async function isPersonOrganizationAdministrator (personId, organizationId) {
|
||||
const isPersonAdmin = await knex('OrganizationAdministrator')
|
||||
.where('id_person', personId)
|
||||
.where('id_organization', organizationId)
|
||||
@ -84,7 +84,7 @@ async function removeOrganizationAdmin (personId, organizationId) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isPersonAdmin,
|
||||
isPersonOrganizationAdministrator,
|
||||
addOrganizationAdministrator,
|
||||
removeOrganizationAdmin
|
||||
};
|
||||
|
@ -21,12 +21,12 @@ const knex = require('../utils/knex_config');
|
||||
* @param {*} isHiring
|
||||
* @returns
|
||||
*/
|
||||
function organization (name, location, description, isHiring) {
|
||||
function createOrganization (name, location, description, isHiring) {
|
||||
const organization = {
|
||||
name,
|
||||
location,
|
||||
description,
|
||||
isHiring
|
||||
name: name,
|
||||
location: location,
|
||||
description: description,
|
||||
is_hiring: isHiring
|
||||
};
|
||||
return organization;
|
||||
}
|
||||
@ -139,7 +139,7 @@ async function deleteOrganization (organizationId, requester) {
|
||||
// module available for use in another module.
|
||||
module.exports = {
|
||||
getOrganizationById,
|
||||
organization,
|
||||
createOrganization,
|
||||
insertOrganization,
|
||||
updateOrganization,
|
||||
deleteOrganization
|
||||
|
@ -19,7 +19,7 @@ const knex = require('../utils/knex_config');
|
||||
* @param {*} content
|
||||
* @param {*} originalAuthor
|
||||
*/
|
||||
function organizationPost (organizationId, content, originalAuthor) {
|
||||
function createOrganizationPost (organizationId, content, originalAuthor) {
|
||||
const organizationPost = {
|
||||
organization_id: organizationId,
|
||||
content,
|
||||
@ -90,7 +90,7 @@ async function deleteOrganizationPost (postId, requester) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
organizationPost,
|
||||
createOrganizationPost,
|
||||
insertOrganizationPost,
|
||||
isPersonPostAdministrator,
|
||||
deleteOrganizationPost
|
||||
|
@ -25,7 +25,7 @@ const bcrypt = require('bcrypt');
|
||||
* @param {*} place_of_living
|
||||
* @returns
|
||||
*/
|
||||
function person (email, password, display_name, date_of_birth, available, enabled, place_of_living) {
|
||||
function createPerson (email, password, display_name, date_of_birth, available, enabled, place_of_living) {
|
||||
const person = {
|
||||
email: email.toLowerCase(),
|
||||
password,
|
||||
@ -138,7 +138,7 @@ async function deletePerson (person_id) {
|
||||
// means making a JavaScript function defined in one
|
||||
// module available for use in another module.
|
||||
module.exports = {
|
||||
person,
|
||||
createPerson,
|
||||
getPersonByEmail,
|
||||
getPersonById,
|
||||
getPersonByEmailAndPassword,
|
||||
|
@ -11,7 +11,7 @@
|
||||
IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
const organization_admin_model = require('../models/organization_admin_model');
|
||||
const organizationAdminModel = require('../models/organization_admin_model');
|
||||
|
||||
/**
|
||||
* POST Method
|
||||
@ -28,7 +28,7 @@ async function addOrganizationAdmin (req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const success = await organization_admin_model.addOrganizationAdministrator(req.body.person_id, req.body.organization_id, req.jwt.person_id);
|
||||
const success = await organizationAdminModel.addOrganizationAdministrator(req.body.person_id, req.body.organization_id, req.jwt.person_id);
|
||||
if(success){
|
||||
return res.status(200).json({ success: true });
|
||||
}
|
||||
@ -55,7 +55,7 @@ async function removeOrganizationAdmin (req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
await organization_admin_model.removeOrganizationAdmin(req.jwt.person_id, req.body.organization_id);
|
||||
await organizationAdminModel.removeOrganizationAdmin(req.jwt.person_id, req.body.organization_id);
|
||||
return res.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${removeOrganizationAdmin.name}: ${error}`);
|
||||
|
@ -27,7 +27,7 @@ async function createOrganizationPost (req, res) {
|
||||
return res.status(400).json({ error: 'Invalid request' });
|
||||
}
|
||||
|
||||
const organization = organizationPostModel.organizationPost(
|
||||
const organization = organizationPostModel.createOrganizationPost(
|
||||
req.body.organization_id,
|
||||
req.body.content,
|
||||
req.jwt.person_id);
|
||||
|
@ -11,7 +11,7 @@
|
||||
IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
const organization_model = require('../models/organization_model');
|
||||
const organizationModel = require('../models/organization_model');
|
||||
|
||||
/**
|
||||
* POST Request
|
||||
@ -29,8 +29,8 @@ async function createOrganization (req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const organization = organization_model.organization(req.body.name, req.body.location, req.body.description, req.body.is_hiring);
|
||||
await organization_model.insertOrganization(organization, req.jwt.person_id);
|
||||
const organization = organizationModel.createOrganization(req.body.name, req.body.location, req.body.description, req.body.is_hiring);
|
||||
await organizationModel.insertOrganization(organization, req.jwt.person_id);
|
||||
return res.status(200).json({ Organization: organization });
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${createOrganization.name}: ${error}`);
|
||||
@ -68,7 +68,7 @@ async function updateOrganization (req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const isUpdateSuccessful = organization_model.updateOrganization(updateOrganization, req.params.id, req.jwt.person_id);
|
||||
const isUpdateSuccessful = organizationModel.updateOrganization(updateOrganization, req.params.id, req.jwt.person_id);
|
||||
if (isUpdateSuccessful) {
|
||||
return res.status(200).json({ success: 'true' });
|
||||
} else {
|
||||
@ -88,7 +88,7 @@ async function updateOrganization (req, res) {
|
||||
*/
|
||||
async function deleteOrganization (req, res) {
|
||||
try {
|
||||
const isDeleteSuccessful = organization_model.deleteOrganization(req.params.id, req.jwt.person_id);
|
||||
const isDeleteSuccessful = organizationModel.deleteOrganization(req.params.id, req.jwt.person_id);
|
||||
if (isDeleteSuccessful) {
|
||||
return res.status(200).json({ success: true });
|
||||
}
|
||||
@ -110,7 +110,7 @@ async function deleteOrganization (req, res) {
|
||||
*/
|
||||
async function getOrganization (req, res) {
|
||||
try {
|
||||
const organization = await organization_model.getOrganizationById(req.params.id);
|
||||
const organization = await organizationModel.getOrganizationById(req.params.id);
|
||||
if (organization) {
|
||||
return res.status(200).json(organization);
|
||||
} else {
|
||||
|
@ -12,11 +12,10 @@
|
||||
*/
|
||||
|
||||
const validator = require('../utils/validation');
|
||||
const knex = require('../utils/knex_config');
|
||||
const jwt_utils = require('../utils/middleware_utils');
|
||||
const jwtUtils = require('../utils/middleware_utils');
|
||||
const bcrypt = require('bcrypt');
|
||||
const crypto = require('crypto');
|
||||
const person_model = require('../models/person_model');
|
||||
const personModel = require('../models/person_model');
|
||||
|
||||
/**
|
||||
* POST Request
|
||||
@ -47,11 +46,11 @@ async function registerPerson (req, res) {
|
||||
|
||||
try {
|
||||
// Check whether e-mail exists already (enforced by database constraints)
|
||||
const existingUser = await person_model.getPersonByEmail(req.body.email);
|
||||
const existingUser = await personModel.getPersonByEmail(req.body.email);
|
||||
if (existingUser) {
|
||||
return res.status(409).json({ error: 'E-mail already in use' });
|
||||
}
|
||||
const personToInsert = person_model.person(
|
||||
const personToInsert = personModel.createPerson(
|
||||
req.body.email,
|
||||
await hashPasswordPromise,
|
||||
req.body.display_name,
|
||||
@ -59,7 +58,7 @@ async function registerPerson (req, res) {
|
||||
req.body.available,
|
||||
true,
|
||||
req.body.place_of_living);
|
||||
await person_model.registerPerson(personToInsert, activationLink);
|
||||
await personModel.registerPerson(personToInsert, activationLink);
|
||||
return res.status(200).json({ activationLink });
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${console.trace()}: ${error}`);
|
||||
@ -84,9 +83,9 @@ async function login (req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const person = await person_model.getPersonByEmailAndPassword(req.body.email, req.body.password);
|
||||
const person = await personModel.getPersonByEmailAndPassword(req.body.email, req.body.password);
|
||||
if (person) {
|
||||
const token = jwt_utils.generateToken(person.id);
|
||||
const token = jwtUtils.generateToken(person.id);
|
||||
res.status(200).json({ token });
|
||||
} else {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
@ -108,7 +107,7 @@ async function login (req, res) {
|
||||
*/
|
||||
async function getPerson (req, res) {
|
||||
try {
|
||||
const person = await person_model.getPersonById(req.params.id);
|
||||
const person = await personModel.getPersonById(req.params.id);
|
||||
if (person) {
|
||||
// I am retrieving either myself or an enabled user
|
||||
if (person.id == req.jwt.person_id || person.enabled) {
|
||||
@ -133,7 +132,7 @@ async function getPerson (req, res) {
|
||||
*/
|
||||
async function getMyself (req, res) {
|
||||
try {
|
||||
const person = await person_model.getPersonById(req.jwt.person_id);
|
||||
const person = await personModel.getPersonById(req.jwt.person_id);
|
||||
if (person) {
|
||||
delete person.password;
|
||||
return res.status(200).send(person);
|
||||
@ -184,10 +183,7 @@ async function updatePerson (req, res) {
|
||||
|
||||
// If we are tying to change password, the old password must be provided
|
||||
if (req.body.old_password && req.body.new_password) {
|
||||
const user = await knex('Person')
|
||||
.select('password')
|
||||
.where({ id: req.jwt.person_id })
|
||||
.first();
|
||||
const user = await personModel.getPersonById(req.jwt.person_id);
|
||||
const passwordMatches = await bcrypt.compare(req.body.old_password, user.password);
|
||||
if (passwordMatches) {
|
||||
updatePerson.password = await bcrypt.hash(req.body.new_password, 10);
|
||||
@ -201,7 +197,7 @@ async function updatePerson (req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
await person_model.updatePerson(updatePerson, req.params.id);
|
||||
await personModel.updatePerson(updatePerson, req.params.id);
|
||||
return res.status(200).json({ success: 'true' });
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${updatePerson.name}: ${error}`);
|
||||
@ -221,7 +217,7 @@ async function updatePerson (req, res) {
|
||||
async function deletePerson (req, res) {
|
||||
// TODO: Delete Organization if this user was its only administrator
|
||||
try {
|
||||
await person_model.deletePerson(req.jwt.person_id);
|
||||
await personModel.deletePerson(req.jwt.person_id);
|
||||
return res.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
console.error(`Error in function ${deletePerson.name}: ${error}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user