Skip to content

Commit c41513f

Browse files
committed
Removed service fee enabled updating
1 parent f36bff8 commit c41513f

2 files changed

Lines changed: 0 additions & 122 deletions

File tree

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import { errors } from "@strapi/utils";
2-
import { getMonthsDifference } from "../../../../utils/date";
3-
4-
const COW_BONDING_POOL_SERVICE_FEE_TH: number = 6;
5-
const COLOCATED_BONDING_POOL_SERVICE_FEE_TH: number = 3;
6-
const COW_CONDING_POOL_NAME: string = "CoW";
72

83
export default {
94
async afterCreate(event) {
105
try {
116
await updateActiveNetworks(event);
12-
await updateServiceFeeEnabled(event);
137
} catch (error) {
148
console.error("Error in beforeCreate:", error);
159
throw new errors.ValidationError(error.message || "Error processing solver data");
@@ -19,7 +13,6 @@ export default {
1913
async afterUpdate(event) {
2014
try {
2115
await updateActiveNetworks(event);
22-
await updateServiceFeeEnabled(event);
2316
} catch (error) {
2417
console.error("Error in beforeUpdate:", error);
2518
throw new errors.ValidationError(error.message || "Error processing solver data");
@@ -113,85 +106,3 @@ async function updateActiveNetworksData(solver: Solver, data: SolverData): Promi
113106
data.hasActiveNetworks = activeNetworks.length > 0;
114107
data.activeNetworks = activeNetworks;
115108
}
116-
117-
async function updateServiceFeeEnabled(event: StrapiEvent): Promise<void> {
118-
const { data, where } = event.params;
119-
const solverData: SolverData = data;
120-
121-
if (where) {
122-
try {
123-
const solver = await strapi.entityService.findOne(
124-
'api::solver.solver',
125-
where.id,
126-
{
127-
populate: {
128-
solver_bonding_pools: {
129-
fields: ['name', 'joinedOn']
130-
}
131-
}
132-
}
133-
);
134-
135-
if (solver) {
136-
await setServiceFeeEnabled(solver as Solver, solverData);
137-
}
138-
} catch (error) {
139-
console.error(`Error fetching solver data for service fee calculation (id ${where.id}):`, error);
140-
throw new errors.ApplicationError(`Failed to fetch solver data for service fee calculation: ${error.message}`);
141-
}
142-
}
143-
// For create operation, we handle it in afterCreate since we need the ID
144-
}
145-
146-
/**
147-
* Determines if a solver is eligible for service fees based on bonding pool criteria.
148-
* Pure function that checks eligibility based on time thresholds:
149-
* - 6+ months for non-colocated CoW pools
150-
* - 3+ months for colocated pools
151-
* @param solver The solver entity to check
152-
* @returns Boolean indicating if the solver is eligible for service fees
153-
*/
154-
function isEligibleForServiceFee(solver: Solver): boolean {
155-
if (!solver.solver_bonding_pools || solver.solver_bonding_pools.length === 0) {
156-
return false;
157-
}
158-
159-
const currentDate = new Date();
160-
161-
for (const bondingPool of solver.solver_bonding_pools) {
162-
// Skip if joinedOn field is not set (not a mandatory field)
163-
if (!bondingPool.joinedOn) {
164-
continue;
165-
}
166-
167-
const joinedDate = new Date(bondingPool.joinedOn);
168-
const monthsDifference = getMonthsDifference(joinedDate, currentDate);
169-
170-
if (bondingPool.name === COW_CONDING_POOL_NAME && solver.isColocated === "No") {
171-
if (monthsDifference >= COW_BONDING_POOL_SERVICE_FEE_TH) {
172-
return true;
173-
}
174-
}
175-
else if (solver.isColocated === "Yes") {
176-
if (monthsDifference >= COLOCATED_BONDING_POOL_SERVICE_FEE_TH) {
177-
return true;
178-
}
179-
}
180-
// For partial colocated, we'll treat it as not colocated
181-
}
182-
183-
return false;
184-
}
185-
186-
/**
187-
* Sets the isServiceFeeEnabled flag in the solver data based on eligibility.
188-
* Uses the pure function isEligibleForServiceFee to determine eligibility.
189-
*/
190-
async function setServiceFeeEnabled(solver: Solver, data: SolverData): Promise<void> {
191-
try {
192-
data.isServiceFeeEnabled = isEligibleForServiceFee(solver);
193-
} catch (error) {
194-
console.error(`Error setting service fee enabled status:`, error);
195-
throw new errors.ApplicationError(`Failed to set service fee status: ${error.message}`);
196-
}
197-
}

src/utils/date.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)