Phase 5 cleanup
This commit is contained in:
parent
5536acd67d
commit
76a516a417
136 changed files with 6322 additions and 1985 deletions
|
|
@ -9,7 +9,6 @@ import type {
|
|||
UpdateRefillListInput,
|
||||
UpdateRefillListItemInput,
|
||||
RefillListQueryInput,
|
||||
RefillAlertQueryInput,
|
||||
} from '@meshitrack/shared';
|
||||
import { RefillListStatus } from '@meshitrack/shared';
|
||||
import { NotFoundError } from '../../common/errors.js';
|
||||
|
|
@ -58,7 +57,10 @@ export class RefillsService {
|
|||
|
||||
// Get strength data from cabinet aggregate
|
||||
const summaries = await this.cabinetRepository.getAggregateSummary(householdId);
|
||||
const summaryMap = new Map<string, { medicineStrength: number; medicineStrengthUnit: string }>();
|
||||
const summaryMap = new Map<
|
||||
string,
|
||||
{ medicineStrength: number; medicineStrengthUnit: string }
|
||||
>();
|
||||
for (const s of summaries) {
|
||||
summaryMap.set(s._id as string, {
|
||||
medicineStrength: s.medicineStrength as number,
|
||||
|
|
@ -217,17 +219,19 @@ export class RefillsService {
|
|||
public async addToCabinet(listId: string, householdId: string, userId: string) {
|
||||
const list = await this.getById(listId, householdId);
|
||||
|
||||
const checkedItems = (list.items as Array<{
|
||||
_id: { toString: () => string };
|
||||
medicineId: string;
|
||||
medicineName: string;
|
||||
quantity: number;
|
||||
unit: string;
|
||||
actualPrice?: number;
|
||||
storeId?: string;
|
||||
checked: boolean;
|
||||
addedToCabinet: boolean;
|
||||
}>).filter((item) => item.checked && !item.addedToCabinet);
|
||||
const checkedItems = (
|
||||
list.items as Array<{
|
||||
_id: { toString: () => string };
|
||||
medicineId: string;
|
||||
medicineName: string;
|
||||
quantity: number;
|
||||
unit: string;
|
||||
actualPrice?: number;
|
||||
storeId?: string;
|
||||
checked: boolean;
|
||||
addedToCabinet: boolean;
|
||||
}>
|
||||
).filter((item) => item.checked && !item.addedToCabinet);
|
||||
|
||||
if (checkedItems.length === 0) {
|
||||
return { addedCount: 0, priceRecordsCreated: 0 };
|
||||
|
|
@ -242,9 +246,10 @@ export class RefillsService {
|
|||
medicineId: item.medicineId,
|
||||
quantity: item.quantity,
|
||||
unit: item.unit as never,
|
||||
unitPrice: item.actualPrice !== undefined && item.quantity > 0
|
||||
? item.actualPrice / item.quantity
|
||||
: undefined,
|
||||
unitPrice:
|
||||
item.actualPrice !== undefined && item.quantity > 0
|
||||
? item.actualPrice / item.quantity
|
||||
: undefined,
|
||||
totalPrice: item.actualPrice,
|
||||
storeId: item.storeId,
|
||||
purchaseDate: new Date().toISOString(),
|
||||
|
|
@ -265,9 +270,7 @@ export class RefillsService {
|
|||
const list = await this.getById(listId, householdId);
|
||||
|
||||
const medicineIds = [
|
||||
...new Set(
|
||||
(list.items as Array<{ medicineId: string }>).map((item) => item.medicineId),
|
||||
),
|
||||
...new Set((list.items as Array<{ medicineId: string }>).map((item) => item.medicineId)),
|
||||
];
|
||||
|
||||
const comparisons = await Promise.all(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue