Skip to content

Commit b5125de

Browse files
committed
Merge branch 'main' into discord-integration
2 parents d27cbd4 + 0bdca5b commit b5125de

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const environmentConfig: EnvironmentConfigType = {
4747
ValidCorsOrigins: [
4848
"http://localhost:3000",
4949
"http://localhost:5173",
50+
"https://merch-pwa.pages.dev",
51+
"https://manage.qa.acmuiuc.org",
5052
/^https:\/\/(?:.*\.)?acmuiuc\.pages\.dev$/,
5153
],
5254
AadValidClientId: "39c28870-94e4-47ee-b4fb-affe0bf96c9f",

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import fastifyZodValidationPlugin from "./plugins/validate.js";
1313
import { environmentConfig } from "./config.js";
1414
import organizationsPlugin from "./routes/organizations.js";
1515
import icalPlugin from "./routes/ics.js";
16+
import vendingPlugin from "./routes/vending.js";
1617

1718
const now = () => Date.now();
1819

@@ -68,6 +69,9 @@ async function init() {
6869
api.register(eventsPlugin, { prefix: "/events" });
6970
api.register(organizationsPlugin, { prefix: "/organizations" });
7071
api.register(icalPlugin, { prefix: "/ical" });
72+
if (app.runEnvironment === "dev") {
73+
api.register(vendingPlugin, { prefix: "/vending" });
74+
}
7175
},
7276
{ prefix: "/api/v1" },
7377
);

src/routes/vending.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { FastifyPluginAsync } from "fastify";
2+
import { z } from "zod";
3+
4+
const postSchema = z.object({
5+
name: z.string().min(1),
6+
imageUrl: z.string().url(),
7+
price: z.number().min(0),
8+
});
9+
10+
type VendingItemPostRequest = z.infer<typeof postSchema>;
11+
12+
const vendingPlugin: FastifyPluginAsync = async (fastify, _options) => {
13+
fastify.get("/items", async (request, reply) => {
14+
reply.send({
15+
items: [
16+
{
17+
rowid: 1,
18+
name: "A Picture of Ronit",
19+
image_url: "https://acm-brand-images.s3.amazonaws.com/ronit.jpeg",
20+
price: 999,
21+
calories: null,
22+
fat: null,
23+
carbs: null,
24+
fiber: null,
25+
sugar: null,
26+
protein: null,
27+
quantity: 100,
28+
locations: null,
29+
},
30+
],
31+
});
32+
});
33+
fastify.post<{ Body: VendingItemPostRequest }>(
34+
"/items",
35+
{
36+
preValidation: async (request, reply) => {
37+
await fastify.zodValidateBody(request, reply, postSchema);
38+
},
39+
},
40+
async (request, reply) => {
41+
reply.send({ status: "Not implemented." });
42+
},
43+
);
44+
};
45+
46+
export default vendingPlugin;

tests/unit/vending.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from "vitest";
2+
import init from "../../src/index.js";
3+
4+
const app = await init();
5+
test("Test getting events", async () => {
6+
const response = await app.inject({
7+
method: "GET",
8+
url: "/api/v1/vending/items",
9+
});
10+
expect(response.statusCode).toBe(200);
11+
});

0 commit comments

Comments
 (0)