feat: finish company profile in the backoffice

This commit is contained in:
Nathnael
2026-06-23 06:45:29 +00:00
parent f7cbb6af6f
commit a6f3fd5643
24 changed files with 690 additions and 938 deletions

View File

@@ -4,6 +4,7 @@ import {
Get,
HttpStatus,
Param,
ParseUUIDPipe,
Post,
Query,
Res,
@@ -33,6 +34,14 @@ import {
export class PaymentController {
constructor(private readonly paymentService: PaymentService) { }
@Get("by-company/:companyId/customer-view")
@ApiOperation({ summary: "List payments for a company (customer-view shape, backoffice)" })
findByCompanyCustomerView(
@Param("companyId", ParseUUIDPipe) companyId: string,
) {
return this.paymentService.findByCompanyId(companyId);
}
@Get("summary")
@BookingView()
@ApiOperation({ summary: "Payment count/amount summary for dashboard cards" })

View File

@@ -61,4 +61,56 @@ export class PaymentRepository {
return this.paymentRepo.createQueryBuilder(alias);
}
async findByCompanyId(companyId: string): Promise<{
id: string;
merchantOrderId: string;
bookingReference: string;
amount: number;
currency: string;
method: string;
status: string;
paidAt: Date | null;
createdAt: Date;
}[]> {
const rows: {
id: string;
merchant_order_id: string;
booking_reference: string;
amount: number;
currency: string;
method: string;
status: string;
paid_at: Date | null;
created_at: Date;
}[] = await this.dataSource.query(
`SELECT p.id,
p.merchant_order_id,
b.reference AS booking_reference,
p.amount,
p.currency,
p.method,
p.status,
p.paid_at,
p.created_at
FROM freight.payments p
JOIN freight.bookings b ON b.id = p.ref_id
WHERE b.company_id = $1
AND p.deleted_at IS NULL
AND b.deleted_at IS NULL
ORDER BY p.created_at DESC`,
[companyId],
);
return rows.map((r) => ({
id: r.id,
merchantOrderId: r.merchant_order_id,
bookingReference: r.booking_reference,
amount: Number(r.amount),
currency: r.currency,
method: r.method,
status: r.status,
paidAt: r.paid_at,
createdAt: r.created_at,
}));
}
}

View File

@@ -428,4 +428,8 @@ export class PaymentService {
default: return "action-required";
}
}
async findByCompanyId(companyId: string) {
return this.paymentRepo.findByCompanyId(companyId);
}
}