-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from IntersectMBO/dynamically-filter-ga-type-…
…list-based-on-protocol-major Dynamically filter qa type list based on protocol_major
- Loading branch information
Showing
1 changed file
with
56 additions
and
3 deletions.
There are no files selected for viewing
59 changes: 56 additions & 3 deletions
59
backend/src/api/governance-action-type/controllers/governance-action-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,62 @@ | ||
'use strict'; | ||
// @ts-nocheck | ||
"use strict"; | ||
|
||
/** | ||
* governance-action-type controller | ||
*/ | ||
|
||
const { createCoreController } = require('@strapi/strapi').factories; | ||
const axios = require("axios"); | ||
const { createCoreController } = require("@strapi/strapi").factories; | ||
|
||
module.exports = createCoreController('api::governance-action-type.governance-action-type'); | ||
module.exports = createCoreController( | ||
"api::governance-action-type.governance-action-type", | ||
({ strapi }) => ({ | ||
async find(ctx) { | ||
const sanitizedQueryParams = await this.sanitizeQuery(ctx); | ||
|
||
try { | ||
const { data } = await axios.get( | ||
`${process.env.GOVTOOL_API_BASE_URL}/epoch/params` | ||
); | ||
|
||
if (data) { | ||
if (!sanitizedQueryParams.filters) { | ||
sanitizedQueryParams.filters = {}; | ||
} | ||
|
||
if (+data?.protocol_major < 9) { | ||
sanitizedQueryParams.filters = { | ||
...sanitizedQueryParams.filters, | ||
$and: [ | ||
{ | ||
gov_action_type_name: { | ||
$ne: "Treasury", | ||
}, | ||
}, | ||
{ | ||
gov_action_type_name: { | ||
$ne: "Info", | ||
}, | ||
}, | ||
], | ||
}; | ||
} | ||
if (+data?.protocol_major === 9) { | ||
sanitizedQueryParams.filters = { | ||
...sanitizedQueryParams.filters, | ||
gov_action_type_name: { | ||
$ne: "Treasury", | ||
}, | ||
}; | ||
} | ||
} | ||
} catch (error) {} | ||
|
||
const { results, pagination } = await strapi | ||
.service("api::governance-action-type.governance-action-type") | ||
.find(sanitizedQueryParams); | ||
|
||
return this.transformResponse(results, { pagination }); | ||
}, | ||
}) | ||
); |