Skip to content

Commit

Permalink
feat: get frameworks endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinKruglov committed Jul 13, 2023
1 parent a01b22f commit c51fbc2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ routeInterruptionPages.route(app)
const routeIntroPages = require('./routeIntroPages')
routeIntroPages.route(app)

const frameworkRoutes = require('./routeFrameworks')
frameworkRoutes.route(app)

app.locals.db = require('./dbTree/db')({
connectionString: process.env.MONGO_READONLY,
docStatus: process.env.DOC_STATUS || 'LIVE'
Expand Down
35 changes: 35 additions & 0 deletions app/routeFrameworks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const route = (app) => {
const populateFrameworkReferences = (frameworks, categories, providers) => {
const populatedFrameworks = frameworks.map(f => {
if (f.cat) {
const matchingCategory = categories.filter(c => c._id.toString() === f.cat.toString())[0];
if (matchingCategory) {
f.cat = JSON.parse(JSON.stringify(matchingCategory));
delete f.cat._id;
}
}
if (f.provider) {
const matchingProvider = providers.filter(p => p._id.toString() === f.provider.toString())[0];
if (matchingProvider) {
f.provider = JSON.parse(JSON.stringify(matchingProvider));
delete f.provider._id;
}
}
delete f._id;
return f;
})
return populatedFrameworks;
};

app.get("/frameworks", (req, res, next) => {
const db = app.locals.db;
db.getRecord().then((doc) => {
populatedFrameworks = populateFrameworkReferences(doc.framework, doc.category, doc.provider);
res.send(populatedFrameworks);
});
});
};

module.exports = {
route
};

0 comments on commit c51fbc2

Please sign in to comment.