@lcas58/esmi-api-types 1.0.8 → 1.0.10

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.
Files changed (52) hide show
  1. package/dist/src/routes/events/events.handlers.d.ts +2 -18
  2. package/dist/src/routes/events/events.handlers.js +24 -154
  3. package/dist/src/routes/events/events.index.d.ts +47 -442
  4. package/dist/src/routes/events/events.index.js +1 -3
  5. package/dist/src/routes/events/events.routes.d.ts +347 -1194
  6. package/dist/src/routes/events/events.routes.js +11 -53
  7. package/dist/src/routes/events/schemas/event.schemas.d.ts +173 -824
  8. package/dist/src/routes/events/schemas/event.schemas.js +26 -46
  9. package/dist/src/routes/events/schemas/index.d.ts +1 -1
  10. package/dist/src/routes/events/schemas/index.js +1 -1
  11. package/dist/src/routes/leagues/leagues.handlers.js +2 -1
  12. package/dist/src/routes/marketing/marketing.index.d.ts +15 -15
  13. package/dist/src/routes/marketing/marketing.routes.d.ts +5 -5
  14. package/dist/src/routes/organizations/organizations.index.d.ts +6 -6
  15. package/dist/src/routes/sports/sports.handlers.d.ts +4 -0
  16. package/dist/src/routes/sports/sports.handlers.js +23 -0
  17. package/dist/src/routes/sports/sports.index.d.ts +45 -0
  18. package/dist/src/routes/sports/sports.index.js +7 -0
  19. package/dist/src/routes/sports/sports.routes.d.ts +90 -0
  20. package/dist/src/routes/sports/sports.routes.js +27 -0
  21. package/dist/src/routes/webhooks/webhooks.handlers.d.ts +3 -0
  22. package/dist/src/routes/webhooks/webhooks.handlers.js +14 -0
  23. package/dist/src/routes/webhooks/webhooks.index.d.ts +32 -0
  24. package/dist/src/routes/webhooks/webhooks.index.js +6 -0
  25. package/dist/src/routes/webhooks/webhooks.routes.d.ts +65 -0
  26. package/dist/src/routes/webhooks/webhooks.routes.js +26 -0
  27. package/dist/src/shared/client-types.d.ts +3 -16
  28. package/dist/src/shared/client-types.js +0 -12
  29. package/package.json +25 -32
  30. package/dist/src/app.d.ts +0 -2
  31. package/dist/src/app.js +0 -22
  32. package/dist/src/db/schema/event.d.ts +0 -264
  33. package/dist/src/db/schema/event.js +0 -38
  34. package/dist/src/db/schema/index.d.ts +0 -8
  35. package/dist/src/db/schema/index.js +0 -8
  36. package/dist/src/db/schema/league.d.ts +0 -261
  37. package/dist/src/db/schema/league.js +0 -27
  38. package/dist/src/db/schema/location.d.ts +0 -239
  39. package/dist/src/db/schema/location.js +0 -22
  40. package/dist/src/db/schema/marketing.d.ts +0 -77
  41. package/dist/src/db/schema/marketing.js +0 -16
  42. package/dist/src/db/schema/organization.d.ts +0 -882
  43. package/dist/src/db/schema/organization.js +0 -174
  44. package/dist/src/db/schema/pickup.d.ts +0 -417
  45. package/dist/src/db/schema/pickup.js +0 -42
  46. package/dist/src/db/schema/tag.d.ts +0 -261
  47. package/dist/src/db/schema/tag.js +0 -55
  48. package/dist/src/db/schema/user.d.ts +0 -597
  49. package/dist/src/db/schema/user.js +0 -45
  50. package/dist/src/lib/types.d.ts +0 -14
  51. package/dist/src/shared/index.d.ts +0 -7
  52. package/dist/src/shared/index.js +0 -28
@@ -1,20 +1,4 @@
1
1
  import type { AppRouteHandler } from "../../lib/types.js";
2
- import type { CreateRoute, GetCountStatsRoute, ListRoute, PatchRoute } from "./events.routes.js";
3
- /**
4
- * GET /events
5
- * - Returns a list of events
6
- */
2
+ import type { GetOneRoute, ListRoute } from "./events.routes.js";
7
3
  export declare const list: AppRouteHandler<ListRoute>;
8
- /**
9
- * POST /events
10
- * - Idempotently upserts the optional location
11
- * - Inserts the event in a single transaction
12
- * - Returns 201 + created entity
13
- */
14
- export declare const create: AppRouteHandler<CreateRoute>;
15
- /**
16
- * PATCH /events/{id}
17
- * - Updates the event
18
- */
19
- export declare const patch: AppRouteHandler<PatchRoute>;
20
- export declare const getCountStats: AppRouteHandler<GetCountStatsRoute>;
4
+ export declare const getOne: AppRouteHandler<GetOneRoute>;
@@ -1,177 +1,47 @@
1
- import { and, eq, sql } from "drizzle-orm";
1
+ import { and, eq } 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/event.js";
6
- import location from "../../db/schema/location.js";
7
- import { ZOD_ERROR_CODES, ZOD_ERROR_MESSAGES } from "../../lib/constants.js";
8
- /**
9
- * GET /events
10
- * - Returns a list of events
11
- */
5
+ import { event } from "../../db/schema/index.js";
12
6
  export const list = async (c) => {
13
7
  const { db } = createDb(c.env);
14
- const { type, organizationId, status } = c.req.valid("query");
15
- // Build where conditions
8
+ const query = c.req.valid("query");
9
+ const { sportId, source } = query;
10
+ const limit = query.limit ?? 20;
11
+ const offset = query.offset ?? 0;
16
12
  const whereConditions = [];
17
- if (type) {
18
- whereConditions.push(eq(event.type, type));
13
+ if (sportId) {
14
+ whereConditions.push(eq(event.sportId, sportId));
19
15
  }
20
- if (status) {
21
- whereConditions.push(eq(event.status, status));
22
- }
23
- if (organizationId) {
24
- whereConditions.push(eq(event.organizationId, organizationId));
16
+ if (source) {
17
+ whereConditions.push(eq(event.source, source));
25
18
  }
26
19
  const events = await db.query.event.findMany({
27
20
  where: whereConditions.length > 0 ? and(...whereConditions) : undefined,
28
21
  with: {
29
- creator: true,
30
- organization: true,
22
+ sport: true,
31
23
  location: true,
24
+ externalLink: true,
32
25
  },
26
+ limit,
27
+ offset,
28
+ orderBy: (event, { desc }) => [desc(event.startsAt)],
33
29
  });
34
- if (events.length === 0) {
35
- return c.json({
36
- message: HttpStatusPhrases.NOT_FOUND,
37
- }, HttpStatusCodes.NOT_FOUND);
38
- }
39
30
  return c.json(events, HttpStatusCodes.OK);
40
31
  };
41
- /**
42
- * POST /events
43
- * - Idempotently upserts the optional location
44
- * - Inserts the event in a single transaction
45
- * - Returns 201 + created entity
46
- */
47
- export const create = async (c) => {
48
- const { db } = createDb(c.env);
49
- const data = c.req.valid("json");
50
- const user = c.get("user");
51
- if (!user) {
52
- return c.json({ message: HttpStatusPhrases.UNAUTHORIZED }, HttpStatusCodes.UNAUTHORIZED);
53
- }
54
- try {
55
- // Insert location first (if provided)
56
- if (data.location) {
57
- const loc = data.location;
58
- await db
59
- .insert(location)
60
- .values({
61
- id: loc.id,
62
- provider: loc.provider,
63
- name: loc.name,
64
- formattedAddress: loc.formattedAddress,
65
- city: loc.city,
66
- state: loc.state,
67
- country: loc.country,
68
- postalCode: loc.postalCode,
69
- latitude: loc.latitude ? Number.parseFloat(loc.latitude) : null,
70
- longitude: loc.longitude ? Number.parseFloat(loc.longitude) : null,
71
- })
72
- .onConflictDoNothing({ target: location.id });
73
- }
74
- // Insert event
75
- const [createdEvent] = await db
76
- .insert(event)
77
- .values({
78
- name: data.name.trim(),
79
- description: data.description ?? null,
80
- locationId: data.location?.id ?? null,
81
- type: data.type,
82
- organizationId: data.organizationId,
83
- creatorId: user.id,
84
- mode: "ADULT",
85
- ageGroup: data.ageGroup,
86
- gender: data.gender,
87
- status: "WIP",
88
- })
89
- .returning();
90
- const eventWithRelations = await db.query.event.findFirst({
91
- where: eq(event.id, createdEvent.id),
92
- with: {
93
- creator: true,
94
- organization: true,
95
- location: true,
96
- },
97
- });
98
- return c.json(eventWithRelations, HttpStatusCodes.CREATED);
99
- }
100
- catch (err) {
101
- console.error("Error creating event:", err);
102
- return c.json({
103
- success: false,
104
- error: {
105
- issues: [
106
- {
107
- code: "CREATE_EVENT_FAILED",
108
- path: [],
109
- message: err instanceof Error ? err.message : "Failed to create event.",
110
- },
111
- ],
112
- name: "ValidationError",
113
- },
114
- }, HttpStatusCodes.UNPROCESSABLE_ENTITY);
115
- }
116
- };
117
- /**
118
- * PATCH /events/{id}
119
- * - Updates the event
120
- */
121
- export const patch = async (c) => {
32
+ export const getOne = async (c) => {
122
33
  const { db } = createDb(c.env);
123
34
  const { id } = c.req.valid("param");
124
- const updates = c.req.valid("json");
125
- if (Object.keys(updates).length === 0) {
126
- return c.json({
127
- success: false,
128
- error: {
129
- issues: [
130
- {
131
- code: ZOD_ERROR_CODES.INVALID_UPDATES,
132
- path: [],
133
- message: ZOD_ERROR_MESSAGES.NO_UPDATES,
134
- },
135
- ],
136
- name: "ZodError",
137
- },
138
- }, HttpStatusCodes.UNPROCESSABLE_ENTITY);
139
- }
140
- const [updatedEvent] = await db.update(event)
141
- .set(updates)
142
- .where(eq(event.id, id))
143
- .returning();
144
- if (!updatedEvent) {
145
- return c.json({
146
- message: HttpStatusPhrases.NOT_FOUND,
147
- }, HttpStatusCodes.NOT_FOUND);
148
- }
149
- // Fetch the updated event with relations
150
- const eventWithRelations = await db.query.event.findFirst({
151
- where: eq(event.id, updatedEvent.id),
35
+ const foundEvent = await db.query.event.findFirst({
36
+ where: eq(event.id, id),
152
37
  with: {
153
- creator: true,
154
- organization: true,
38
+ sport: true,
155
39
  location: true,
40
+ externalLink: true,
156
41
  },
157
42
  });
158
- return c.json(eventWithRelations, HttpStatusCodes.OK);
159
- };
160
- export const getCountStats = async (c) => {
161
- const { db } = createDb(c.env);
162
- const { organizationId } = c.req.valid("query");
163
- // Single optimized query to get all counts at once
164
- const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
165
- const oneYearAgo = new Date(Date.now() - 360 * 24 * 60 * 60 * 1000);
166
- const [stats] = await db
167
- .select({
168
- total: sql `count(case when ${event.status} in ('IN_PROGRESS', 'PUBLISHED', 'COMPLETED') then 1 end)`,
169
- thisMonth: sql `count(case when ${event.createdAt} >= ${thirtyDaysAgo} and ${event.status} in ('IN_PROGRESS', 'PUBLISHED', 'COMPLETED') then 1 end)`,
170
- inProgress: sql `count(case when ${event.status} = 'IN_PROGRESS' then 1 end)`,
171
- completed: sql `count(case when ${event.status} = 'COMPLETED' and ${event.createdAt} >= ${oneYearAgo} then 1 end)`,
172
- upcoming: sql `count(case when ${event.status} = 'PUBLISHED' and ${event.createdAt} >= ${thirtyDaysAgo} then 1 end)`,
173
- })
174
- .from(event)
175
- .where(eq(event.organizationId, organizationId));
176
- return c.json(stats, HttpStatusCodes.OK);
43
+ if (!foundEvent) {
44
+ return c.json({ message: HttpStatusPhrases.NOT_FOUND }, HttpStatusCodes.NOT_FOUND);
45
+ }
46
+ return c.json(foundEvent, HttpStatusCodes.OK);
177
47
  };