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