Skip to content

Commit be13099

Browse files
authored
Revert "fix: add endpoint to update legacy payment records"
1 parent cd6bb93 commit be13099

File tree

4 files changed

+3
-168
lines changed

4 files changed

+3
-168
lines changed

config/default.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ module.exports = {
9292
UPDATE: process.env.SCOPE_CHALLENGES_UPDATE || "update:challenges",
9393
DELETE: process.env.SCOPE_CHALLENGES_DELETE || "delete:challenges",
9494
ALL: process.env.SCOPE_CHALLENGES_ALL || "all:challenges",
95-
PAYMENT: process.env.SCOPE_PAYMENT || "create:payments",
9695
},
9796

9897
DEFAULT_CONFIDENTIALITY_TYPE: process.env.DEFAULT_CONFIDENTIALITY_TYPE || "public",
@@ -130,8 +129,7 @@ module.exports = {
130129
GRPC_CHALLENGE_SERVER_HOST: process.env.GRPC_DOMAIN_CHALLENGE_SERVER_HOST || "localhost",
131130
GRPC_CHALLENGE_SERVER_PORT: process.env.GRPC_DOMAIN_CHALLENGE_SERVER_PORT || 8888,
132131
GRPC_ACL_SERVER_HOST: process.env.GRPC_ACL_SERVER_HOST || "localhost",
133-
GRPC_ACL_SERVER_PORT: process.env.GRPC_ACL_SERVER_PORT || 40020,
132+
GRPC_ACL_SERVER_PORT: process.env.GRPC_ACL_SERVER_PORT || 8889,
134133

135-
SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID:
136-
process.env.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID || "517e76b0-8824-4e72-9b48-a1ebde1793a8",
134+
SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID: process.env.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID || '517e76b0-8824-4e72-9b48-a1ebde1793a8'
137135
};

src/controllers/ChallengeController.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,6 @@ async function updateChallenge(req, res) {
104104
res.send(result);
105105
}
106106

107-
/**
108-
* Update Legacy Payout (Updates informixoltp:payment_detail)
109-
* This has no effect other than to keep DW in sync for looker with
110-
* Updates that happen in Wallet
111-
*/
112-
async function updateLegacyPayout(req, res) {
113-
logger.debug(
114-
`updateLegacyPayout User: ${JSON.stringify(req.authUser)} - ChallengeID: ${
115-
req.params.challengeId
116-
} - Body: ${JSON.stringify(req.body)}`
117-
);
118-
const result = await service.updateLegacyPayout(
119-
req,
120-
req.authUser,
121-
req.params.challengeId,
122-
req.body
123-
);
124-
res.send(result);
125-
}
126-
127107
/**
128108
* Delete challenge
129109
* @param {Object} req the request
@@ -172,7 +152,6 @@ module.exports = {
172152
createChallenge,
173153
getChallenge,
174154
updateChallenge,
175-
updateLegacyPayout,
176155
deleteChallenge,
177156
getChallengeStatistics,
178157
sendNotifications,

src/routes.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const constants = require("../app-constants");
66
const {
7-
SCOPES: { PAYMENT, READ, CREATE, UPDATE, DELETE, ALL },
7+
SCOPES: { READ, CREATE, UPDATE, DELETE, ALL },
88
} = require("config");
99

1010
module.exports = {
@@ -112,14 +112,6 @@ module.exports = {
112112
scopes: [UPDATE, ALL],
113113
},
114114
},
115-
"/challenges/:challengeId/legacy-payment": {
116-
patch: {
117-
controller: "ChallengeController",
118-
method: "updateLegacyPayout",
119-
auth: "jwt",
120-
scopes: [PAYMENT],
121-
},
122-
},
123115
"/challenges/:challengeId/statistics": {
124116
get: {
125117
controller: "ChallengeController",

src/services/ChallengeService.js

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,13 +2172,6 @@ updateChallenge.schema = {
21722172
)
21732173
.optional(),
21742174
overview: Joi.any().forbidden(),
2175-
v5Payout: Joi.object().keys({
2176-
userId: Joi.number().integer().positive().required(),
2177-
amount: Joi.number().allow(null),
2178-
status: Joi.string().allow(null),
2179-
datePaid: Joi.string().allow(null),
2180-
releaseDate: Joi.string().allow(null),
2181-
}),
21822175
})
21832176
.unknown(true)
21842177
.required(),
@@ -2505,132 +2498,6 @@ async function indexChallengeAndPostToKafka(updatedChallenge, track, type) {
25052498
});
25062499
}
25072500

2508-
async function updateLegacyPayout(currentUser, challengeId, data) {
2509-
const challenge = await challengeDomain.lookup(getLookupCriteria("id", challengeId));
2510-
const { v5Payout } = data;
2511-
2512-
// SQL qurey to fetch the payment and payment_detail record
2513-
let sql = `SELECT * FROM informixoltp:payment p
2514-
INNER JOIN informixoltp:payment_detail pd ON p.most_recent_detail_id = pd.payment_detail_id
2515-
WHERE p.user_id = ${v5Payout.userId} AND`;
2516-
2517-
if (challenge.legacyId != null) {
2518-
sql += ` pd.component_project_id = ${challenge.legacyId}`;
2519-
} else {
2520-
sql += ` pd.jira_issue_id = \'${challengeId}\'`;
2521-
}
2522-
2523-
sql += " ORDER BY pd.payment_detail_id ASC";
2524-
2525-
console.log("Fetch legacy payment detail: ", sql);
2526-
2527-
const result = await aclQueryDomain.rawQuery({ sql });
2528-
let updateClauses = [`date_modified = current`];
2529-
2530-
const statusMap = {
2531-
Paid: 53,
2532-
OnHold: 55,
2533-
OnHoldAdmin: 55,
2534-
Owed: 56,
2535-
Cancelled: 65,
2536-
EnteredIntoPaymentSystem: 70,
2537-
};
2538-
2539-
if (v5Payout.status != null) {
2540-
updateClauses.push(`payment_status_id = ${statusMap[v5Payout.status]}`);
2541-
if (v5Payout.status === "Paid") {
2542-
updateClauses.push(`date_paid = '${v5Payout.datePaid}'`);
2543-
} else {
2544-
updateClauses.push("date_paid = null");
2545-
}
2546-
}
2547-
2548-
if (v5Payout.releaseDate != null) {
2549-
updateClauses.push(`date_due = '${v5Payout.releaseDate}'`);
2550-
}
2551-
2552-
const paymentDetailIds = result.rows.map(
2553-
(row) => row.fields.find((field) => field.key === "payment_detail_id").value
2554-
);
2555-
2556-
if (v5Payout.amount != null) {
2557-
updateClauses.push(`total_amount = ${v5Payout.amount}`);
2558-
if (paymentDetailIds.length === 1) {
2559-
updateClauses.push(`net_amount = ${v5Payout.amount}`);
2560-
updateClauses.push(`gross_amount = ${v5Payout.amount}`);
2561-
}
2562-
}
2563-
2564-
if (paymentDetailIds.length === 0) {
2565-
return {
2566-
success: false,
2567-
message: "No payment detail record found",
2568-
};
2569-
}
2570-
2571-
const whereClause = [`payment_detail_id IN (${paymentDetailIds.join(",")})`];
2572-
2573-
const updateQuery = `UPDATE informixoltp:payment_detail SET ${updateClauses.join(
2574-
", "
2575-
)} WHERE ${whereClause.join(" AND ")}`;
2576-
2577-
console.log("Update Clauses", updateClauses);
2578-
console.log("Update Query", updateQuery);
2579-
2580-
await aclQueryDomain.rawQuery({ sql: updateQuery });
2581-
2582-
if (v5Payout.amount != null) {
2583-
if (paymentDetailIds.length > 1) {
2584-
const amountInCents = v5Payout.amount * 100;
2585-
2586-
const split1Cents = Math.round(amountInCents * 0.75);
2587-
const split2Cents = amountInCents - split1Cents;
2588-
2589-
const split1Dollars = Number((split1Cents / 100).toFixed(2));
2590-
const split2Dollars = Number((split2Cents / 100).toFixed(2));
2591-
2592-
const paymentUpdateQueries = paymentDetailIds.map((paymentDetailId, index) => {
2593-
let amt = 0;
2594-
if (index === 0) {
2595-
amt = split1Dollars;
2596-
}
2597-
if (index === 1) {
2598-
amt = split2Dollars;
2599-
}
2600-
2601-
return `UPDATE informixoltp:payment_detail SET date_modified = CURRENT, net_amount = ${amt}, gross_amount = ${amt} WHERE payment_detail_id = ${paymentDetailId}`;
2602-
});
2603-
2604-
console.log("Payment Update Queries", paymentUpdateQueries);
2605-
2606-
await Promise.all(
2607-
paymentUpdateQueries.map((query) => aclQueryDomain.rawQuery({ sql: query }))
2608-
);
2609-
}
2610-
}
2611-
2612-
return {
2613-
success: true,
2614-
message: "Successfully updated legacy payout",
2615-
};
2616-
}
2617-
updateLegacyPayout.schema = {
2618-
currentUser: Joi.any(),
2619-
challengeId: Joi.id(),
2620-
data: Joi.object()
2621-
.keys({
2622-
v5Payout: Joi.object().keys({
2623-
userId: Joi.number().integer().positive().required(),
2624-
amount: Joi.number().allow(null),
2625-
status: Joi.string().allow(null),
2626-
datePaid: Joi.string().allow(null),
2627-
releaseDate: Joi.string().allow(null),
2628-
}),
2629-
})
2630-
.unknown(true)
2631-
.required(),
2632-
};
2633-
26342501
/**
26352502
* Get SRM Schedule
26362503
* @param {Object} criteria the criteria
@@ -2695,7 +2562,6 @@ module.exports = {
26952562
getChallenge,
26962563
updateChallenge,
26972564
deleteChallenge,
2698-
updateLegacyPayout,
26992565
getChallengeStatistics,
27002566
sendNotifications,
27012567
advancePhase,

0 commit comments

Comments
 (0)