Skip to content

Commit

Permalink
Dynamically filter qa type list based on protocol_major
Browse files Browse the repository at this point in the history
  • Loading branch information
teske00 committed Aug 15, 2024
1 parent e879b57 commit 5d5a055
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 5d5a055

Please sign in to comment.