potential fix to user duplicates when user adds mopre than 1 of same item

This commit is contained in:
Nico 2026-01-22 23:54:53 -08:00
parent 5ce4177446
commit 4139a07cd2

View File

@ -11,15 +11,14 @@ exports.getUnboughtItems = async () => {
ENCODE(gl.item_image, 'base64') as item_image, ENCODE(gl.item_image, 'base64') as item_image,
gl.image_mime_type, gl.image_mime_type,
( (
SELECT ARRAY_AGG(u.name ORDER BY gh.added_on DESC) SELECT ARRAY_AGG(DISTINCT u.name)
FROM ( FROM (
SELECT gh.added_by, gh.added_on, SELECT DISTINCT gh.added_by
ROW_NUMBER() OVER (PARTITION BY gh.list_item_id ORDER BY gh.added_on DESC) as rn
FROM grocery_history gh FROM grocery_history gh
WHERE gh.list_item_id = gl.id WHERE gh.list_item_id = gl.id
ORDER BY gh.added_by
) gh ) gh
JOIN users u ON gh.added_by = u.id JOIN users u ON gh.added_by = u.id
WHERE gh.rn <= gl.quantity
) as added_by_users, ) as added_by_users,
gl.modified_on as last_added_on, gl.modified_on as last_added_on,
ic.item_type, ic.item_type,
@ -126,15 +125,14 @@ exports.getRecentlyBoughtItems = async () => {
ENCODE(gl.item_image, 'base64') as item_image, ENCODE(gl.item_image, 'base64') as item_image,
gl.image_mime_type, gl.image_mime_type,
( (
SELECT ARRAY_AGG(u.name ORDER BY gh.added_on DESC) SELECT ARRAY_AGG(DISTINCT u.name)
FROM ( FROM (
SELECT gh.added_by, gh.added_on, SELECT DISTINCT gh.added_by
ROW_NUMBER() OVER (PARTITION BY gh.list_item_id ORDER BY gh.added_on DESC) as rn
FROM grocery_history gh FROM grocery_history gh
WHERE gh.list_item_id = gl.id WHERE gh.list_item_id = gl.id
ORDER BY gh.added_by
) gh ) gh
JOIN users u ON gh.added_by = u.id JOIN users u ON gh.added_by = u.id
WHERE gh.rn <= gl.quantity
) as added_by_users, ) as added_by_users,
gl.modified_on as last_added_on gl.modified_on as last_added_on
FROM grocery_list gl FROM grocery_list gl