@lcas58/esmi-api-types 1.0.12 → 1.0.14
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 +29 -3
- 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/dist/src/routes/users/users.handlers.d.ts +3 -0
- package/dist/src/routes/users/users.handlers.js +33 -0
- package/dist/src/routes/users/users.index.d.ts +31 -0
- package/dist/src/routes/users/users.index.js +6 -0
- package/dist/src/routes/users/users.routes.d.ts +72 -0
- package/dist/src/routes/users/users.routes.js +27 -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,12 +51,14 @@ 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
|
},
|
|
33
59
|
limit,
|
|
34
60
|
offset,
|
|
35
|
-
orderBy: (event, {
|
|
61
|
+
orderBy: (event, { asc }) => [asc(event.startsAt)],
|
|
36
62
|
});
|
|
37
63
|
return c.json(events, HttpStatusCodes.OK);
|
|
38
64
|
};
|
|
@@ -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
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
3
|
+
import * as HttpStatusPhrases from "stoker/http-status-phrases";
|
|
4
|
+
import { createDb } from "../../db/index.js";
|
|
5
|
+
import { user } from "../../db/schema/index.js";
|
|
6
|
+
export const me = async (c) => {
|
|
7
|
+
const sessionUser = c.get("user");
|
|
8
|
+
if (!sessionUser) {
|
|
9
|
+
return c.json({ message: HttpStatusPhrases.UNAUTHORIZED }, HttpStatusCodes.UNAUTHORIZED);
|
|
10
|
+
}
|
|
11
|
+
const { db } = createDb(c.env);
|
|
12
|
+
const foundUser = await db.query.user.findFirst({
|
|
13
|
+
where: eq(user.id, sessionUser.id),
|
|
14
|
+
columns: {
|
|
15
|
+
id: true,
|
|
16
|
+
name: true,
|
|
17
|
+
email: true,
|
|
18
|
+
emailVerified: true,
|
|
19
|
+
image: true,
|
|
20
|
+
onboardingStatus: true,
|
|
21
|
+
onboardingVersion: true,
|
|
22
|
+
onboardingCompletedAt: true,
|
|
23
|
+
homeCity: true,
|
|
24
|
+
homeState: true,
|
|
25
|
+
homeCountry: true,
|
|
26
|
+
sports: true,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
if (!foundUser) {
|
|
30
|
+
return c.json({ message: HttpStatusPhrases.UNAUTHORIZED }, HttpStatusCodes.UNAUTHORIZED);
|
|
31
|
+
}
|
|
32
|
+
return c.json(foundUser, HttpStatusCodes.OK);
|
|
33
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shared/index.js").AppBindings, {
|
|
2
|
+
"/me": {
|
|
3
|
+
$get: {
|
|
4
|
+
input: {};
|
|
5
|
+
output: {
|
|
6
|
+
image: string | null;
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
email: string;
|
|
10
|
+
emailVerified: boolean;
|
|
11
|
+
onboardingStatus: "not_started" | "in_progress" | "completed";
|
|
12
|
+
onboardingVersion: number;
|
|
13
|
+
onboardingCompletedAt: string | null;
|
|
14
|
+
homeCity: string | null;
|
|
15
|
+
homeState: string | null;
|
|
16
|
+
homeCountry: string | null;
|
|
17
|
+
sports: string[] | null;
|
|
18
|
+
};
|
|
19
|
+
outputFormat: "text" | "json";
|
|
20
|
+
status: 200;
|
|
21
|
+
} | {
|
|
22
|
+
input: {};
|
|
23
|
+
output: {
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
outputFormat: "text" | "json";
|
|
27
|
+
status: 401;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}, "/">;
|
|
31
|
+
export default router;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
export declare const me: {
|
|
3
|
+
path: "/me";
|
|
4
|
+
method: "get";
|
|
5
|
+
tags: string[];
|
|
6
|
+
responses: {
|
|
7
|
+
200: {
|
|
8
|
+
content: {
|
|
9
|
+
"application/json": {
|
|
10
|
+
schema: z.ZodObject<{
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
email: z.ZodString;
|
|
14
|
+
emailVerified: z.ZodBoolean;
|
|
15
|
+
image: z.ZodNullable<z.ZodString>;
|
|
16
|
+
onboardingStatus: z.ZodEnum<["not_started", "in_progress", "completed"]>;
|
|
17
|
+
onboardingVersion: z.ZodNumber;
|
|
18
|
+
onboardingCompletedAt: z.ZodNullable<z.ZodDate>;
|
|
19
|
+
homeCity: z.ZodNullable<z.ZodString>;
|
|
20
|
+
homeState: z.ZodNullable<z.ZodString>;
|
|
21
|
+
homeCountry: z.ZodNullable<z.ZodString>;
|
|
22
|
+
sports: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
image: string | null;
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
email: string;
|
|
28
|
+
emailVerified: boolean;
|
|
29
|
+
onboardingStatus: "not_started" | "in_progress" | "completed";
|
|
30
|
+
onboardingVersion: number;
|
|
31
|
+
onboardingCompletedAt: Date | null;
|
|
32
|
+
homeCity: string | null;
|
|
33
|
+
homeState: string | null;
|
|
34
|
+
homeCountry: string | null;
|
|
35
|
+
sports: string[] | null;
|
|
36
|
+
}, {
|
|
37
|
+
image: string | null;
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
email: string;
|
|
41
|
+
emailVerified: boolean;
|
|
42
|
+
onboardingStatus: "not_started" | "in_progress" | "completed";
|
|
43
|
+
onboardingVersion: number;
|
|
44
|
+
onboardingCompletedAt: Date | null;
|
|
45
|
+
homeCity: string | null;
|
|
46
|
+
homeState: string | null;
|
|
47
|
+
homeCountry: string | null;
|
|
48
|
+
sports: string[] | null;
|
|
49
|
+
}>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
description: string;
|
|
53
|
+
};
|
|
54
|
+
401: {
|
|
55
|
+
content: {
|
|
56
|
+
"application/json": {
|
|
57
|
+
schema: z.ZodObject<{
|
|
58
|
+
message: z.ZodString;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
message: string;
|
|
61
|
+
}, {
|
|
62
|
+
message: string;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
description: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
} & {
|
|
70
|
+
getRoutingPath(): "/me";
|
|
71
|
+
};
|
|
72
|
+
export type MeRoute = typeof me;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRoute, z } from "@hono/zod-openapi";
|
|
2
|
+
import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
3
|
+
import { jsonContent } from "stoker/openapi/helpers";
|
|
4
|
+
import { unauthorizedSchema } from "../../lib/constants.js";
|
|
5
|
+
const userProfileSchema = z.object({
|
|
6
|
+
id: z.string(),
|
|
7
|
+
name: z.string(),
|
|
8
|
+
email: z.string(),
|
|
9
|
+
emailVerified: z.boolean(),
|
|
10
|
+
image: z.string().nullable(),
|
|
11
|
+
onboardingStatus: z.enum(["not_started", "in_progress", "completed"]),
|
|
12
|
+
onboardingVersion: z.number(),
|
|
13
|
+
onboardingCompletedAt: z.date().nullable(),
|
|
14
|
+
homeCity: z.string().nullable(),
|
|
15
|
+
homeState: z.string().nullable(),
|
|
16
|
+
homeCountry: z.string().nullable(),
|
|
17
|
+
sports: z.array(z.string()).nullable(),
|
|
18
|
+
});
|
|
19
|
+
export const me = createRoute({
|
|
20
|
+
path: "/me",
|
|
21
|
+
method: "get",
|
|
22
|
+
tags: ["Users"],
|
|
23
|
+
responses: {
|
|
24
|
+
[HttpStatusCodes.OK]: jsonContent(userProfileSchema, "Current user profile"),
|
|
25
|
+
[HttpStatusCodes.UNAUTHORIZED]: jsonContent(unauthorizedSchema, "Not authenticated"),
|
|
26
|
+
},
|
|
27
|
+
});
|