diff --git a/src/controllers/governance.controller.js b/src/controllers/governance.controller.js index 0c860052..615dd31e 100644 --- a/src/controllers/governance.controller.js +++ b/src/controllers/governance.controller.js @@ -9,6 +9,11 @@ import { assertCanBeGovernanceBody, } from '../utils/data-assertions'; +import { getConfig } from '../utils/config-loader'; +import glossaryStub from '../models/governance/glossary.stub.json'; + +const { CHIA_NETWORK } = getConfig().APP; + export const findAll = async (req, res) => { try { const results = await Governance.findAll(); @@ -70,6 +75,24 @@ export const findPickList = async (req, res) => { } }; +export const findGlossary = async (req, res) => { + try { + if (CHIA_NETWORK === 'testnet') { + return res.json(glossaryStub); + } + + const results = await Governance.findOne({ + where: { metaKey: 'glossary' }, + }); + return res.json(JSON.parse(_.get(results, 'metaValue', {}))); + } catch (error) { + res.status(400).json({ + message: 'Can not retreive Governance Data', + error: error.message, + }); + } +}; + // eslint-disable-next-line export const createGoveranceBody = async (req, res) => { try { @@ -161,4 +184,4 @@ export const setGlossary = async (req, res) => { error: error.message, }); } -}; \ No newline at end of file +}; diff --git a/src/models/governance/glossary.stub.json b/src/models/governance/glossary.stub.json new file mode 100644 index 00000000..d4c7e1aa --- /dev/null +++ b/src/models/governance/glossary.stub.json @@ -0,0 +1,61 @@ +{ + "Project Statuses": [ + "Listed; The project is listed in a registry and pending validation or registration", + "Validated; The project has been validated and is pending registration or other status", + "Registered; The project has been registered", + "Transitioned; The project has been transitioned from a previous registry (e.g. CDM) to a new registry or mechanism (e.g. Article 6.4)", + "Approved; The project has been approved to sell units on through voluntary market mechanism", + "Authorized; The project has been authorized to sell units with corresponding adjustment through a compliance market mechanism", + "Withdrawn; Request for requestration was withdrawn by the project proponent prior to registration", + "Deregistered; Project was deregistered after registration and is no longer active", + "Completed; The project has reached the end of its lifetime" + ], + "Covered By NDC Statuses": [ + "Inside NDC; The project (or resulting units) is from a sector, sub-sector, or activity listed in the Host Country's NDC as part of the NDC", + "Outside NDC; The project (or resulting units) is from a sector, sub-sector, or activity not listed in the Host Country's NDC as part of the NDC, or listed in the NDC as outside of the Host Country's NDC", + "Unknown; The relationship of the project (or resulting units) to the Host Country's NDC is not known" + ], + "Unit Metric": [ + "tCO2e; A metric indicating tonnes of carbon dioxide equivalent" + ], + "Rating Types": [ + "CDP; Project or Unit rating from the Carbon Disclosure Project (CDP)", + "CCQI; Project or Unit rating from the Carbon Credit Quality Initiative (CCQI)", + "MAAP; Project or Unit rating from the Mitigation Action Assessment Protocol (MAAP)", + "Sylvera; Project or Unit rating from Sylvera", + "BeZero; Project or Unit rating from BeZero" + ], + "Unit Types": [ + "Reduction - nature; Reduction of carbon dioxide equivalent relative to a defined Business-as-Usual scenario through a nature-based project", + "Reduction - technical; Reduction of carbon dioxide equivalent relative to a defined Business-as-Usual scenario through a technical project", + "Removal - nature; Removal of carbon dioxide equivalent from the atmosphere through a nature-based project", + "Removal - technical; Removal of carbon dioxide equivalent from the atmosphere through a technical project", + "Avoidance; Avoidance of greenhouse gas emissions relative to a defined Business-as-Usual scenario" + ], + "Unit Statuses": [ + "Held; Units are considered active on the current registry and are available to be transacted, cancelled, retired, or have another status applied", + "Retired; Units have been retired by the owner and cannot be transferred or sold", + "Cancelled; Units have been cancelled by the owner and cannot be transferred or sold", + "Expired; Units have expired", + "Buffer; Units are in a buffer account", + "Exported; Units have been transferred to another registry or account", + "Pending Export; Units are pending transfer to another regisry or account" + ], + "Corresponding Adjustment Declarations": [ + "Committed; The host country has committed to undertake a corresponding adjustment for these units", + "Not Required; No corresponding adjustment is required for this units", + "Unknown; The status of the corresponding adjustment is not known for these units" + ], + "Corresponding Adjustment Statuses": [ + "Not Started; The process for corresponding adjustment by the host country has not started", + "Pending; Corresponding adjustment by the host country is in process", + "Completed; Corresponding adjustment by the host country is complete" + ], + "Label Types": [ + "Endorsement; The unit or project is supported by an Endorsement", + "Letter of Qualification; The unit or project is supported by an Letter of Qualification", + "Certification; The unit or project is supported by a Certification", + "Letter of Authorization; Units are authorized for sale with corresponding adjustment", + "Letter of Approval; Units are approved for sale through a voluntary mechanism" + ] +} diff --git a/src/models/organizations/organizations.model.js b/src/models/organizations/organizations.model.js index 1456b0aa..fbe47c5a 100644 --- a/src/models/organizations/organizations.model.js +++ b/src/models/organizations/organizations.model.js @@ -308,7 +308,7 @@ class Organization extends Model { const onResult = (data) => { const updateData = data .filter( - ({ dataEntry }) => + (dataEntry) => dataEntry.key !== 'registryId' || !dataEntry.key.includes('meta_'), ) @@ -319,7 +319,7 @@ class Organization extends Model { // will return metadata fields. i.e.: { meta_key1: 'value1', meta_key2: 'value2' } const metadata = data - .filter(({ dataEntry }) => dataEntry.key.includes('meta_')) + .filter((dataEntry) => dataEntry.key.includes('meta_')) .reduce((update, current) => { update[current.key] = current.value; return update; diff --git a/src/routes/v1/resources/governance.js b/src/routes/v1/resources/governance.js index ec2eddaa..1a48a509 100644 --- a/src/routes/v1/resources/governance.js +++ b/src/routes/v1/resources/governance.js @@ -29,6 +29,10 @@ GovernanceRouter.get('/meta/pickList', (req, res) => { return GovernanceController.findPickList(req, res); }); +GovernanceRouter.get('/meta/glossary', (req, res) => { + return GovernanceController.findGlossary(req, res); +}); + GovernanceRouter.post('/', (req, res) => { return GovernanceController.createGoveranceBody(req, res); }); @@ -49,12 +53,9 @@ GovernanceRouter.post( }, ); -GovernanceRouter.post( - '/meta/glossary', - (req, res) => { - return GovernanceController.setGlossary(req, res); - }, -); +GovernanceRouter.post('/meta/glossary', (req, res) => { + return GovernanceController.setGlossary(req, res); +}); GovernanceRouter.post( '/subscribe',