fix: include recent bought items in map data

This commit is contained in:
Nico 2026-06-04 12:37:53 -07:00
parent 48aab43220
commit 8614c0d984
2 changed files with 39 additions and 11 deletions

View File

@ -269,7 +269,10 @@ async function getMapItems(db, householdId, locationId) {
) )
WHERE hl.household_id = $1 WHERE hl.household_id = $1
AND hl.store_location_id = $2 AND hl.store_location_id = $2
AND hl.bought = FALSE AND (
hl.bought = FALSE
OR hl.modified_on >= NOW() - INTERVAL '24 hours'
)
ORDER BY resolved_zone.sort_order ASC NULLS LAST, hsi.name ASC`, ORDER BY resolved_zone.sort_order ASC NULLS LAST, hsi.name ASC`,
[householdId, locationId] [householdId, locationId]
); );

View File

@ -72,16 +72,28 @@ describe("location-map.model", () => {
label: "Published Bakery", label: "Published Bakery",
}; };
const zones = [{ id: 501, name: "Bakery", sort_order: 10, item_count: 1 }]; const zones = [{ id: 501, name: "Bakery", sort_order: 10, item_count: 1 }];
const items = [{ const items = [
id: 3001, {
item_id: 2001, id: 3001,
item_name: "sourdough", item_id: 2001,
quantity: 1, item_name: "sourdough",
bought: false, quantity: 1,
zone_id: 501, bought: false,
zone: "Bakery", zone_id: 501,
added_by_users: ["Owner"], zone: "Bakery",
}]; added_by_users: ["Owner"],
},
{
id: 3002,
item_id: 2002,
item_name: "bagels",
quantity: 1,
bought: true,
zone_id: 501,
zone: "Bakery",
added_by_users: ["Owner"],
},
];
storeModel.getLocationById.mockResolvedValue(location); storeModel.getLocationById.mockResolvedValue(location);
pool.query.mockImplementation(async (sql, params = []) => { pool.query.mockImplementation(async (sql, params = []) => {
@ -151,6 +163,19 @@ describe("location-map.model", () => {
expect(state.published_objects).toEqual([expect.objectContaining({ id: publishedObject.id })]); expect(state.published_objects).toEqual([expect.objectContaining({ id: publishedObject.id })]);
}); });
test("loads active and recent bought rows for map item layers", async () => {
const { items } = mockMapStateQueries();
const state = await LocationMap.getMapState(1, 10, true);
expect(state.items).toEqual(items);
expect(state.items.some((item) => item.bought)).toBe(true);
expect(pool.query).toHaveBeenCalledWith(
expect.stringContaining("OR hl.modified_on >= NOW() - INTERVAL '24 hours'"),
[1, 10]
);
});
test("unlinks saved map objects from zones outside the current location", async () => { test("unlinks saved map objects from zones outside the current location", async () => {
const client = createClient(); const client = createClient();
pool.connect.mockResolvedValue(client); pool.connect.mockResolvedValue(client);