refinement phase 3
This commit is contained in:
+37
-21
@@ -103,32 +103,48 @@ internal sealed class RefundRepository : BaseAsyncRepository<Refund>, IRefundRep
|
||||
return new PagedResult<RefundListItemDto>(items, total, page, pageSize);
|
||||
}
|
||||
|
||||
public async Task<RefundStatusProjection?> GetStatusAsync(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
var row = await (from r in TableNoTracking
|
||||
where r.Id == id
|
||||
join b in DbContext.Set<Booking>() on r.BookingId equals b.Id
|
||||
join c in DbContext.Set<CustomerProfile>() on b.CustomerId equals c.Id
|
||||
select new
|
||||
{
|
||||
c.UserId,
|
||||
r.Id,
|
||||
r.BookingId,
|
||||
r.Status,
|
||||
r.RefundChannel,
|
||||
r.Amount,
|
||||
r.ExpectedCustomerRefundEta,
|
||||
r.GatewayRefundReference,
|
||||
r.ExternalRevertReference
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
public Task<RefundStatusProjection?> GetStatusAsync(long id, CancellationToken cancellationToken)
|
||||
=> StatusProjection(r => r.Id == id, cancellationToken);
|
||||
|
||||
public Task<RefundStatusProjection?> GetStatusByBookingAsync(long bookingId, CancellationToken cancellationToken)
|
||||
// Newest refund for the booking (a re-refund is rare, but keep it deterministic).
|
||||
=> StatusProjection(r => r.BookingId == bookingId, cancellationToken, latestFirst: true);
|
||||
|
||||
private async Task<RefundStatusProjection?> StatusProjection(
|
||||
System.Linq.Expressions.Expression<Func<Refund, bool>> predicate, CancellationToken cancellationToken, bool latestFirst = false)
|
||||
{
|
||||
var query = from r in TableNoTracking.Where(predicate)
|
||||
join b in DbContext.Set<Booking>() on r.BookingId equals b.Id
|
||||
join c in DbContext.Set<CustomerProfile>() on b.CustomerId equals c.Id
|
||||
select new
|
||||
{
|
||||
c.UserId,
|
||||
r.Id,
|
||||
r.BookingId,
|
||||
r.Status,
|
||||
r.RefundChannel,
|
||||
r.Amount,
|
||||
r.ExpectedCustomerRefundEta,
|
||||
r.GatewayRefundReference,
|
||||
r.ExternalRevertReference,
|
||||
r.PlatformFeeRefundedIrr,
|
||||
r.NursePayoutRefundedIrr,
|
||||
r.RefundPercentageApplied,
|
||||
r.CancellationPolicyCode,
|
||||
r.CreatedAt,
|
||||
r.ProcessedAt
|
||||
};
|
||||
|
||||
var row = await (latestFirst ? query.OrderByDescending(x => x.Id) : query).FirstOrDefaultAsync(cancellationToken);
|
||||
if (row is null)
|
||||
return null;
|
||||
|
||||
var reference = Mask(row.GatewayRefundReference ?? row.ExternalRevertReference);
|
||||
var dto = new RefundStatusDto(row.Id, row.BookingId, row.Status, row.RefundChannel, row.Amount.ToString(),
|
||||
row.ExpectedCustomerRefundEta, reference);
|
||||
var dto = new RefundStatusDto(
|
||||
row.Id, row.BookingId, row.Status, row.RefundChannel, row.Amount.ToString(),
|
||||
row.ExpectedCustomerRefundEta, reference,
|
||||
row.PlatformFeeRefundedIrr.ToString(), row.NursePayoutRefundedIrr.ToString(),
|
||||
row.RefundPercentageApplied, row.CancellationPolicyCode, row.CreatedAt, row.ProcessedAt);
|
||||
return new RefundStatusProjection(row.UserId, dto);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user