Files
loyaly-merchant/src/features/dashboard/repositories/reportRepository.ts

39 lines
1.5 KiB
TypeScript

import {scopedEndpoint} from '@/shared/services/httpClient';
import type {Endpoint, Scope} from '@/shared/services/httpClient';
import type {
ConversionReport,
FootfallReport,
} from '@/features/dashboard/types/reports';
import type {VisitsPage} from '@/features/dashboard/types/visits';
/**
* The platform's own resources, addressed by their own names.
*
* There is no `/api/dashboard/*` here and there must not be: the dashboard is
* a READ MODEL over footfall, conversion and visits, not a data domain of its
* own. Mobile reads the same three resources from the same platform, so
* neither client can drift into having its own version of a number.
*/
export const reportRepository = {
footfall: (scope: Scope, opts: {bucket?: string; compare?: boolean} = {}):
Endpoint<FootfallReport> =>
scopedEndpoint('/api/reports/footfall', scope, {
...(opts.bucket ? {bucket: opts.bucket} : {}),
...(opts.compare ? {compare: 'previous'} : {}),
}),
conversion: (scope: Scope, opts: {bucket?: string; compare?: boolean} = {}):
Endpoint<ConversionReport> =>
scopedEndpoint('/api/reports/conversion', scope, {
...(opts.bucket ? {bucket: opts.bucket} : {}),
...(opts.compare ? {compare: 'previous'} : {}),
}),
visits: (scope: Scope, opts: {limit?: number; cursor?: string} = {}):
Endpoint<VisitsPage> =>
scopedEndpoint('/api/visits', scope, {
...(opts.limit ? {limit: String(opts.limit)} : {}),
...(opts.cursor ? {cursor: opts.cursor} : {}),
}),
};