groceries: nightly AH/Jumbo catalogue import, unit-price normalisation, product groups and compare UI
Deploy production / deploy (push) Successful in 2m48s
Deploy production / deploy (push) Successful in 2m48s
This commit is contained in:
1 parent
8dde5aa302
commit
427f4ed095
20 files changed
+34891
-699
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { db } from '#lib/server/db/index.js';
|
||||
import { requireOwner } from '#lib/server/owner.js';
|
||||
import { fold } from '#lib/server/groceries/normalize.js';
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { Sql } from 'postgres';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
/** Group picker for merge/move: top matches for ?q= (owner only). */
|
||||
export const GET: RequestHandler = async (event) => {
|
||||
requireOwner(event);
|
||||
const q = fold(event.url.searchParams.get('q')?.trim() ?? '').slice(0, 100);
|
||||
const words = q.split(/\s+/).filter(Boolean).slice(0, 6);
|
||||
if (!words.length) return json([]);
|
||||
const s = db.$client as unknown as Sql;
|
||||
const conds = words.map((w) => s`search_text like ${'%' + w.replace(/[%_\\]/g, '\\$&') + '%'}`);
|
||||
const rows = await s`
|
||||
select id, name, brand, unit, store_count as "storeCount", item_count as "itemCount"
|
||||
from groceries.groups
|
||||
where merged_into_id is null and ${conds.reduce((a, c) => s`${a} and ${c}`)}
|
||||
order by word_similarity(${q}, lower(name)) desc, store_count desc, item_count desc, id
|
||||
limit 15`;
|
||||
return json(rows, { headers: { 'cache-control': 'private, no-store' } });
|
||||
};
|
||||
Reference in new issue
Block a user