@lcas58/esmi-api-types 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/routes/events/events.handlers.js +28 -2
- package/dist/src/routes/events/events.index.d.ts +4 -0
- package/dist/src/routes/events/events.routes.d.ts +12 -0
- package/dist/src/routes/events/schemas/event.schemas.d.ts +12 -0
- package/dist/src/routes/events/schemas/event.schemas.js +4 -0
- package/package.json +1 -1
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { and, eq } from "drizzle-orm";
|
|
1
|
+
import { and, eq, gte, inArray, lte } from "drizzle-orm";
|
|
2
2
|
import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
3
3
|
import * as HttpStatusPhrases from "stoker/http-status-phrases";
|
|
4
4
|
import { createDb } from "../../db/index.js";
|
|
5
|
-
import { event } from "../../db/schema/index.js";
|
|
5
|
+
import { event, location } from "../../db/schema/index.js";
|
|
6
6
|
export const list = async (c) => {
|
|
7
7
|
const { db } = createDb(c.env);
|
|
8
8
|
const query = c.req.valid("query");
|
|
9
9
|
const { sportId, source } = query;
|
|
10
10
|
const limit = query.limit ?? 20;
|
|
11
11
|
const offset = query.offset ?? 0;
|
|
12
|
+
const city = query.city?.trim();
|
|
13
|
+
const state = query.state?.trim();
|
|
14
|
+
// Time window (default: now → +7 days)
|
|
15
|
+
const now = new Date();
|
|
16
|
+
const from = query.from ? new Date(query.from) : now;
|
|
17
|
+
const to = query.to
|
|
18
|
+
? new Date(query.to)
|
|
19
|
+
: new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
|
|
12
20
|
const whereConditions = [];
|
|
13
21
|
if (sportId) {
|
|
14
22
|
whereConditions.push(eq(event.sportId, sportId));
|
|
@@ -16,6 +24,22 @@ export const list = async (c) => {
|
|
|
16
24
|
if (source) {
|
|
17
25
|
whereConditions.push(eq(event.source, source));
|
|
18
26
|
}
|
|
27
|
+
// Time filtering (recommended for feed relevance)
|
|
28
|
+
whereConditions.push(gte(event.startsAt, from));
|
|
29
|
+
whereConditions.push(lte(event.startsAt, to));
|
|
30
|
+
// City/state → locationIds → events
|
|
31
|
+
if (city && state) {
|
|
32
|
+
const locations = await db.query.location.findMany({
|
|
33
|
+
where: and(eq(location.city, city), eq(location.state, state)),
|
|
34
|
+
columns: { id: true },
|
|
35
|
+
limit: 1000,
|
|
36
|
+
});
|
|
37
|
+
if (locations.length === 0) {
|
|
38
|
+
return c.json([], HttpStatusCodes.OK);
|
|
39
|
+
}
|
|
40
|
+
const locationIds = locations.map((l) => l.id);
|
|
41
|
+
whereConditions.push(inArray(event.locationId, locationIds));
|
|
42
|
+
}
|
|
19
43
|
const events = await db.query.event.findMany({
|
|
20
44
|
where: whereConditions.length > 0 ? and(...whereConditions) : undefined,
|
|
21
45
|
with: {
|
|
@@ -27,6 +51,8 @@ export const list = async (c) => {
|
|
|
27
51
|
id: true,
|
|
28
52
|
name: true,
|
|
29
53
|
image: true,
|
|
54
|
+
homeCity: true,
|
|
55
|
+
homeState: true,
|
|
30
56
|
},
|
|
31
57
|
},
|
|
32
58
|
},
|
|
@@ -4,7 +4,11 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
|
|
|
4
4
|
input: {
|
|
5
5
|
query: {
|
|
6
6
|
sportId?: string | string[] | undefined;
|
|
7
|
+
city?: string | string[] | undefined;
|
|
8
|
+
state?: string | string[] | undefined;
|
|
7
9
|
source?: string | string[] | undefined;
|
|
10
|
+
from?: string | string[] | undefined;
|
|
11
|
+
to?: string | string[] | undefined;
|
|
8
12
|
limit?: string | string[] | undefined;
|
|
9
13
|
offset?: string | string[] | undefined;
|
|
10
14
|
};
|
|
@@ -7,16 +7,28 @@ export declare const list: {
|
|
|
7
7
|
query: z.ZodObject<{
|
|
8
8
|
sportId: z.ZodOptional<z.ZodString>;
|
|
9
9
|
source: z.ZodOptional<z.ZodEnum<["external", "community"]>>;
|
|
10
|
+
city: z.ZodOptional<z.ZodString>;
|
|
11
|
+
state: z.ZodOptional<z.ZodString>;
|
|
12
|
+
from: z.ZodOptional<z.ZodDate>;
|
|
13
|
+
to: z.ZodOptional<z.ZodDate>;
|
|
10
14
|
limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
11
15
|
offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
12
16
|
}, "strip", z.ZodTypeAny, {
|
|
13
17
|
sportId?: string | undefined;
|
|
18
|
+
city?: string | undefined;
|
|
19
|
+
state?: string | undefined;
|
|
14
20
|
source?: "external" | "community" | undefined;
|
|
21
|
+
from?: Date | undefined;
|
|
22
|
+
to?: Date | undefined;
|
|
15
23
|
limit?: number | undefined;
|
|
16
24
|
offset?: number | undefined;
|
|
17
25
|
}, {
|
|
18
26
|
sportId?: string | undefined;
|
|
27
|
+
city?: string | undefined;
|
|
28
|
+
state?: string | undefined;
|
|
19
29
|
source?: "external" | "community" | undefined;
|
|
30
|
+
from?: Date | undefined;
|
|
31
|
+
to?: Date | undefined;
|
|
20
32
|
limit?: number | undefined;
|
|
21
33
|
offset?: number | undefined;
|
|
22
34
|
}>;
|
|
@@ -254,16 +254,28 @@ export declare const eventWithRelationsSchema: z.ZodObject<z.objectUtil.extendSh
|
|
|
254
254
|
export declare const listEventsQuerySchema: z.ZodObject<{
|
|
255
255
|
sportId: z.ZodOptional<z.ZodString>;
|
|
256
256
|
source: z.ZodOptional<z.ZodEnum<["external", "community"]>>;
|
|
257
|
+
city: z.ZodOptional<z.ZodString>;
|
|
258
|
+
state: z.ZodOptional<z.ZodString>;
|
|
259
|
+
from: z.ZodOptional<z.ZodDate>;
|
|
260
|
+
to: z.ZodOptional<z.ZodDate>;
|
|
257
261
|
limit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
258
262
|
offset: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
259
263
|
}, "strip", z.ZodTypeAny, {
|
|
260
264
|
sportId?: string | undefined;
|
|
265
|
+
city?: string | undefined;
|
|
266
|
+
state?: string | undefined;
|
|
261
267
|
source?: "external" | "community" | undefined;
|
|
268
|
+
from?: Date | undefined;
|
|
269
|
+
to?: Date | undefined;
|
|
262
270
|
limit?: number | undefined;
|
|
263
271
|
offset?: number | undefined;
|
|
264
272
|
}, {
|
|
265
273
|
sportId?: string | undefined;
|
|
274
|
+
city?: string | undefined;
|
|
275
|
+
state?: string | undefined;
|
|
266
276
|
source?: "external" | "community" | undefined;
|
|
277
|
+
from?: Date | undefined;
|
|
278
|
+
to?: Date | undefined;
|
|
267
279
|
limit?: number | undefined;
|
|
268
280
|
offset?: number | undefined;
|
|
269
281
|
}>;
|
|
@@ -29,6 +29,10 @@ export const eventWithRelationsSchema = selectEventSchema.extend({
|
|
|
29
29
|
export const listEventsQuerySchema = z.object({
|
|
30
30
|
sportId: z.string().optional(),
|
|
31
31
|
source: z.enum(["external", "community"]).optional(),
|
|
32
|
+
city: z.string().optional(),
|
|
33
|
+
state: z.string().optional(),
|
|
34
|
+
from: z.coerce.date().optional(),
|
|
35
|
+
to: z.coerce.date().optional(),
|
|
32
36
|
limit: z.coerce.number().min(1).max(100).default(20).optional(),
|
|
33
37
|
offset: z.coerce.number().min(0).default(0).optional(),
|
|
34
38
|
});
|