Skip to content

Commit 8e1ffee

Browse files
authored
Merge pull request #3700 from bcgov/feat/3697
feat(3697): add separate billing code by providers
2 parents dcd3278 + 03b01d8 commit 8e1ffee

File tree

16 files changed

+74
-42
lines changed

16 files changed

+74
-42
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ SHELL := /usr/bin/env bash
33
.PHONY: localdev
44
localdev:
55
export MACHINE_HOST_IP=$$(hostname -I | awk '{print $$1}'); \
6-
docker-compose -f ./localdev/docker-compose.yml up --build
6+
docker-compose -f ./localdev/docker-compose.yml up --build --remove-orphans
77

88
.PHONY: localmac
99
localmac:
1010
export MACHINE_HOST_IP=$$(ipconfig getifaddr en0); \
11-
docker-compose -f ./localdev/docker-compose.yml -f ./localdev/docker-compose-arm64.yml up --build
11+
docker-compose -f ./localdev/docker-compose.yml -f ./localdev/docker-compose-arm64.yml up --build --remove-orphans
1212

1313
.PHONY: dev
1414
dev:

app/app/api/billing/[idOrAccountCoding]/download/route.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Prisma, RequestType } from '@prisma/client';
1+
import { Provider, Cluster, RequestType } from '@prisma/client';
22
import { z } from 'zod';
33
import createApiHandler from '@/core/api-handler';
44
import prisma from '@/core/prisma';
55
import { PdfResponse, BadRequestResponse } from '@/core/responses';
66
import { generateEmouPdf, Product } from '@/helpers/pdfs/emou';
77
import { PermissionsEnum } from '@/types/permissions';
8+
import { processNumber, processUpperEnumString, processBoolean } from '@/utils/zod';
89
import { getBillingIdWhere } from '../helpers';
910

1011
const pathParamSchema = z.object({
@@ -13,6 +14,7 @@ const pathParamSchema = z.object({
1314

1415
const queryParamSchema = z.object({
1516
licencePlate: z.string().optional(),
17+
context: z.preprocess(processUpperEnumString, z.union([z.nativeEnum(Provider), z.nativeEnum(Cluster)]).optional()),
1618
});
1719

1820
const apiHandler = createApiHandler({
@@ -22,9 +24,9 @@ const apiHandler = createApiHandler({
2224

2325
export const GET = apiHandler(async ({ pathParams, queryParams, session }) => {
2426
const { idOrAccountCoding } = pathParams;
25-
const { licencePlate } = queryParams;
27+
const { licencePlate, context } = queryParams;
2628

27-
const billingWhereId = getBillingIdWhere(idOrAccountCoding);
29+
const billingWhereId = getBillingIdWhere(idOrAccountCoding, context);
2830
const billing = await prisma.billing.findFirst({
2931
where: { signed: true, approved: true, ...billingWhereId },
3032
include: {

app/app/api/billing/[idOrAccountCoding]/exist/route.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
import { Prisma } from '@prisma/client';
1+
import { Provider, Cluster } from '@prisma/client';
22
import { z } from 'zod';
33
import createApiHandler from '@/core/api-handler';
44
import prisma from '@/core/prisma';
55
import { NoContent, OkResponse } from '@/core/responses';
6+
import { processNumber, processUpperEnumString, processBoolean } from '@/utils/zod';
67
import { getBillingIdWhere } from '../helpers';
78

89
const pathParamSchema = z.object({
910
idOrAccountCoding: z.string(),
1011
});
1112

13+
const queryParamSchema = z.object({
14+
context: z.preprocess(processUpperEnumString, z.union([z.nativeEnum(Provider), z.nativeEnum(Cluster)]).optional()),
15+
});
16+
1217
const apiHandler = createApiHandler({
1318
roles: ['user'],
14-
validations: { pathParams: pathParamSchema },
19+
validations: { pathParams: pathParamSchema, queryParams: queryParamSchema },
1520
});
1621

17-
export const GET = apiHandler(async ({ pathParams, session }) => {
22+
export const GET = apiHandler(async ({ pathParams, queryParams, session }) => {
1823
const { idOrAccountCoding } = pathParams;
19-
const billingWhereId = getBillingIdWhere(idOrAccountCoding);
24+
const { context } = queryParams;
25+
26+
const billingWhereId = getBillingIdWhere(idOrAccountCoding, context);
2027

2128
const count = await prisma.billing.count({
2229
where: billingWhereId,
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import ObjectID from 'bson-objectid';
1+
export function getBillingIdWhere(idOrAccountCoding: string, context?: string) {
2+
if (!context) {
3+
return { id: idOrAccountCoding };
4+
}
25

3-
export function getBillingIdWhere(idOrAccountCoding: string) {
4-
const isPotentialObjectId = ObjectID.isValid(idOrAccountCoding);
5-
const billingWhereId = isPotentialObjectId
6-
? { OR: [{ id: idOrAccountCoding }, { accountCoding: idOrAccountCoding }] }
7-
: { accountCoding: idOrAccountCoding };
8-
return billingWhereId;
6+
const code = `${idOrAccountCoding}_${context}`;
7+
return { code };
98
}

app/app/api/billing/[idOrAccountCoding]/route.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
import { Provider, Cluster } from '@prisma/client';
12
import { z } from 'zod';
23
import createApiHandler from '@/core/api-handler';
34
import prisma from '@/core/prisma';
45
import { OkResponse } from '@/core/responses';
56
import { BillingGetPayload } from '@/types/billing';
7+
import { processNumber, processUpperEnumString, processBoolean } from '@/utils/zod';
68
import { getBillingIdWhere } from './helpers';
79

810
const pathParamSchema = z.object({
911
idOrAccountCoding: z.string(),
1012
});
1113

14+
const queryParamSchema = z.object({
15+
context: z.preprocess(processUpperEnumString, z.union([z.nativeEnum(Provider), z.nativeEnum(Cluster)]).optional()),
16+
});
17+
1218
export const GET = createApiHandler({
1319
roles: ['user'],
14-
validations: { pathParams: pathParamSchema },
15-
})(async ({ pathParams, session }) => {
20+
validations: { pathParams: pathParamSchema, queryParams: queryParamSchema },
21+
})(async ({ pathParams, queryParams, session }) => {
1622
const { idOrAccountCoding } = pathParams;
23+
const { context } = queryParams;
1724

18-
const billingWhereId = getBillingIdWhere(idOrAccountCoding);
25+
const billingWhereId = getBillingIdWhere(idOrAccountCoding, context);
1926

2027
const billing: BillingGetPayload | null = await prisma.billing.findFirst({
2128
where: billingWhereId,

app/app/public-cloud/products/(product)/create/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default publicCloudProductNew(({ pathParams, queryParams, session }) => {
9393
)
9494
.refine(
9595
async (formData) => {
96-
const hasBilling = await existBilling(formData.accountCoding);
96+
const hasBilling = await existBilling(formData.accountCoding, formData.provider);
9797
if (!hasBilling) return true;
9898
return formData.isEaApproval;
9999
},

app/components/billing/PublicCloudBillingDownloadButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function BillingDownloadButton({ product }: { product: Product })
1616
className="mt-2"
1717
onClick={async () => {
1818
setLoading(true);
19-
await downloadBilling(product.billing.accountCoding, product.licencePlate);
19+
await downloadBilling(product.billing.accountCoding, product.provider, product.licencePlate);
2020
setLoading(false);
2121
}}
2222
>

app/components/form/AccountCoding.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function AccountCoding({
4949
queryFn: () => {
5050
const code = values.accountCoding;
5151
if (code.length < 24) return null;
52-
return getBilling(code);
52+
return getBilling(code, values.provider);
5353
},
5454
enabled: !disabled,
5555
});

app/components/modal/reviewPublicCloudProductModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function ReviewPublicCloudProductModal({
5353
error: billingError,
5454
} = useQuery({
5555
queryKey: ['billing', billingId],
56-
queryFn: () => getBilling(billingId),
56+
queryFn: () => getBilling(billingId, ''),
5757
enabled: !!billingId,
5858
});
5959

app/emails/_components/Params.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const publicRequestData = {
1515
billingId: 'billing-id',
1616
billing: {
1717
id: 'mou-id',
18+
code: '',
1819
accountCoding: '12345',
1920
licencePlate: 'XYZ789',
2021
signed: true,
@@ -186,6 +187,7 @@ export const samplePublicRequest = {
186187
billingId: 'billing-id',
187188
billing: {
188189
id: 'mou-id',
190+
code: '',
189191
accountCoding: '12345',
190192
licencePlate: 'XYZ789',
191193
signed: true,
@@ -287,6 +289,7 @@ export const samplePublicProduct: PublicCloudRequestedProjectWithContacts = {
287289
billingId: 'billing-id',
288290
billing: {
289291
id: 'mou-id',
292+
code: '',
290293
accountCoding: '12345',
291294
licencePlate: 'XYZ789',
292295
signed: true,

0 commit comments

Comments
 (0)