Skip to content

Commit 4ec9f5e

Browse files
committed
PM-4961 Fetch Billing account details api
1 parent 3b0349c commit 4ec9f5e

5 files changed

Lines changed: 98 additions & 1 deletion

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ workflows:
6464
branches:
6565
only:
6666
- develop
67-
- PM-4949
67+
- PM-4961
6868

6969
# Production builds are exectuted only on tagged commits to the
7070
# master branch.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SELECT
2+
ba.name,
3+
ba.description,
4+
ba."subcontractingEndCustomer" AS "subcontractingEndCustomer",
5+
ba.status::text AS status,
6+
ba."startDate" AS "startDate",
7+
ba."endDate" AS "endDate",
8+
ba.budget,
9+
ba.markup
10+
FROM "billing-accounts"."BillingAccount" ba
11+
WHERE ba.id::text = TRIM($1)

src/reports/sfdc/sfdc-reports.controller.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { SfdcReportsService } from "./sfdc-reports.service";
2323
import {
2424
BaFeesReportQueryDto,
2525
BaFeesReportResponse,
26+
BillingAccountProfileQueryDto,
27+
BillingAccountProfileResponse,
2628
ChallengesReportQueryDto,
2729
ChallengesReportResponse,
2830
PaymentsReportQueryDto,
@@ -83,6 +85,24 @@ export class SfdcReportsController {
8385
return report;
8486
}
8587

88+
@Get("/billing-accounts")
89+
@UseGuards(PermissionsGuard)
90+
@Scopes(AppScopes.AllReports, AppScopes.SFDC.PaymentsReport)
91+
@ApiBearerAuth()
92+
@ApiOperation({
93+
summary: "Billing account profile",
94+
description:
95+
"Returns billing account metadata from billing-accounts.BillingAccount when the ID exists.",
96+
})
97+
@ApiResponse({
98+
status: 200,
99+
description: "Billing account profile retrieved successfully",
100+
type: ResponseDto<BillingAccountProfileResponse>,
101+
})
102+
async getBillingAccountProfile(@Query() query: BillingAccountProfileQueryDto) {
103+
return this.reportsService.getBillingAccountProfile(query);
104+
}
105+
86106
@Get("/taas/jobs")
87107
@UseGuards(PermissionsGuard)
88108
@Scopes(AppScopes.AllReports, AppScopes.SFDC.TaasJobs)

src/reports/sfdc/sfdc-reports.dto.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,55 @@ export class PaymentsReportResponse {
350350
challengeStatus: string | null;
351351
}
352352

353+
export class BillingAccountProfileQueryDto {
354+
@ApiProperty({
355+
required: true,
356+
description:
357+
"Billing account identifier (matches finance.payment.billing_account and billing-accounts.BillingAccount.id)",
358+
example: "80004349",
359+
})
360+
@Transform(({ value }) => (typeof value === "string" ? value.trim() : value))
361+
@IsString()
362+
@IsNotEmpty()
363+
billingAccountId: string;
364+
}
365+
366+
export class BillingAccountDetailResponse {
367+
@ApiProperty()
368+
name: string;
369+
370+
@ApiProperty({ nullable: true, type: String })
371+
description: string | null;
372+
373+
@ApiProperty({ nullable: true, type: String })
374+
subcontractingEndCustomer: string | null;
375+
376+
@ApiProperty()
377+
status: string;
378+
379+
@ApiProperty({ nullable: true, type: String })
380+
startDate: string | null;
381+
382+
@ApiProperty({ nullable: true, type: String })
383+
endDate: string | null;
384+
385+
@ApiProperty()
386+
budget: string;
387+
388+
@ApiProperty()
389+
markup: string;
390+
}
391+
392+
export class BillingAccountProfileResponse {
393+
@ApiProperty({
394+
nullable: true,
395+
type: BillingAccountDetailResponse,
396+
description:
397+
"Row from billing-accounts.BillingAccount when the ID exists; null if unknown.",
398+
})
399+
billingAccount: BillingAccountDetailResponse | null;
400+
}
401+
353402
export class TaasJobsReportQueryDto {
354403
@ApiProperty({
355404
required: false,

src/reports/sfdc/sfdc-reports.service.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Logger } from "src/common/logger";
44
import {
55
BaFeesReportQueryDto,
66
BaFeesReportResponse,
7+
BillingAccountProfileQueryDto,
8+
BillingAccountProfileResponse,
79
ChallengesFilterMode,
810
ChallengesReportQueryDto,
911
ChallengesReportResponse,
@@ -137,6 +139,21 @@ export class SfdcReportsService {
137139
}));
138140
}
139141

142+
async getBillingAccountProfile(
143+
filters: BillingAccountProfileQueryDto,
144+
): Promise<BillingAccountProfileResponse> {
145+
const billingAccountId = filters.billingAccountId.trim();
146+
const query = this.sql.load("reports/sfdc/billing-account-detail.sql");
147+
const rows = await this.db.query<BillingAccountProfileResponse["billingAccount"]>(
148+
query,
149+
[billingAccountId],
150+
);
151+
152+
return {
153+
billingAccount: rows[0] ?? null,
154+
};
155+
}
156+
140157
async getTaasJobsReport(filters: TaasJobsReportQueryDto) {
141158
this.logger.debug("Starting getTaasJobsReport with filters:", filters);
142159

0 commit comments

Comments
 (0)