Skip to content

Commit

Permalink
dot not destroy deliverables (#245)
Browse files Browse the repository at this point in the history
* dot not destroy deliverables

* destroy comments and deliverable

* add verifications
  • Loading branch information
vhcsilva authored Nov 7, 2024
1 parent 913c5f9 commit 831fb10
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/actions/get-bounty-canceled-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {updateBountiesHeader} from "src/modules/handle-header-information";
import {Push} from "../services/analytics/push";
import {AnalyticEventName} from "../services/analytics/types/events";
import updateSeoCardBounty from "src/modules/handle-seo-card";
import { Op } from "sequelize";

export const name = "getBountyCanceledEvents";
export const schedule = "*/11 * * * *";
Expand All @@ -34,10 +35,11 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
}

const dbBounty = await db.issues.findOne({
where: {contractId: block.returnValues.id, network_id: network.id,},
where: {contractId: block.returnValues.id, network_id: network.id, state: { [Op.not]: 'canceled' }},
include: [
{association: "benefactors"},
{association: "network"}
{association: "network"},
{association: "deliverables", include: [{ association: 'comments' }]}
],
});

Expand All @@ -49,14 +51,18 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
const fundingAmount = dbBounty?.fundingAmount !== '0' ? dbBounty?.fundingAmount : undefined
const fundedAmount = dbBounty?.fundedAmount !== '0' ? dbBounty?.fundedAmount : undefined
const isFunded = BigNumber(fundingAmount || 0).isEqualTo(BigNumber(fundedAmount || 1))
const isHardCancel = ['open', 'ready'].includes(dbBounty?.state || '') && (dbBounty.fundingAmount === ('0' || undefined) || isFunded)
const isHardCancel = ['open', 'ready'].includes(dbBounty?.state || '') && (fundingAmount === undefined || isFunded)

if(isHardCancel) {
if(dbBounty?.deliverables.length > 0)
if(dbBounty?.deliverables?.length > 0)
for (const dr of dbBounty?.deliverables) {
await dr.destroy()
if (dr.comments?.length > 0) {
for (const comment of dr.comments)
await comment.destroy();
}

await dr.destroy();
}

}

dbBounty.state = `canceled`;
Expand Down

0 comments on commit 831fb10

Please sign in to comment.