From a7673246c28fde7bcb0a21e7d93d8ffcd05118ac Mon Sep 17 00:00:00 2001 From: Gwynn DP Date: Mon, 4 Apr 2022 11:08:33 -0700 Subject: [PATCH] refactor: remove cols that aren't in the database --- api-tests/stakeholder-api.spec.js | 8 +- docs/api/spec/stakeholder.yaml | 31 ++-- .../spec/treetracker-stakeholders-api.yaml | 8 +- server/handlers/stakeholderHandler.js | 4 +- server/models/Stakeholder.js | 148 ++++++------------ server/models/Stakeholder.spec.js | 6 +- server/routes.js | 34 ---- 7 files changed, 78 insertions(+), 161 deletions(-) diff --git a/api-tests/stakeholder-api.spec.js b/api-tests/stakeholder-api.spec.js index 95d81ff..d19d216 100644 --- a/api-tests/stakeholder-api.spec.js +++ b/api-tests/stakeholder-api.spec.js @@ -98,9 +98,7 @@ describe.skip('Stakeholder API tests.', () => { .expect(422) .end(function (err, res) { // console.log('res.body.message ----------> ', res.body); - expect(res.body.message).to.eql( - '"id" must be a valid GUID', - ); + expect(res.body.message).to.eql('"id" must be a valid GUID'); if (err) return done(err); return done(); }); @@ -171,7 +169,7 @@ describe.skip('Stakeholder API tests.', () => { 'wallet', 'password', 'salt', - 'active_contract_id', + // 'active_contract_id', 'offering_pay_to_plant', 'tree_validation_contract_id', 'logo_url', @@ -179,7 +177,7 @@ describe.skip('Stakeholder API tests.', () => { 'organization_id', 'owner_id', 'children', - 'parents' + 'parents', ]); } diff --git a/docs/api/spec/stakeholder.yaml b/docs/api/spec/stakeholder.yaml index 1fa084a..9e0a997 100644 --- a/docs/api/spec/stakeholder.yaml +++ b/docs/api/spec/stakeholder.yaml @@ -198,7 +198,7 @@ paths: description: get all Organization and Person entities that could possibly be linked to the stakeholder as children, parents # growers and users to be added soon parameters: - # NOT IMPLEMENTED YET + # NOT IMPLEMENTED YET # - in: query # name: search # description: pass an optional search term for partial match on any part of a name field, phone number, email, etc. @@ -421,7 +421,7 @@ components: - wallet - salt - offering_pay_to_plant - - active_contract_id + # - active_contract_id - tree_validation_contract_id - website - logo_url @@ -481,10 +481,10 @@ components: type: boolean format: boolean example: false - active_contract_id: - type: string - format: uuid - example: '792a4eee-8e18-4750-a56f-91bdec383aa6' + # active_contract_id: + # type: string + # format: uuid + # example: '792a4eee-8e18-4750-a56f-91bdec383aa6' tree_validation_contract_id: type: string format: uuid @@ -537,8 +537,7 @@ components: format: json items: $ref: '#/components/schemas/Stakeholder' - example: - [ + example: [ { id: '1a05ec87-3c38-4395-b9f3-aa15becedc31', type: 'Organization', @@ -552,7 +551,7 @@ components: wallet: null, salt: null, offering_pay_to_plant: null, - active_contract_id: null, + # active_contract_id: null, tree_validation_contract_id: null, website: 'childone.com', logo_url: './logo_192x192.png', @@ -573,7 +572,7 @@ components: wallet: null, salt: null, offering_pay_to_plant: null, - active_contract_id: null, + # active_contract_id: null, tree_validation_contract_id: null, website: 'childtwo.com', logo_url: './logo_192x192.png', @@ -587,8 +586,7 @@ components: format: json items: $ref: '#/components/schemas/Stakeholder' - example: - [ + example: [ { id: '792a4eee-8e18-4750-a56f-91bdec383aa6', type: 'Organization', @@ -602,7 +600,7 @@ components: wallet: null, salt: null, offering_pay_to_plant: null, - active_contract_id: null, + # active_contract_id: null, tree_validation_contract_id: null, website: 'greenstand', logo_url: './logo_192x192.png', @@ -616,8 +614,7 @@ components: format: json items: $ref: '#/components/schemas/Stakeholder' - example: - [ + example: [ { id: '35a23de8-f1ab-4409-be79-3c6a158d5bde', type: 'Person', @@ -631,7 +628,7 @@ components: wallet: null, salt: null, offering_pay_to_plant: null, - active_contract_id: null, + # active_contract_id: null, tree_validation_contract_id: null, website: '', logo_url: './person_192x192.png', @@ -652,7 +649,7 @@ components: wallet: null, salt: null, offering_pay_to_plant: null, - active_contract_id: null, + # active_contract_id: null, tree_validation_contract_id: null, website: '', logo_url: './person_192x192.png', diff --git a/docs/api/spec/treetracker-stakeholders-api.yaml b/docs/api/spec/treetracker-stakeholders-api.yaml index 662318f..f25e308 100644 --- a/docs/api/spec/treetracker-stakeholders-api.yaml +++ b/docs/api/spec/treetracker-stakeholders-api.yaml @@ -58,7 +58,7 @@ paths: wallet: 'wallet.com' password: 'password' salt: 'salt' - active_contract_id: 1 + # active_contract_id: 1 offering_pay_to_plant: false tree_validation_contract_id: 1 logo_url: 'logo_url' @@ -101,9 +101,9 @@ paths: type: string salt: type: string - active_contract_id: - type: number - format: integer + # active_contract_id: + # type: number + # format: integer offering_pay_to_plant: type: boolean tree_validation_contract_id: diff --git a/server/handlers/stakeholderHandler.js b/server/handlers/stakeholderHandler.js index bb7f3ed..d890d9b 100644 --- a/server/handlers/stakeholderHandler.js +++ b/server/handlers/stakeholderHandler.js @@ -20,8 +20,8 @@ const StakeholderRepository = require('../repositories/StakeholderRepository'); const stakeholderGetQuerySchema = Joi.object({ id: Joi.string().uuid(), - organization_id: Joi.number().integer(), - owner_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(), diff --git a/server/models/Stakeholder.js b/server/models/Stakeholder.js index c2f1730..199cafc 100644 --- a/server/models/Stakeholder.js +++ b/server/models/Stakeholder.js @@ -9,18 +9,18 @@ const StakeholderPostObject = ({ last_name, email, phone, - pwd_reset_required, - password, - wallet, - salt, - active_contract_id, - offering_pay_to_plant, - tree_validation_contract_id, website, logo_url, map, - organization_id, - owner_id, + // 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, @@ -30,117 +30,73 @@ const StakeholderPostObject = ({ last_name, email, phone, - 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, website, logo_url, map, - organization_id, - owner_id, + // 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, }); }; const StakeholderTree = ({ id, - organization_id, - owner_id, type, org_name, first_name, last_name, email, phone, - pwd_reset_required, - password, - wallet, - salt, - active_contract_id, - offering_pay_to_plant, - tree_validation_contract_id, 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, children = [], parents = [], }) => { return Object.freeze({ id, - organization_id, - owner_id, type, org_name, first_name, last_name, email, phone, - pwd_reset_required, - password, - wallet, - salt, - active_contract_id, - offering_pay_to_plant, - tree_validation_contract_id, 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, children, parents, }); }; -// const Stakeholder = ({ -// id, -// organization_id, -// owner_id, -// type, -// org_name, -// first_name, -// last_name, -// email, -// phone, -// pwd_reset_required, -// password, -// wallet, -// salt, -// active_contract_id, -// offering_pay_to_plant, -// tree_validation_contract_id, -// website, -// logo_url, -// map, -// }) => { -// return Object.freeze({ -// id, -// organization_id, -// owner_id, -// type, -// org_name, -// first_name, -// last_name, -// email, -// phone, -// pwd_reset_required, -// password, -// wallet, -// salt, -// active_contract_id, -// offering_pay_to_plant, -// tree_validation_contract_id, -// website, -// logo_url, -// map, -// }); -// }; - const FilterCriteria = ({ id = null, - owner_id = null, - organization_id = null, + // owner_id = null, + // organization_id = null, type = null, org_name = null, first_name = null, @@ -154,8 +110,8 @@ const FilterCriteria = ({ }) => { return Object.entries({ id, - owner_id, - organization_id, + // owner_id, + // organization_id, type, org_name, first_name, @@ -224,24 +180,24 @@ const getUUID = async (repo, id, options = { limit: 100, offset: 0 }) => { // map from entity fields to stakeholder fields const stakeholderObj = { id: entity.stakeholder_uuid, - organization_id: id, - owner_id, type: entity.type, org_name: entity.name, first_name: entity.first_name, last_name: entity.last_name, email: entity.email, phone: entity.phone, - pwd_reset_required: entity.pwd_reset_required, - password: entity.password, - wallet: entity.wallet, - salt: entity.salt, - active_contract_id: entity.active_contract_id, - offering_pay_to_plant: entity.offering_pay_to_plant, - tree_validation_contract_id: entity.tree_validation_contract_id, - website: entity.website, logo_url: entity.logo_url, map: entity.map, + website: entity.website, + // pwd_reset_required: entity.pwd_reset_required, + // password: entity.password, + // wallet: entity.wallet, + // salt: entity.salt, + // active_contract_id: entity.active_contract_id, + // offering_pay_to_plant: entity.offering_pay_to_plant, + // tree_validation_contract_id: entity.tree_validation_contract_id, + // organization_id: id, + // owner_id, }; const stakeholder = await repo.createStakeholder(stakeholderObj); @@ -568,7 +524,7 @@ const createStakeholder = const stakeholderObj = StakeholderPostObject({ ...newStakeholder, - organization_id: orgId || id, // to prevent it from being 0 + // organization_id: orgId || id, // to prevent it from being 0 owner_id: id, }); @@ -587,5 +543,5 @@ module.exports = { createRelation, deleteRelation, StakeholderTree, - FilterCriteria + FilterCriteria, }; diff --git a/server/models/Stakeholder.spec.js b/server/models/Stakeholder.spec.js index 513d74b..42a387e 100644 --- a/server/models/Stakeholder.spec.js +++ b/server/models/Stakeholder.spec.js @@ -22,15 +22,15 @@ describe('Stakeholder Model', () => { 'wallet', 'password', 'salt', - 'active_contract_id', - 'offering_pay_to_plant', + // 'active_contract_id', + // 'offering_pay_to_plant', 'tree_validation_contract_id', 'logo_url', 'map', 'owner_id', 'organization_id', 'parents', - 'children' + 'children', ]); }); diff --git a/server/routes.js b/server/routes.js index d0406a8..25f6ecb 100644 --- a/server/routes.js +++ b/server/routes.js @@ -1,38 +1,4 @@ const router = require('express').Router(); -// const uuid = require('uuid'); -// const log = require('loglevel'); - -// const validateRequest = (req, res, next) => { -// console.log('QUERY -------> ', req.query); - -// if(req.query.limit && !Number.isInteger(+req.query.limit)) { -// // throw new Error('"limit" must be an integer'); -// next({ status: 422, message: '"limit" must be an integer' }); -// } -// if (req.query.limit && +req.query.limit < 1) { -// next({ status: 422, message: '"limit" must be greater than 0' }); -// } -// if (req.query.limit && +req.query.limit > 100) { -// next({ status: 422, message: '"limit" must be less than 101' }); -// } -// if (req.query.offset && !Number.isInteger(+req.query.offset)) { -// next({ status: 422, message: '"offset" must be an integer' }); -// } -// if (req.query.offset && +req.query.offset < 0) { -// next({ status: 422, message: '"offset" must be greater than -1' }); -// } -// if (req.query.id && !uuid.validate(req.query.id)) { -// next({ status: 422, message: '"id" must be a valid GUID' }); -// } -// if (req.query.owner_id && !uuid.validate(req.query.owner_id)) { -// next({ status: 422, message: '"id" must be a valid GUID' }); -// } -// if(req.query.organization_id && !Number.isInteger(+req.query.organization_id)) { -// next({ status: 422, message: '"organization_id" must be an integer' }); -// } - -// next(); -// }; const { stakeholderGetAllById,