File tree Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ const environmentConfig: EnvironmentConfigType = {
47
47
ValidCorsOrigins : [
48
48
"http://localhost:3000" ,
49
49
"http://localhost:5173" ,
50
+ "https://merch-pwa.pages.dev" ,
50
51
/ ^ h t t p s : \/ \/ (?: .* \. ) ? a c m u i u c \. p a g e s \. d e v $ / ,
51
52
] ,
52
53
AadValidClientId : "39c28870-94e4-47ee-b4fb-affe0bf96c9f" ,
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import fastifyZodValidationPlugin from "./plugins/validate.js";
13
13
import { environmentConfig } from "./config.js" ;
14
14
import organizationsPlugin from "./routes/organizations.js" ;
15
15
import icalPlugin from "./routes/ics.js" ;
16
+ import vendingPlugin from "./routes/vending.js" ;
16
17
17
18
const now = ( ) => Date . now ( ) ;
18
19
@@ -68,6 +69,9 @@ async function init() {
68
69
api . register ( eventsPlugin , { prefix : "/events" } ) ;
69
70
api . register ( organizationsPlugin , { prefix : "/organizations" } ) ;
70
71
api . register ( icalPlugin , { prefix : "/ical" } ) ;
72
+ if ( app . runEnvironment === "dev" ) {
73
+ api . register ( vendingPlugin , { prefix : "/vending" } ) ;
74
+ }
71
75
} ,
72
76
{ prefix : "/api/v1" } ,
73
77
) ;
Original file line number Diff line number Diff line change
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 : "TBD" ,
19
+ image_url :
20
+ "https://acm-brand-images.s3.amazonaws.com/square-blue.png" ,
21
+ price : 400 ,
22
+ calories : null ,
23
+ fat : null ,
24
+ carbs : null ,
25
+ fiber : null ,
26
+ sugar : null ,
27
+ protein : null ,
28
+ quantity : 100 ,
29
+ locations : null ,
30
+ } ,
31
+ ] ,
32
+ } ) ;
33
+ } ) ;
34
+ fastify . post < { Body : VendingItemPostRequest } > (
35
+ "/items" ,
36
+ {
37
+ preValidation : async ( request , reply ) => {
38
+ await fastify . zodValidateBody ( request , reply , postSchema ) ;
39
+ } ,
40
+ } ,
41
+ async ( request , reply ) => {
42
+ reply . send ( { status : "Not implemented." } ) ;
43
+ } ,
44
+ ) ;
45
+ } ;
46
+
47
+ export default vendingPlugin ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments