mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-21 22:16:18 +00:00
solo mostrar precios recientes
This commit is contained in:
parent
68b5691037
commit
8e69bb85bc
3 changed files with 4 additions and 0 deletions
BIN
sepa/bun.lockb
BIN
sepa/bun.lockb
Binary file not shown.
|
@ -46,6 +46,7 @@
|
|||
"@types/node": "^22.5.0",
|
||||
"bits-ui": "^0.21.13",
|
||||
"clsx": "^2.1.1",
|
||||
"date-fns": "^4.1.0",
|
||||
"drizzle-orm": "^0.33.0",
|
||||
"leaflet": "^1.9.4",
|
||||
"leaflet.markercluster": "^1.5.3",
|
||||
|
|
|
@ -4,8 +4,10 @@ import { datasets, precios, sucursales } from '$lib/server/db/schema';
|
|||
import { and, eq, sql } from 'drizzle-orm';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import * as Sentry from '@sentry/sveltekit';
|
||||
import { formatISO, subDays } from 'date-fns';
|
||||
export const load: PageServerLoad = async ({ params, setHeaders }) => {
|
||||
const id = BigInt(params.id);
|
||||
const aWeekAgo = subDays(new Date(), 5);
|
||||
const preciosQuery = db
|
||||
.select({
|
||||
id_comercio: precios.id_comercio,
|
||||
|
@ -33,6 +35,7 @@ FROM datasets d1
|
|||
JOIN (
|
||||
SELECT id_comercio, MAX(date) as max_date
|
||||
FROM datasets
|
||||
WHERE date > ${formatISO(aWeekAgo, { representation: 'date' })}
|
||||
GROUP BY id_comercio
|
||||
) d2 ON d1.id_comercio = d2.id_comercio AND d1.date = d2.max_date
|
||||
ORDER BY d1.id_comercio)
|
||||
|
|
Loading…
Reference in a new issue