Implement regimens
This commit is contained in:
parent
1f66fab30f
commit
9f416903ef
66 changed files with 9130 additions and 189 deletions
60
packages/web/src/services/cabinet-events.ts
Normal file
60
packages/web/src/services/cabinet-events.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { apiClient } from './api-client';
|
||||
import type { z } from 'zod/v4';
|
||||
import type {
|
||||
CabinetEventListResponseSchema,
|
||||
SpendingSummaryResponseSchema,
|
||||
} from '@meshitrack/shared';
|
||||
|
||||
type CabinetEventListResponse = z.infer<typeof CabinetEventListResponseSchema>;
|
||||
type SpendingSummaryResponse = z.infer<typeof SpendingSummaryResponseSchema>;
|
||||
|
||||
export async function listCabinetEvents(
|
||||
householdId: string,
|
||||
query?: {
|
||||
medicineId?: string;
|
||||
eventType?: string;
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
cursor?: string;
|
||||
limit?: number;
|
||||
},
|
||||
): Promise<CabinetEventListResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (query?.medicineId) params.set('medicineId', query.medicineId);
|
||||
if (query?.eventType) params.set('eventType', query.eventType);
|
||||
if (query?.startDate) params.set('startDate', query.startDate);
|
||||
if (query?.endDate) params.set('endDate', query.endDate);
|
||||
if (query?.cursor) params.set('cursor', query.cursor);
|
||||
if (query?.limit) params.set('limit', String(query.limit));
|
||||
const qs = params.toString();
|
||||
return apiClient.get<CabinetEventListResponse>(
|
||||
`/households/${householdId}/cabinet-events${qs ? `?${qs}` : ''}`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getEventsByItem(
|
||||
householdId: string,
|
||||
cabinetItemId: string,
|
||||
query?: { cursor?: string; limit?: number },
|
||||
): Promise<CabinetEventListResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (query?.cursor) params.set('cursor', query.cursor);
|
||||
if (query?.limit) params.set('limit', String(query.limit));
|
||||
const qs = params.toString();
|
||||
return apiClient.get<CabinetEventListResponse>(
|
||||
`/households/${householdId}/cabinet-events/by-item/${cabinetItemId}${qs ? `?${qs}` : ''}`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getSpendingSummary(
|
||||
householdId: string,
|
||||
query?: { period?: string; medicineId?: string },
|
||||
): Promise<SpendingSummaryResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (query?.period) params.set('period', query.period);
|
||||
if (query?.medicineId) params.set('medicineId', query.medicineId);
|
||||
const qs = params.toString();
|
||||
return apiClient.get<SpendingSummaryResponse>(
|
||||
`/households/${householdId}/cabinet-events/spending-summary${qs ? `?${qs}` : ''}`,
|
||||
);
|
||||
}
|
||||
55
packages/web/src/services/organizer.ts
Normal file
55
packages/web/src/services/organizer.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { apiClient } from './api-client';
|
||||
import type { z } from 'zod/v4';
|
||||
import type {
|
||||
OrganizerFillListResponseSchema,
|
||||
OrganizerFillResponseSchema,
|
||||
OrganizerPreviewResponseSchema,
|
||||
OrganizerFillSchema,
|
||||
OrganizerPreviewSchema,
|
||||
} from '@meshitrack/shared';
|
||||
|
||||
type OrganizerFillListResponse = z.infer<typeof OrganizerFillListResponseSchema>;
|
||||
type OrganizerFillResponse = z.infer<typeof OrganizerFillResponseSchema>;
|
||||
type OrganizerPreviewResponse = z.infer<typeof OrganizerPreviewResponseSchema>;
|
||||
type OrganizerFillInput = z.infer<typeof OrganizerFillSchema>;
|
||||
type OrganizerPreviewInput = z.infer<typeof OrganizerPreviewSchema>;
|
||||
|
||||
export async function listFills(
|
||||
householdId: string,
|
||||
query?: { regimenId?: string; status?: string; cursor?: string; limit?: number },
|
||||
): Promise<OrganizerFillListResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (query?.regimenId) params.set('regimenId', query.regimenId);
|
||||
if (query?.status) params.set('status', query.status);
|
||||
if (query?.cursor) params.set('cursor', query.cursor);
|
||||
if (query?.limit) params.set('limit', String(query.limit));
|
||||
const qs = params.toString();
|
||||
return apiClient.get<OrganizerFillListResponse>(
|
||||
`/households/${householdId}/organizer/fills${qs ? `?${qs}` : ''}`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getFill(householdId: string, id: string): Promise<OrganizerFillResponse> {
|
||||
return apiClient.get<OrganizerFillResponse>(`/households/${householdId}/organizer/fills/${id}`);
|
||||
}
|
||||
|
||||
export async function previewFill(
|
||||
householdId: string,
|
||||
data: OrganizerPreviewInput,
|
||||
): Promise<OrganizerPreviewResponse> {
|
||||
return apiClient.post<OrganizerPreviewResponse>(`/households/${householdId}/organizer/preview`, data);
|
||||
}
|
||||
|
||||
export async function executeFill(
|
||||
householdId: string,
|
||||
data: OrganizerFillInput,
|
||||
): Promise<OrganizerFillResponse> {
|
||||
return apiClient.post<OrganizerFillResponse>(`/households/${householdId}/organizer/fill`, data);
|
||||
}
|
||||
|
||||
export async function undoFill(householdId: string, fillId: string): Promise<OrganizerFillResponse> {
|
||||
return apiClient.post<OrganizerFillResponse>(
|
||||
`/households/${householdId}/organizer/fills/${fillId}/undo`,
|
||||
{},
|
||||
);
|
||||
}
|
||||
51
packages/web/src/services/regimens.ts
Normal file
51
packages/web/src/services/regimens.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { apiClient } from './api-client';
|
||||
import type { z } from 'zod/v4';
|
||||
import type {
|
||||
RegimenResponseSchema,
|
||||
RegimenListResponseSchema,
|
||||
BurnRateResponseSchema,
|
||||
CreateRegimenSchema,
|
||||
UpdateRegimenSchema,
|
||||
} from '@meshitrack/shared';
|
||||
|
||||
type RegimenResponse = z.infer<typeof RegimenResponseSchema>;
|
||||
type RegimenListResponse = z.infer<typeof RegimenListResponseSchema>;
|
||||
type BurnRateResponse = z.infer<typeof BurnRateResponseSchema>;
|
||||
type CreateRegimenInput = z.infer<typeof CreateRegimenSchema>;
|
||||
type UpdateRegimenInput = z.infer<typeof UpdateRegimenSchema>;
|
||||
|
||||
export async function listRegimens(
|
||||
householdId: string,
|
||||
query?: { isActive?: boolean; cursor?: string; limit?: number },
|
||||
): Promise<RegimenListResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (query?.isActive !== undefined) params.set('isActive', String(query.isActive));
|
||||
if (query?.cursor) params.set('cursor', query.cursor);
|
||||
if (query?.limit) params.set('limit', String(query.limit));
|
||||
const qs = params.toString();
|
||||
return apiClient.get<RegimenListResponse>(`/households/${householdId}/regimens${qs ? `?${qs}` : ''}`);
|
||||
}
|
||||
|
||||
export async function getRegimen(householdId: string, id: string): Promise<RegimenResponse> {
|
||||
return apiClient.get<RegimenResponse>(`/households/${householdId}/regimens/${id}`);
|
||||
}
|
||||
|
||||
export async function getBurnRates(householdId: string): Promise<BurnRateResponse> {
|
||||
return apiClient.get<BurnRateResponse>(`/households/${householdId}/regimens/burn-rate`);
|
||||
}
|
||||
|
||||
export async function createRegimen(householdId: string, data: CreateRegimenInput): Promise<RegimenResponse> {
|
||||
return apiClient.post<RegimenResponse>(`/households/${householdId}/regimens`, data);
|
||||
}
|
||||
|
||||
export async function updateRegimen(
|
||||
householdId: string,
|
||||
id: string,
|
||||
data: UpdateRegimenInput,
|
||||
): Promise<RegimenResponse> {
|
||||
return apiClient.patch<RegimenResponse>(`/households/${householdId}/regimens/${id}`, data);
|
||||
}
|
||||
|
||||
export async function deleteRegimen(householdId: string, id: string): Promise<void> {
|
||||
return apiClient.delete<void>(`/households/${householdId}/regimens/${id}`);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue