Description
Background
At the moment we do not allow editing work period payments (only status
). But to fulfill the need of this frontend task topcoder-archive/topcoder-platform-micro-frontends-taas-admin-app#80 we should support editing amount
and days
.
Task
Update payment endpoint
-
PATCH /work-period-payments
endpoints should allow updating the next fields if thestatus
is NOTin-progress
:-
amount
- float number greater then0
-
days
- integer value from0
till maximum days we can pay:we cannot pay for more days than user worked this week. So
WorkPeriod.daysPaid
cannot be more thanWorkPeriod.daysWorked
.WorkPeriod.daysPaid
is calculated as a sum of thedays
of all the payment of this WorkPeriod not includingcancelled
orfailed
payments. If user pass such a value which would causeWorkPeriod.daysPaid
to be more thanWorkPeriod.daysWorked
we should return an error like during creating https://github.com/topcoder-platform/taas-apis/blob/dev/src/services/WorkPeriodPaymentService.js#L71-L74
-
-
Each payment actually is processed by the challenge which is stored in
challengeId
field. if we update the payment andchallengeId
is notnull
i. e. challenge for the payment was already created we have to update the corresponding challenge prize to reflect newamount
(only ifamount
has been changed).- So before writing new payment data to DB and send Kafka update the challenge
prizeSets[0].prizes[0].value
to the new amount. See how we create a challenge https://github.com/topcoder-platform/taas-apis/blob/dev/src/services/PaymentService.js#L75-L78. You would have to create a new method in this service to update the challenge.- If updating challenge request failed, then trow error
Cannot update the payment amount inside the challenge: ${erro message from Challenge API}
- If updating challenge request failed, then trow error
- So before writing new payment data to DB and send Kafka update the challenge
Automation logic
We have some automation logic which happens when we create or cancel payment, see "Automation Logic" section here #288.
The automation logic should be also triggered when we edit payment amount or days. I think it should work without any additional changes, just, please, make sure.
General Requirements
Please, follow general requirements which are applicable for this task https://github.com/topcoder-platform/taas-apis#documentation-and-utils