Skip to content

Commit

Permalink
Merge pull request #51 from IntersectMBO/qa
Browse files Browse the repository at this point in the history
From QA to PreProd backend
  • Loading branch information
nebojsact authored Dec 5, 2024
2 parents e5f0eaf + d5fc225 commit 907d64a
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions backend/src/api/proposal/controllers/proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
/**
* proposal controller
*/
const {Address,RewardAddress} = require("@emurgo/cardano-serialization-lib-nodejs");

const { createCoreController } = require("@strapi/strapi").factories;

const { createCoreController } = require("@strapi/strapi").factories;
async function isRewardAddress(address) {
try {
const stake = RewardAddress.from_address(Address.from_bech32(address));
return stake ? true : false;
} catch (e) {
return false;
}
}
module.exports = createCoreController(
"api::proposal.proposal",
({ strapi }) => ({
Expand All @@ -22,7 +31,7 @@ module.exports = createCoreController(
}

/////GOV ACTION TYPE///////////
const hasGovActionTypeIDFilter = ctx?.query?.filters["$and"]?.find(
const hasGovActionTypeIDFilter = sanitizedQueryParams.filters["$and"]?.find(
(elem) => elem?.hasOwnProperty("gov_action_type_id")
);

Expand Down Expand Up @@ -255,8 +264,24 @@ module.exports = createCoreController(
return ctx.badRequest(null, "Proposal content not deleted");
}
};

try {
// chek if treasuiry action have adress and amount
const gaTypes = await strapi.entityService.findOne("api::governance-action-type.governance-action-type",data?.gov_action_type_id)

if(gaTypes.gov_action_type_name === 'Treasury')
{
// check if withdrawal parameters exist
if (data?.proposal_withdrawals?.length === 0) {
return ctx.badRequest(null, "Withdrawal parametars not exist");
}
// Check if data is invalid
const isInvalid = await Promise.all(data.proposal_withdrawals.map(async (item) => {
return !(await isRewardAddress(item.prop_receiving_address)) || !item.prop_amount || item.prop_amount <= 0;
})).then(results => results.some(result => result));
if(isInvalid)
return ctx.badRequest(null, "Withdrawal addrress or amount parametars not valid");
}
// Create the Proposal
try {
proposal = await strapi.entityService.create(
Expand Down

0 comments on commit 907d64a

Please sign in to comment.