Updated the expense details API

This commit is contained in:
ashutosh.nehete 2025-12-09 14:44:39 +05:30
parent 6a300db97c
commit 0395b46610
2 changed files with 9 additions and 4 deletions

View File

@ -17,7 +17,6 @@ namespace Marco.Pms.Model.Expenses
public ICollection<BillAttachments> Attachments { get; set; } = new List<BillAttachments>();
public ICollection<ExpensesReimburseMapping> ExpensesReimburseMappings { get; set; } = new List<ExpensesReimburseMapping>();
public ICollection<ExpenseLog> ExpenseLogs { get; set; } = new List<ExpenseLog>();
public Guid ExpenseCategoryId { get; set; }

View File

@ -528,9 +528,6 @@ namespace Marco.Pms.Services.Service
.ThenInclude(erm => erm.ExpensesReimburse)
.ThenInclude(er => er!.ReimburseBy)
.ThenInclude(e => e!.JobRole)
.Include(e => e.ExpenseLogs)
.ThenInclude(el => el.UpdatedBy)
.ThenInclude(e => e!.JobRole)
.FirstOrDefaultAsync(e =>
(e.Id == id || (e.UIDPrefix + "/" + e.UIDPostfix.ToString().PadLeft(5, '0')) == expenseUId)
&& e.TenantId == tenantId);
@ -563,6 +560,15 @@ namespace Marco.Pms.Services.Service
var projectVm = await GetProjectDetailsAsync(expense.ProjectId, tenantId);
response.Project = projectVm;
response.ExpenseLogs = await _context.ExpenseLogs
.AsNoTracking() // Read-only query optimization
.Include(el => el.UpdatedBy)
.ThenInclude(e => e!.JobRole)
.Where(el => el.ExpenseId == expense.Id)
.OrderByDescending(el => el.UpdateAt)
.ProjectTo<ExpenseLogVM>(_mapper.ConfigurationProvider) // Projection
.ToListAsync();
// 9. Generate S3 Pre-signed URLs for attachments
response.Documents = expense.Attachments
.Where(ba => ba.Document != null)