diff --git a/internal/lending/loanorders/db/postgresql.go b/internal/lending/loanorders/db/postgresql.go index 3fdf71d..9e7b1a5 100644 --- a/internal/lending/loanorders/db/postgresql.go +++ b/internal/lending/loanorders/db/postgresql.go @@ -36,10 +36,11 @@ LEFT JOIN loan_order_required_docs d ON d.id = lo.loan_order_required_doc_id` const loanOrderListFromClause = ` FROM loan_orders lo LEFT JOIN loan_types lt ON lt.id = lo.loan_type -LEFT JOIN branches b ON b.id = lo.branch_id` +LEFT JOIN branches b ON b.id = lo.branch_id +LEFT JOIN provinces bp ON bp.id = b.province_id` const loanOrderListColumns = `lo.id, lo.loan_type, lt.name, lo.created_at, lo.region, - lo.branch_id, b.name, lo.customer_name, lo.customer_surname, lo.phone, lo.status` + lo.branch_id, b.name, bp.name, lo.customer_name, lo.customer_surname, lo.phone, lo.status` // loanOrderWritableColumns lists every loan_orders column except id, created_at and // updated_at, in the exact order CreateLoanOrderDTO/UpdateLoanOrderDTO fields are read. @@ -284,11 +285,11 @@ func (r *repository) Delete(ctx context.Context, id int64) error { func scanLoanOrderListItem(row genericrepo.Scanner) (loanorders.LoanOrderListItemDTO, error) { var item loanorders.LoanOrderListItemDTO var loanTypeId, branchId int64 - var loanTypeNameJSON, branchNameJSON []byte + var loanTypeNameJSON, branchNameJSON, provinceNameJSON []byte err := row.Scan( &item.Id, &loanTypeId, &loanTypeNameJSON, &item.CreatedAt, &item.Region, - &branchId, &branchNameJSON, &item.CustomerName, &item.CustomerSurname, &item.Phone, &item.Status, + &branchId, &branchNameJSON, &provinceNameJSON, &item.CustomerName, &item.CustomerSurname, &item.Phone, &item.Status, ) if err != nil { return loanorders.LoanOrderListItemDTO{}, err @@ -297,6 +298,7 @@ func scanLoanOrderListItem(row genericrepo.Scanner) (loanorders.LoanOrderListIte var loanTypeName, branchName shared.LocalizedText _ = shared.UnmarshalLocalized(loanTypeNameJSON, &loanTypeName) _ = shared.UnmarshalLocalized(branchNameJSON, &branchName) + _ = shared.UnmarshalLocalized(provinceNameJSON, &item.ProvinceName) if loanTypeId != 0 { item.LoanType = &shared.NamedInfo{Id: loanTypeId, Name: loanTypeName} diff --git a/internal/lending/loanorders/dto.go b/internal/lending/loanorders/dto.go index 133ee7f..bb13402 100644 --- a/internal/lending/loanorders/dto.go +++ b/internal/lending/loanorders/dto.go @@ -236,15 +236,17 @@ type ListFilter struct { // LoanOrderListItemDTO is the list row; passport, work, card and guarantor // details come from GET /loan-orders/:id. type LoanOrderListItemDTO struct { - Id int64 `json:"id"` - LoanType *shared.NamedInfo `json:"loanType,omitempty"` - CreatedAt time.Time `json:"createdAt"` - Region string `json:"region"` - Branch *shared.NamedInfo `json:"branch,omitempty"` - CustomerName string `json:"customerName"` - CustomerSurname string `json:"customerSurname"` - Phone string `json:"phone"` - Status *string `json:"status"` + Id int64 `json:"id"` + LoanType *shared.NamedInfo `json:"loanType,omitempty"` + CreatedAt time.Time `json:"createdAt"` + Region string `json:"region"` + Branch *shared.NamedInfo `json:"branch,omitempty"` + // ProvinceName is the branch's province (etrap). + ProvinceName shared.LocalizedText `json:"provinceName"` + CustomerName string `json:"customerName"` + CustomerSurname string `json:"customerSurname"` + Phone string `json:"phone"` + Status *string `json:"status"` } type ListLoanOrderDTO struct {