Skip to content

Commit

Permalink
Merge pull request #103 from IntersectMBO/dynamically-filter-ga-type-…
Browse files Browse the repository at this point in the history
…list-based-on-protocol-major

Dynamically filter qa type list based on protocol_major
  • Loading branch information
Nemanzh authored Aug 15, 2024
2 parents e879b57 + 5d5a055 commit b757633
Showing 1 changed file with 56 additions and 3 deletions.
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 });
},
})
);

0 comments on commit b757633

Please sign in to comment.