Implement regimens
This commit is contained in:
parent
1f66fab30f
commit
9f416903ef
66 changed files with 9130 additions and 189 deletions
|
|
@ -0,0 +1,43 @@
|
|||
import type { CabinetEventsRepository, CreateCabinetEventData } from './cabinet-events.repository.js';
|
||||
import type { CabinetEventQueryInput, SpendingSummaryQueryInput } from '@meshitrack/shared';
|
||||
|
||||
interface Deps {
|
||||
cabinetEventsRepository: CabinetEventsRepository;
|
||||
}
|
||||
|
||||
export class CabinetEventsService {
|
||||
private readonly cabinetEventsRepository: CabinetEventsRepository;
|
||||
|
||||
public constructor({ cabinetEventsRepository }: Deps) {
|
||||
this.cabinetEventsRepository = cabinetEventsRepository;
|
||||
}
|
||||
|
||||
public async logEvent(data: CreateCabinetEventData) {
|
||||
return this.cabinetEventsRepository.create(data);
|
||||
}
|
||||
|
||||
public async logEvents(events: CreateCabinetEventData[]) {
|
||||
if (events.length === 0) return [];
|
||||
return this.cabinetEventsRepository.createMany(events);
|
||||
}
|
||||
|
||||
public async listEvents(householdId: string, query: CabinetEventQueryInput) {
|
||||
return this.cabinetEventsRepository.findByHousehold(householdId, query);
|
||||
}
|
||||
|
||||
public async getEventsByItem(
|
||||
householdId: string,
|
||||
cabinetItemId: string,
|
||||
query: { cursor?: string; limit: number },
|
||||
) {
|
||||
return this.cabinetEventsRepository.findByCabinetItem(householdId, cabinetItemId, query);
|
||||
}
|
||||
|
||||
public async getSpendingSummary(householdId: string, query: SpendingSummaryQueryInput) {
|
||||
return this.cabinetEventsRepository.getSpendingSummary(householdId, query);
|
||||
}
|
||||
|
||||
public async getAvgUnitPrices(householdId: string, medicineIds: string[]) {
|
||||
return this.cabinetEventsRepository.getAvgUnitPriceByMedicine(householdId, medicineIds);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue