Skip to content

Commit

Permalink
fix: lint errors and remove commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Apr 10, 2022
1 parent f4d91a4 commit ffb193b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 217 deletions.
19 changes: 0 additions & 19 deletions server/handlers/stakeholderHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@ const {
deleteStakeholder,
updateStakeholder,
getRelations,
// getNonRelations,
createRelation,
deleteRelation,
} = require('../models/Stakeholder');
// const { dispatch } = require('../models/DomainEvent');

const Session = require('../models/Session');
// const { publishMessage } = require('../infra/messaging/RabbitMQMessaging');

const StakeholderRepository = require('../repositories/StakeholderRepository');

const stakeholderGetQuerySchema = Joi.object({
id: Joi.string().uuid(),
// organization_id: Joi.number().integer(),
// owner_id: Joi.string().uuid(),
// limit: Joi.number().integer().greater(0).less(101),
// offset: Joi.number().integer().greater(-1),
type: Joi.string(),
logo_url: Joi.string(),
org_name: Joi.string(),
Expand Down Expand Up @@ -93,11 +86,9 @@ const stakeholderGetAllById = async function (req, res, next) {

const stakeholderGetRelations = async function (req, res, next) {
const { id } = req.params;
// const { isRelation = true, org_id = null } = req.query;
const session = new Session(false);
const repo = new StakeholderRepository(session);

// if (isRelation !== 'false') {
const executeGetRelations = getRelations(repo, id);
try {
const result = await executeGetRelations();
Expand All @@ -106,16 +97,6 @@ const stakeholderGetRelations = async function (req, res, next) {
} catch (e) {
next(e);
}
// } else {
// const executeGetNonRelations = getNonRelations(repo, id);
// try {
// const result = await executeGetNonRelations(org_id);
// res.send(result);
// res.end();
// } catch (e) {
// next(e);
// }
// }
};

const stakeholderCreateRelation = async function (req, res, next) {
Expand Down
110 changes: 15 additions & 95 deletions server/models/Stakeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ const StakeholderPostObject = ({
website,
logo_url,
map,
// pwd_reset_required,
// password,
// wallet,
// salt,
// active_contract_id,
// offering_pay_to_plant,
// tree_validation_contract_id,
// organization_id,
// owner_id,
}) => {
return Object.freeze({
id: uuidv4(), // give it a uuid,
Expand All @@ -33,15 +24,6 @@ const StakeholderPostObject = ({
website,
logo_url,
map,
// pwd_reset_required: pwd_reset_required || false,
// password,
// wallet,
// salt,
// active_contract_id: active_contract_id || null,
// offering_pay_to_plant,
// tree_validation_contract_id: tree_validation_contract_id || null,
// organization_id,
// owner_id,
});
};

Expand Down Expand Up @@ -95,8 +77,6 @@ const StakeholderTree = ({

const FilterCriteria = ({
id = null,
// owner_id = null,
// organization_id = null,
type = null,
org_name = null,
first_name = null,
Expand All @@ -111,8 +91,6 @@ const FilterCriteria = ({
}) => {
return Object.entries({
id,
// owner_id,
// organization_id,
type,
org_name,
first_name,
Expand Down Expand Up @@ -165,20 +143,8 @@ const makeNextPrevUrls = (url, filter, options) => {
};

const createRelation = (repo, org_id) => async (stakeholder) => {
// eslint-disable-next-line no-use-before-define
const id = await getUUID(repo, org_id);

// check both stakeholders exist
// const current = await repo.getById(id);
// const newRelation = await repo.getById(stakeholder.data.id);

// confirm there's permission to create
// note: owners should have their own id as owner_id
// if (
// newRelation.owner_id === id ||
// current.owner_id === newRelation.owner_id ||
// id === null ||
// newRelation.owner_id === null
// ) {
const { type, data } = stakeholder;
const insertObj = {};

Expand All @@ -191,10 +157,6 @@ const createRelation = (repo, org_id) => async (stakeholder) => {
const stakeholderRelation = await repo.createRelation(insertObj);

return stakeholderRelation;
// }
// throw new Error({
// message: "Whoops! That stakeholder link can't be updated, no permission",
// });
};

async function getUUIDbyId(repo, id, options = { limit: 100, offset: 0 }) {
Expand Down Expand Up @@ -379,7 +341,6 @@ const getAllStakeholdersById =
};

const getRelations = (repo, current_id) => async () => {
// const id = await getUUID(repo, org_id);
const { stakeholders, count } = await repo.getRelations(current_id);

return {
Expand All @@ -394,6 +355,7 @@ const getRelations = (repo, current_id) => async () => {
};
};

// SAVE IN CASE WE NEED TO ADD AGAIN
// const getNonRelations = (repo, current_id) => async (org_id) => {
// const id = await getUUID(repo, org_id);
// const { stakeholders, count } = await repo.getNonRelations(current_id, id);
Expand All @@ -412,24 +374,6 @@ const getRelations = (repo, current_id) => async () => {

const deleteRelation = (repo, current_id) => async (stakeholder) => {
const id = await getUUID(repo, current_id);

// get relations for owner
// const relatedStakeholders = await repo.getRelatedIds(id);

// check both stakeholders exist
// const current = await repo.getById(id);
// const delRelation = await repo.getById(stakeholder.data.id);

// confirm there's permission to delete
// note: owners should have their own id as owner_id
// if (
// relatedStakeholders.includes(delRelation.id) &&
// (delRelation.owner_id === id ||
// current.owner_id === delRelation.owner_id ||
// id === null ||
// delRelation.owner_id === null ||
// current.owner_id === null)
// ) {
const { type, data } = stakeholder;
const removeObj = {};

Expand All @@ -441,60 +385,36 @@ const deleteRelation = (repo, current_id) => async (stakeholder) => {
const stakeholderRelation = await repo.deleteRelation(removeObj);

return stakeholderRelation;
// }
// throw new Error(
// "Whoops! That stakeholder link can't be updated, no permission",
// );
};

const updateStakeholder =
(repo, org_id = null) =>
async (data) => {
// const id = await getUUID(repo, org_id);
const editedStakeholder = StakeholderTree({ ...data });
// const relatedStakeholders = await repo.getRelatedIds(id);
// const foundStakeholder = await repo.getById(editedStakeholder.id);

// confirm they have right to edit
// if (
// (id && relatedStakeholders.includes(editedStakeholder.id)) ||
// foundStakeholder.owner_id === id ||
// id === null
// ) {
// remove children and parents temporarily to update
const { children, parents, ...updateObj } = editedStakeholder;
const stakeholder = await repo.updateStakeholder(updateObj);

return StakeholderTree({ ...stakeholder, children, parents });
// }
// throw new Error({
// message: "Whoops! That stakeholder can't be edited, no permission",
// });
};
const updateStakeholder = (repo) => async (data) => {
const editedStakeholder = StakeholderTree({ ...data });

// remove children and parents temporarily to update
const { children, parents, ...updateObj } = editedStakeholder;
const stakeholder = await repo.updateStakeholder(updateObj);

return StakeholderTree({ ...stakeholder, children, parents });
};

const createStakeholder =
(repo, org_id = null) =>
async (newStakeholder) => {
const id = await getUUID(repo, org_id);
const stakeholderObj = StakeholderPostObject({
...newStakeholder,
// organization_id: orgId || id, // to prevent it from being 0
// owner_id: id,
});

const stakeholder = await repo.createStakeholder(stakeholderObj, id);

return StakeholderTree({ ...stakeholder });
};

const deleteStakeholder =
(repo, org_id = null) =>
async (removeStakeholder) => {
const id = await getUUID(repo, org_id);
const stakeholder = await repo.deleteStakeholder(removeStakeholder);
const deleteStakeholder = (repo) => async (removeStakeholder) => {
const stakeholder = await repo.deleteStakeholder(removeStakeholder);

return StakeholderTree({ ...stakeholder });
};
return StakeholderTree({ ...stakeholder });
};

module.exports = {
getAllStakeholdersById,
Expand Down
Loading

0 comments on commit ffb193b

Please sign in to comment.