diff --git a/src/app/modules/billing/billing.controller.ts b/src/app/modules/billing/billing.controller.ts index 5711c9c8db..77d9e6fb3b 100644 --- a/src/app/modules/billing/billing.controller.ts +++ b/src/app/modules/billing/billing.controller.ts @@ -4,11 +4,7 @@ import { StatusCodes } from 'http-status-codes' import moment from 'moment-timezone' import { createLoggerWithLabel } from '../../../config/logger' -import { - BillingInformationDto, - BillingQueryDto, - ErrorDto, -} from '../../../types/api' +import { BillingInfoDto, BillingQueryDto, ErrorDto } from '../../../types/api' import { createReqMeta } from '../../utils/request' import { BillingFactory } from './billing.factory' @@ -25,7 +21,7 @@ const logger = createLoggerWithLabel(module) */ export const handleGetBillInfo: RequestHandler< ParamsDictionary, - ErrorDto | BillingInformationDto, + ErrorDto | BillingInfoDto, unknown, BillingQueryDto > = async (req, res) => { @@ -55,7 +51,7 @@ export const handleGetBillInfo: RequestHandler< }) return res .status(StatusCodes.INTERNAL_SERVER_ERROR) - .json('Error in retrieving billing records') + .json({ message: 'Error in retrieving billing records' }) } // Retrieved login stats successfully. diff --git a/src/public/services/BillingService.ts b/src/public/services/BillingService.ts index 42f5fb26f6..1a77743300 100644 --- a/src/public/services/BillingService.ts +++ b/src/public/services/BillingService.ts @@ -1,29 +1,21 @@ import axios from 'axios' -import { BillingInformationDto } from '../../types/api/billing' +import { BillingInfoDto, BillingQueryDto } from '../../types/api/billing' // Exported for testing export const BILLING_ENDPOINT = '/billing' /** * Gets the billing information for the given month and year - * @param yr The year to get the billing information for - * @param mth The month to get the billing information for - * @param esrvcId The id of the form + * @param billingQueryParams The formId and the specific month to get the information for * @returns Promise The billing statistics of the given month */ export const getBillingInfo = ( - yr: string, - mth: string, - esrvcId: string, -): Promise => { + billingQueryParams: BillingQueryDto, +): Promise => { return axios - .get(BILLING_ENDPOINT, { - params: { - yr, - mth, - esrvcId, - }, + .get(BILLING_ENDPOINT, { + params: billingQueryParams, }) .then(({ data }) => data) } diff --git a/src/types/api/billing.ts b/src/types/api/billing.ts index 5cdaa89770..4cd0cd7953 100644 --- a/src/types/api/billing.ts +++ b/src/types/api/billing.ts @@ -1,9 +1,22 @@ -import { LoginStatistic } from '../../types' +import { AuthType } from '../../types' +// yr: The year to get the billing information for +// mth: The month to get the billing information for +// esrvcId: The id of the form export type BillingQueryDto = { esrvcId: string yr: string mth: string } -export type BillingInformationDto = { loginStats: LoginStatistic[] } +// NOTE: LoginStatistic is defined here and in src/types/login. +// This is to allow the communication layer (the dto) to be agnostic of intermediate representations. +type LoginStatistic = { + adminEmail: string + formName: string + total: number + formId: string + authType: AuthType +} + +export type BillingInfoDto = { loginStats: LoginStatistic[] } diff --git a/src/types/api/index.ts b/src/types/api/index.ts index 7fbcc9b31c..20d19312a1 100644 --- a/src/types/api/index.ts +++ b/src/types/api/index.ts @@ -1,3 +1,4 @@ export * from './core' export * from './form' export * from './billing' +export * from './examples'