From 4c630815b1b6980a7df0ceeebad8d02f75f8f080 Mon Sep 17 00:00:00 2001 From: Frantz Arty Date: Thu, 21 Apr 2022 08:31:06 -0400 Subject: [PATCH] feat: governance getters --- src/controllers/governance.controller.js | 28 ++++++++++++++++++++++++ src/routes/v1/resources/governance.js | 8 +++++++ 2 files changed, 36 insertions(+) diff --git a/src/controllers/governance.controller.js b/src/controllers/governance.controller.js index 3a463608..904a285c 100644 --- a/src/controllers/governance.controller.js +++ b/src/controllers/governance.controller.js @@ -1,3 +1,5 @@ +import _ from 'lodash'; + import { Governance } from '../models'; import { @@ -21,6 +23,32 @@ export const findAll = async (req, res) => { } }; +export const findOrgList = async (req, res) => { + try { + const results = await Governance.findOne({ where: { metaKey: 'orgList' } }); + return res.json(JSON.parse(_.get(results, 'metaValue', {}))); + } catch (error) { + res.status(400).json({ + message: 'Can not retreive Governance Data', + error: error.message, + }); + } +}; + +export const findPickList = async (req, res) => { + try { + const results = await Governance.findOne({ + where: { metaKey: 'pickList' }, + }); + 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 { diff --git a/src/routes/v1/resources/governance.js b/src/routes/v1/resources/governance.js index 11868ce4..a9594e3f 100644 --- a/src/routes/v1/resources/governance.js +++ b/src/routes/v1/resources/governance.js @@ -17,6 +17,14 @@ GovernanceRouter.get('/', (req, res) => { return GovernanceController.findAll(req, res); }); +GovernanceRouter.get('/meta/orgList', (req, res) => { + return GovernanceController.findOrgList(req, res); +}); + +GovernanceRouter.get('/meta/pickList', (req, res) => { + return GovernanceController.findPickList(req, res); +}); + GovernanceRouter.post('/', (req, res) => { return GovernanceController.createGoveranceBody(req, res); });