@lcas58/esmi-api-types 1.0.5 → 1.0.7
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/app.d.ts +1158 -0
- package/dist/src/app.js +22 -0
- package/dist/src/routes/events/events.handlers.d.ts +20 -0
- package/dist/src/routes/events/events.handlers.js +177 -0
- package/dist/src/routes/events/events.index.d.ts +501 -0
- package/dist/src/routes/events/events.index.js +9 -0
- package/dist/src/routes/events/events.routes.d.ts +1375 -0
- package/dist/src/routes/events/events.routes.js +72 -0
- package/dist/src/routes/events/schemas/event.schemas.d.ts +896 -0
- package/dist/src/routes/events/schemas/event.schemas.js +49 -0
- package/dist/src/routes/events/schemas/index.d.ts +1 -0
- package/dist/src/routes/events/schemas/index.js +1 -0
- package/dist/src/routes/index.route.d.ts +13 -0
- package/dist/src/routes/index.route.js +19 -0
- package/dist/src/routes/leagues/leagues.handlers.d.ts +3 -0
- package/dist/src/routes/leagues/leagues.handlers.js +49 -0
- package/dist/src/routes/leagues/leagues.index.d.ts +53 -0
- package/dist/src/routes/leagues/leagues.index.js +6 -0
- package/dist/src/routes/leagues/leagues.routes.d.ts +137 -0
- package/dist/src/routes/leagues/leagues.routes.js +47 -0
- package/dist/src/routes/marketing/marketing.handlers.d.ts +4 -0
- package/dist/src/routes/marketing/marketing.handlers.js +20 -0
- package/dist/src/routes/marketing/marketing.index.d.ts +58 -0
- package/dist/src/routes/marketing/marketing.index.js +7 -0
- package/dist/src/routes/marketing/marketing.routes.d.ts +154 -0
- package/dist/src/routes/marketing/marketing.routes.js +27 -0
- package/dist/src/routes/organizations/organizations.handlers.d.ts +74 -0
- package/dist/src/routes/organizations/organizations.handlers.js +485 -0
- package/dist/src/routes/organizations/organizations.index.d.ts +517 -0
- package/dist/src/routes/organizations/organizations.index.js +12 -0
- package/dist/src/routes/organizations/organizations.routes.d.ts +1236 -0
- package/dist/src/routes/organizations/organizations.routes.js +137 -0
- package/dist/src/routes/organizations/tasks.test.d.ts +0 -0
- package/dist/src/routes/organizations/tasks.test.js +181 -0
- package/dist/src/routes/tags/tags.handlers.d.ts +3 -0
- package/dist/src/routes/tags/tags.handlers.js +15 -0
- package/dist/src/routes/tags/tags.index.d.ts +24 -0
- package/dist/src/routes/tags/tags.index.js +6 -0
- package/dist/src/routes/tags/tags.routes.d.ts +68 -0
- package/dist/src/routes/tags/tags.routes.js +25 -0
- package/dist/src/shared/client-types.d.ts +8 -3
- package/dist/src/shared/client-types.js +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { selectEventSchema } from "../../../db/schema/event.js";
|
|
3
|
+
import { insertLocationSchema, selectLocationSchema } from "../../../db/schema/location.js";
|
|
4
|
+
import { selectOrganizationSchema } from "../../../db/schema/organization.js";
|
|
5
|
+
import { selectUserSchema } from "../../../db/schema/user.js";
|
|
6
|
+
export const createEventSchema = z.object({
|
|
7
|
+
name: selectEventSchema.shape.name,
|
|
8
|
+
description: selectEventSchema.shape.description,
|
|
9
|
+
location: insertLocationSchema,
|
|
10
|
+
type: selectEventSchema.shape.type,
|
|
11
|
+
organizationId: selectEventSchema.shape.organizationId,
|
|
12
|
+
ageGroup: selectEventSchema.shape.ageGroup,
|
|
13
|
+
gender: selectEventSchema.shape.gender,
|
|
14
|
+
}).refine(data => data.location, {
|
|
15
|
+
message: "Location details must be provided",
|
|
16
|
+
});
|
|
17
|
+
// Patch event schema (all fields optional)
|
|
18
|
+
export const patchEventSchema = z.object({
|
|
19
|
+
name: selectEventSchema.shape.name.min(1).optional(),
|
|
20
|
+
description: selectEventSchema.shape.description,
|
|
21
|
+
location: insertLocationSchema.optional(),
|
|
22
|
+
type: selectEventSchema.shape.type.optional(),
|
|
23
|
+
organizationId: selectEventSchema.shape.organizationId.optional(),
|
|
24
|
+
mode: selectEventSchema.shape.mode.optional(),
|
|
25
|
+
ageGroup: selectEventSchema.shape.ageGroup.optional(),
|
|
26
|
+
gender: selectEventSchema.shape.gender,
|
|
27
|
+
status: selectEventSchema.shape.status.optional(),
|
|
28
|
+
});
|
|
29
|
+
// Query schema for list endpoint using Drizzle schema shape
|
|
30
|
+
export const listEventsQuerySchema = z.object({
|
|
31
|
+
status: selectEventSchema.shape.status.optional(),
|
|
32
|
+
type: selectEventSchema.shape.type.optional(),
|
|
33
|
+
organizationId: selectEventSchema.shape.organizationId.optional(),
|
|
34
|
+
});
|
|
35
|
+
// Response schemas with relations
|
|
36
|
+
export const eventWithRelationsSchema = selectEventSchema.extend({
|
|
37
|
+
creator: selectUserSchema.nullable(),
|
|
38
|
+
organization: selectOrganizationSchema.nullable(),
|
|
39
|
+
location: selectLocationSchema.nullable(),
|
|
40
|
+
});
|
|
41
|
+
export const eventResponseSchema = eventWithRelationsSchema;
|
|
42
|
+
export const eventsListResponseSchema = z.array(eventWithRelationsSchema);
|
|
43
|
+
export const countStatsResponseSchema = z.object({
|
|
44
|
+
total: z.number(),
|
|
45
|
+
thisMonth: z.number(),
|
|
46
|
+
upcoming: z.number(),
|
|
47
|
+
inProgress: z.number(),
|
|
48
|
+
completed: z.number(),
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type CreateEventInput, createEventSchema, type EventResponse, eventResponseSchema, type EventsListResponse, eventsListResponseSchema, type ListEventsQuery, listEventsQuerySchema, type PatchEventInput, patchEventSchema, } from "./event.schemas.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createEventSchema, eventResponseSchema, eventsListResponseSchema, listEventsQuerySchema, patchEventSchema, } from "./event.schemas.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../shared/index.js").AppBindings, {
|
|
2
|
+
"/": {
|
|
3
|
+
$get: {
|
|
4
|
+
input: {};
|
|
5
|
+
output: {
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
outputFormat: "text" | "json";
|
|
9
|
+
status: 200;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}, "/">;
|
|
13
|
+
export default router;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createRoute } from "@hono/zod-openapi";
|
|
2
|
+
import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
3
|
+
import { jsonContent } from "stoker/openapi/helpers";
|
|
4
|
+
import { createMessageObjectSchema } from "stoker/openapi/schemas";
|
|
5
|
+
import { createRouter } from "../lib/create-app.js";
|
|
6
|
+
const router = createRouter()
|
|
7
|
+
.openapi(createRoute({
|
|
8
|
+
tags: ["Index"],
|
|
9
|
+
method: "get",
|
|
10
|
+
path: "/",
|
|
11
|
+
responses: {
|
|
12
|
+
[HttpStatusCodes.OK]: jsonContent(createMessageObjectSchema("ESMI API"), "ESMI API Index"),
|
|
13
|
+
},
|
|
14
|
+
}), (c) => {
|
|
15
|
+
return c.json({
|
|
16
|
+
message: "ESMI API",
|
|
17
|
+
}, HttpStatusCodes.OK);
|
|
18
|
+
});
|
|
19
|
+
export default router;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { eq, sql } 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 { event, eventTags, leagues, location, organization, tags, user } from "../../db/schema/index.js";
|
|
6
|
+
export const list = async (c) => {
|
|
7
|
+
const { db } = createDb(c.env);
|
|
8
|
+
const { locationId } = c.req.valid("param");
|
|
9
|
+
const data = await db
|
|
10
|
+
.select({
|
|
11
|
+
name: event.name,
|
|
12
|
+
description: event.description,
|
|
13
|
+
formattedAddress: location.formattedAddress,
|
|
14
|
+
type: event.type,
|
|
15
|
+
organization: {
|
|
16
|
+
name: organization.name,
|
|
17
|
+
description: organization.description,
|
|
18
|
+
ownerName: user.name,
|
|
19
|
+
},
|
|
20
|
+
mode: event.mode,
|
|
21
|
+
ageGroup: event.ageGroup,
|
|
22
|
+
gender: event.gender,
|
|
23
|
+
status: event.status,
|
|
24
|
+
numberOfTeams: leagues.numberOfTeams,
|
|
25
|
+
scheduleDays: leagues.scheduleDays,
|
|
26
|
+
scheduleTimes: leagues.scheduleTimes,
|
|
27
|
+
startDate: leagues.startDate,
|
|
28
|
+
endDate: leagues.endDate,
|
|
29
|
+
season: leagues.season,
|
|
30
|
+
registrationStart: leagues.registrationStart,
|
|
31
|
+
registrationEnd: leagues.registrationEnd,
|
|
32
|
+
teamFee: leagues.teamFee,
|
|
33
|
+
tags: sql `array_agg(json_build_object('id', ${tags.id}, 'name', ${tags.name}))`.as("tags"),
|
|
34
|
+
})
|
|
35
|
+
.from(event)
|
|
36
|
+
.innerJoin(location, eq(event.locationId, location.id))
|
|
37
|
+
.innerJoin(organization, eq(event.organizationId, organization.id))
|
|
38
|
+
.innerJoin(user, eq(organization.ownerId, user.id))
|
|
39
|
+
.innerJoin(eventTags, eq(event.id, eventTags.eventId))
|
|
40
|
+
.innerJoin(tags, eq(eventTags.tagId, tags.id))
|
|
41
|
+
.where(eq(event.locationId, locationId))
|
|
42
|
+
.groupBy(event.id, location.id, organization.id, user.id, leagues.id);
|
|
43
|
+
if (data.length === 0) {
|
|
44
|
+
return c.json({
|
|
45
|
+
message: HttpStatusPhrases.NOT_FOUND,
|
|
46
|
+
}, HttpStatusCodes.NOT_FOUND);
|
|
47
|
+
}
|
|
48
|
+
return c.json(data, HttpStatusCodes.OK);
|
|
49
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shared/index.js").AppBindings, {
|
|
2
|
+
"/leagues/:locationId": {
|
|
3
|
+
$get: {
|
|
4
|
+
input: {
|
|
5
|
+
param: {
|
|
6
|
+
[x: string]: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
output: {
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
outputFormat: "text" | "json";
|
|
13
|
+
status: 404;
|
|
14
|
+
} | {
|
|
15
|
+
input: {
|
|
16
|
+
param: {
|
|
17
|
+
[x: string]: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
output: {
|
|
21
|
+
status: string;
|
|
22
|
+
type: string;
|
|
23
|
+
description: string | null;
|
|
24
|
+
name: string;
|
|
25
|
+
formattedAddress: string;
|
|
26
|
+
organization: {
|
|
27
|
+
description: string;
|
|
28
|
+
name: string;
|
|
29
|
+
ownerName: string;
|
|
30
|
+
};
|
|
31
|
+
mode: string;
|
|
32
|
+
ageGroup: string;
|
|
33
|
+
gender: string;
|
|
34
|
+
tags: {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}[];
|
|
38
|
+
numberOfTeams: number;
|
|
39
|
+
scheduleDays: string | null;
|
|
40
|
+
scheduleTimes: string | null;
|
|
41
|
+
startDate: string;
|
|
42
|
+
endDate: string;
|
|
43
|
+
season: string | null;
|
|
44
|
+
registrationStart: string | null;
|
|
45
|
+
registrationEnd: string | null;
|
|
46
|
+
teamFee: number | null;
|
|
47
|
+
}[];
|
|
48
|
+
outputFormat: "text" | "json";
|
|
49
|
+
status: 200;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}, "/">;
|
|
53
|
+
export default router;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
export declare const list: {
|
|
3
|
+
path: "/leagues/{locationId}";
|
|
4
|
+
method: "get";
|
|
5
|
+
tags: string[];
|
|
6
|
+
request: {
|
|
7
|
+
params: z.ZodObject<{
|
|
8
|
+
[x: string]: z.ZodString;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
[x: string]: string;
|
|
11
|
+
}, {
|
|
12
|
+
[x: string]: string;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
responses: {
|
|
16
|
+
200: {
|
|
17
|
+
content: {
|
|
18
|
+
"application/json": {
|
|
19
|
+
schema: z.ZodArray<z.ZodObject<{
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
description: z.ZodNullable<z.ZodString>;
|
|
22
|
+
formattedAddress: z.ZodString;
|
|
23
|
+
type: z.ZodString;
|
|
24
|
+
organization: z.ZodObject<{
|
|
25
|
+
name: z.ZodString;
|
|
26
|
+
description: z.ZodString;
|
|
27
|
+
ownerName: z.ZodString;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
description: string;
|
|
30
|
+
name: string;
|
|
31
|
+
ownerName: string;
|
|
32
|
+
}, {
|
|
33
|
+
description: string;
|
|
34
|
+
name: string;
|
|
35
|
+
ownerName: string;
|
|
36
|
+
}>;
|
|
37
|
+
mode: z.ZodString;
|
|
38
|
+
ageGroup: z.ZodString;
|
|
39
|
+
gender: z.ZodString;
|
|
40
|
+
status: z.ZodString;
|
|
41
|
+
numberOfTeams: z.ZodNumber;
|
|
42
|
+
scheduleDays: z.ZodNullable<z.ZodString>;
|
|
43
|
+
scheduleTimes: z.ZodNullable<z.ZodString>;
|
|
44
|
+
startDate: z.ZodDate;
|
|
45
|
+
endDate: z.ZodDate;
|
|
46
|
+
season: z.ZodNullable<z.ZodString>;
|
|
47
|
+
registrationStart: z.ZodNullable<z.ZodDate>;
|
|
48
|
+
registrationEnd: z.ZodNullable<z.ZodDate>;
|
|
49
|
+
teamFee: z.ZodNullable<z.ZodNumber>;
|
|
50
|
+
tags: z.ZodArray<z.ZodObject<{
|
|
51
|
+
id: z.ZodString;
|
|
52
|
+
name: z.ZodString;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
}, {
|
|
57
|
+
id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
}>, "many">;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
status: string;
|
|
62
|
+
type: string;
|
|
63
|
+
description: string | null;
|
|
64
|
+
name: string;
|
|
65
|
+
formattedAddress: string;
|
|
66
|
+
organization: {
|
|
67
|
+
description: string;
|
|
68
|
+
name: string;
|
|
69
|
+
ownerName: string;
|
|
70
|
+
};
|
|
71
|
+
mode: string;
|
|
72
|
+
ageGroup: string;
|
|
73
|
+
gender: string;
|
|
74
|
+
tags: {
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
}[];
|
|
78
|
+
numberOfTeams: number;
|
|
79
|
+
scheduleDays: string | null;
|
|
80
|
+
scheduleTimes: string | null;
|
|
81
|
+
startDate: Date;
|
|
82
|
+
endDate: Date;
|
|
83
|
+
season: string | null;
|
|
84
|
+
registrationStart: Date | null;
|
|
85
|
+
registrationEnd: Date | null;
|
|
86
|
+
teamFee: number | null;
|
|
87
|
+
}, {
|
|
88
|
+
status: string;
|
|
89
|
+
type: string;
|
|
90
|
+
description: string | null;
|
|
91
|
+
name: string;
|
|
92
|
+
formattedAddress: string;
|
|
93
|
+
organization: {
|
|
94
|
+
description: string;
|
|
95
|
+
name: string;
|
|
96
|
+
ownerName: string;
|
|
97
|
+
};
|
|
98
|
+
mode: string;
|
|
99
|
+
ageGroup: string;
|
|
100
|
+
gender: string;
|
|
101
|
+
tags: {
|
|
102
|
+
id: string;
|
|
103
|
+
name: string;
|
|
104
|
+
}[];
|
|
105
|
+
numberOfTeams: number;
|
|
106
|
+
scheduleDays: string | null;
|
|
107
|
+
scheduleTimes: string | null;
|
|
108
|
+
startDate: Date;
|
|
109
|
+
endDate: Date;
|
|
110
|
+
season: string | null;
|
|
111
|
+
registrationStart: Date | null;
|
|
112
|
+
registrationEnd: Date | null;
|
|
113
|
+
teamFee: number | null;
|
|
114
|
+
}>, "many">;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
description: string;
|
|
118
|
+
};
|
|
119
|
+
404: {
|
|
120
|
+
content: {
|
|
121
|
+
"application/json": {
|
|
122
|
+
schema: z.ZodObject<{
|
|
123
|
+
message: z.ZodString;
|
|
124
|
+
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
message: string;
|
|
126
|
+
}, {
|
|
127
|
+
message: string;
|
|
128
|
+
}>;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
description: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
} & {
|
|
135
|
+
getRoutingPath(): "/leagues/:locationId";
|
|
136
|
+
};
|
|
137
|
+
export type ListRoute = typeof list;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { selectEventSchema, selectLeaguesSchema, selectLocationSchema, selectOrganizationSchema, selectTagsSchema, selectUserSchema } from "../../db/schema/index.js";
|
|
5
|
+
import { notFoundSchema } from "../../lib/constants.js";
|
|
6
|
+
import { uuidParamsSchema } from "../../lib/openapi-schemas.js";
|
|
7
|
+
const tags = ["Leagues"];
|
|
8
|
+
const leagueSchema = z.object({
|
|
9
|
+
name: selectEventSchema.shape.name,
|
|
10
|
+
description: selectEventSchema.shape.description,
|
|
11
|
+
formattedAddress: selectLocationSchema.shape.formattedAddress,
|
|
12
|
+
type: selectEventSchema.shape.type,
|
|
13
|
+
organization: z.object({
|
|
14
|
+
name: selectOrganizationSchema.shape.name,
|
|
15
|
+
description: selectOrganizationSchema.shape.description,
|
|
16
|
+
ownerName: selectUserSchema.shape.name,
|
|
17
|
+
}),
|
|
18
|
+
mode: selectEventSchema.shape.mode,
|
|
19
|
+
ageGroup: selectEventSchema.shape.ageGroup,
|
|
20
|
+
gender: selectEventSchema.shape.gender,
|
|
21
|
+
status: selectEventSchema.shape.status,
|
|
22
|
+
numberOfTeams: selectLeaguesSchema.shape.numberOfTeams,
|
|
23
|
+
scheduleDays: selectLeaguesSchema.shape.scheduleDays,
|
|
24
|
+
scheduleTimes: selectLeaguesSchema.shape.scheduleTimes,
|
|
25
|
+
startDate: selectLeaguesSchema.shape.startDate,
|
|
26
|
+
endDate: selectLeaguesSchema.shape.endDate,
|
|
27
|
+
season: selectLeaguesSchema.shape.season,
|
|
28
|
+
registrationStart: selectLeaguesSchema.shape.registrationStart,
|
|
29
|
+
registrationEnd: selectLeaguesSchema.shape.registrationEnd,
|
|
30
|
+
teamFee: selectLeaguesSchema.shape.teamFee,
|
|
31
|
+
tags: z.array(z.object({
|
|
32
|
+
id: selectTagsSchema.shape.id,
|
|
33
|
+
name: selectTagsSchema.shape.name,
|
|
34
|
+
})),
|
|
35
|
+
});
|
|
36
|
+
export const list = createRoute({
|
|
37
|
+
path: "/leagues/{locationId}",
|
|
38
|
+
method: "get",
|
|
39
|
+
tags,
|
|
40
|
+
request: {
|
|
41
|
+
params: uuidParamsSchema("locationId"),
|
|
42
|
+
},
|
|
43
|
+
responses: {
|
|
44
|
+
[HttpStatusCodes.OK]: jsonContent(z.array(leagueSchema), "The list of leagues for the given location"),
|
|
45
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent(notFoundSchema, "No leagues found for the given location"),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
2
|
+
import * as HttpStatusPhrases from "stoker/http-status-phrases";
|
|
3
|
+
import { createDb } from "../../db/index.js";
|
|
4
|
+
import { emailCampaign } from "../../db/schema/index.js";
|
|
5
|
+
export const list = async (c) => {
|
|
6
|
+
const { db } = createDb(c.env);
|
|
7
|
+
const emailCampaigns = await db.query.emailCampaign.findMany();
|
|
8
|
+
if (emailCampaigns.length === 0) {
|
|
9
|
+
return c.json({
|
|
10
|
+
message: HttpStatusPhrases.NOT_FOUND,
|
|
11
|
+
}, HttpStatusCodes.NOT_FOUND);
|
|
12
|
+
}
|
|
13
|
+
return c.json(emailCampaigns, HttpStatusCodes.OK);
|
|
14
|
+
};
|
|
15
|
+
export const create = async (c) => {
|
|
16
|
+
const { db } = createDb(c.env);
|
|
17
|
+
const data = c.req.valid("json");
|
|
18
|
+
const [inserted] = await db.insert(emailCampaign).values(data).returning();
|
|
19
|
+
return c.json(inserted, HttpStatusCodes.OK);
|
|
20
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shared/index.js").AppBindings, {
|
|
2
|
+
"/marketing/email": {
|
|
3
|
+
$get: {
|
|
4
|
+
input: {};
|
|
5
|
+
output: {
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
outputFormat: "text" | "json";
|
|
9
|
+
status: 404;
|
|
10
|
+
} | {
|
|
11
|
+
input: {};
|
|
12
|
+
output: {
|
|
13
|
+
id: number;
|
|
14
|
+
email: string;
|
|
15
|
+
createdAt: string | null;
|
|
16
|
+
}[];
|
|
17
|
+
outputFormat: "text" | "json";
|
|
18
|
+
status: 200;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} & {
|
|
22
|
+
"/marketing/email": {
|
|
23
|
+
$post: {
|
|
24
|
+
input: {
|
|
25
|
+
json: {
|
|
26
|
+
email: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
output: {
|
|
30
|
+
error: {
|
|
31
|
+
issues: {
|
|
32
|
+
code: string;
|
|
33
|
+
path: (string | number)[];
|
|
34
|
+
message?: string | undefined;
|
|
35
|
+
}[];
|
|
36
|
+
name: string;
|
|
37
|
+
};
|
|
38
|
+
success: boolean;
|
|
39
|
+
};
|
|
40
|
+
outputFormat: "text" | "json";
|
|
41
|
+
status: 422;
|
|
42
|
+
} | {
|
|
43
|
+
input: {
|
|
44
|
+
json: {
|
|
45
|
+
email: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
output: {
|
|
49
|
+
id: number;
|
|
50
|
+
email: string;
|
|
51
|
+
createdAt: string | null;
|
|
52
|
+
};
|
|
53
|
+
outputFormat: "text" | "json";
|
|
54
|
+
status: 200;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}, "/">;
|
|
58
|
+
export default router;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRouter } from "../../lib/create-app.js";
|
|
2
|
+
import * as handlers from "./marketing.handlers.js";
|
|
3
|
+
import * as routes from "./marketing.routes.js";
|
|
4
|
+
const router = createRouter()
|
|
5
|
+
.openapi(routes.list, handlers.list)
|
|
6
|
+
.openapi(routes.create, handlers.create);
|
|
7
|
+
export default router;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
export declare const list: {
|
|
3
|
+
path: "/marketing/email";
|
|
4
|
+
method: "get";
|
|
5
|
+
tags: string[];
|
|
6
|
+
responses: {
|
|
7
|
+
200: {
|
|
8
|
+
content: {
|
|
9
|
+
"application/json": {
|
|
10
|
+
schema: z.ZodArray<z.ZodObject<{
|
|
11
|
+
id: z.ZodNumber;
|
|
12
|
+
email: z.ZodString;
|
|
13
|
+
createdAt: z.ZodNullable<z.ZodDate>;
|
|
14
|
+
}, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
15
|
+
id: number;
|
|
16
|
+
email: string;
|
|
17
|
+
createdAt: Date | null;
|
|
18
|
+
}, {
|
|
19
|
+
id: number;
|
|
20
|
+
email: string;
|
|
21
|
+
createdAt: Date | null;
|
|
22
|
+
}>, "many">;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
404: {
|
|
28
|
+
content: {
|
|
29
|
+
"application/json": {
|
|
30
|
+
schema: z.ZodObject<{
|
|
31
|
+
message: z.ZodString;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
message: string;
|
|
34
|
+
}, {
|
|
35
|
+
message: string;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
} & {
|
|
43
|
+
getRoutingPath(): "/marketing/email";
|
|
44
|
+
};
|
|
45
|
+
export declare const create: {
|
|
46
|
+
path: "/marketing/email";
|
|
47
|
+
method: "post";
|
|
48
|
+
tags: string[];
|
|
49
|
+
request: {
|
|
50
|
+
body: {
|
|
51
|
+
required: boolean;
|
|
52
|
+
content: {
|
|
53
|
+
"application/json": {
|
|
54
|
+
schema: z.ZodObject<Omit<{
|
|
55
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
email: z.ZodString;
|
|
57
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
58
|
+
}, "id" | "createdAt">, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
59
|
+
email: string;
|
|
60
|
+
}, {
|
|
61
|
+
email: string;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
description: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
responses: {
|
|
69
|
+
200: {
|
|
70
|
+
content: {
|
|
71
|
+
"application/json": {
|
|
72
|
+
schema: z.ZodObject<{
|
|
73
|
+
id: z.ZodNumber;
|
|
74
|
+
email: z.ZodString;
|
|
75
|
+
createdAt: z.ZodNullable<z.ZodDate>;
|
|
76
|
+
}, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
77
|
+
id: number;
|
|
78
|
+
email: string;
|
|
79
|
+
createdAt: Date | null;
|
|
80
|
+
}, {
|
|
81
|
+
id: number;
|
|
82
|
+
email: string;
|
|
83
|
+
createdAt: Date | null;
|
|
84
|
+
}>;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
description: string;
|
|
88
|
+
};
|
|
89
|
+
422: {
|
|
90
|
+
content: {
|
|
91
|
+
"application/json": {
|
|
92
|
+
schema: z.ZodObject<{
|
|
93
|
+
success: z.ZodBoolean;
|
|
94
|
+
error: z.ZodObject<{
|
|
95
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
96
|
+
code: z.ZodString;
|
|
97
|
+
path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
|
|
98
|
+
message: z.ZodOptional<z.ZodString>;
|
|
99
|
+
}, "strip", z.ZodTypeAny, {
|
|
100
|
+
code: string;
|
|
101
|
+
path: (string | number)[];
|
|
102
|
+
message?: string | undefined;
|
|
103
|
+
}, {
|
|
104
|
+
code: string;
|
|
105
|
+
path: (string | number)[];
|
|
106
|
+
message?: string | undefined;
|
|
107
|
+
}>, "many">;
|
|
108
|
+
name: z.ZodString;
|
|
109
|
+
}, "strip", z.ZodTypeAny, {
|
|
110
|
+
issues: {
|
|
111
|
+
code: string;
|
|
112
|
+
path: (string | number)[];
|
|
113
|
+
message?: string | undefined;
|
|
114
|
+
}[];
|
|
115
|
+
name: string;
|
|
116
|
+
}, {
|
|
117
|
+
issues: {
|
|
118
|
+
code: string;
|
|
119
|
+
path: (string | number)[];
|
|
120
|
+
message?: string | undefined;
|
|
121
|
+
}[];
|
|
122
|
+
name: string;
|
|
123
|
+
}>;
|
|
124
|
+
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
error: {
|
|
126
|
+
issues: {
|
|
127
|
+
code: string;
|
|
128
|
+
path: (string | number)[];
|
|
129
|
+
message?: string | undefined;
|
|
130
|
+
}[];
|
|
131
|
+
name: string;
|
|
132
|
+
};
|
|
133
|
+
success: boolean;
|
|
134
|
+
}, {
|
|
135
|
+
error: {
|
|
136
|
+
issues: {
|
|
137
|
+
code: string;
|
|
138
|
+
path: (string | number)[];
|
|
139
|
+
message?: string | undefined;
|
|
140
|
+
}[];
|
|
141
|
+
name: string;
|
|
142
|
+
};
|
|
143
|
+
success: boolean;
|
|
144
|
+
}>;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
description: string;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
} & {
|
|
151
|
+
getRoutingPath(): "/marketing/email";
|
|
152
|
+
};
|
|
153
|
+
export type ListRoute = typeof list;
|
|
154
|
+
export type CreateRoute = typeof create;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRoute, z } from "@hono/zod-openapi";
|
|
2
|
+
import * as HttpStatusCodes from "stoker/http-status-codes";
|
|
3
|
+
import { jsonContent, jsonContentRequired } from "stoker/openapi/helpers";
|
|
4
|
+
import { createErrorSchema } from "stoker/openapi/schemas";
|
|
5
|
+
import { insertEmailCampaignSchema, selectEmailCampaignSchema } from "../../db/schema/index.js";
|
|
6
|
+
import { notFoundSchema } from "../../lib/constants.js";
|
|
7
|
+
export const list = createRoute({
|
|
8
|
+
path: "/marketing/email",
|
|
9
|
+
method: "get",
|
|
10
|
+
tags: ["marketing"],
|
|
11
|
+
responses: {
|
|
12
|
+
[HttpStatusCodes.OK]: jsonContent(z.array(selectEmailCampaignSchema), "The list of email campaigns"),
|
|
13
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent(notFoundSchema, "No email campaigns found"),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
export const create = createRoute({
|
|
17
|
+
path: "/marketing/email",
|
|
18
|
+
method: "post",
|
|
19
|
+
tags: ["marketing"],
|
|
20
|
+
request: {
|
|
21
|
+
body: jsonContentRequired(insertEmailCampaignSchema, "The email campaign to create"),
|
|
22
|
+
},
|
|
23
|
+
responses: {
|
|
24
|
+
[HttpStatusCodes.OK]: jsonContent(selectEmailCampaignSchema, "The email campaign to create"),
|
|
25
|
+
[HttpStatusCodes.UNPROCESSABLE_ENTITY]: jsonContent(createErrorSchema(insertEmailCampaignSchema), "The validation error(s)"),
|
|
26
|
+
},
|
|
27
|
+
});
|