Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dot not destroy deliverables #245

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading