Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema): Define initial entities and relationships in Prisma dat… #92

Merged
merged 17 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
# Since .env is gitignored, you can use .env.example to build a new `.env` file when you clone the repo.
# Keep this file up-to-date when you add new variables to \`.env\`.

# This file will be committed to version control, so make sure not to have any secrets in it.
# If you are cloning this repo, create a copy of this file named `.env` and populate it with your secrets.

# The database URL is used to connect to your PlanetScale database.
DATABASE_URL=''

# @see https://next-auth.js.org/configuration/options#nextauth_url
AUTH_URL='http://localhost:3000'
AUTH_REDIRECT_PROXY_URL="http://localhost:3001/api"

# You can generate the secret via 'openssl rand -base64 32' on Unix
# @see https://next-auth.js.org/configuration/options#secret
AUTH_SECRET='supersecret'

# Preconfigured Discord OAuth provider, works out-of-the-box
# @see https://next-auth.js.org/providers/discord
AUTH_DISCORD_ID=''
AUTH_DISCORD_SECRET=''
DATABASE_URL=""
Empty file added .turbo/cookies/0.cookie
Empty file.
Empty file added .turbo/cookies/1.cookie
Empty file.
Empty file added .turbo/cookies/2.cookie
Empty file.
Empty file added .turbo/cookies/3.cookie
Empty file.
Empty file added .turbo/cookies/4.cookie
Empty file.
4 changes: 2 additions & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "serverless.ts",
"scripts": {
"dev": "sls offline --noPrependStageInUrl",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npx jest"
},
"engines": {
"node": ">=14.15.0"
Expand All @@ -23,4 +23,4 @@
"serverless-esbuild": "^1.51.0",
"serverless-offline": "^13.3.3"
}
}
}
7 changes: 0 additions & 7 deletions apps/server/src/functions/hello/schema.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/server/src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AWS } from "@serverless/typescript";

export const functions: AWS["functions"] = {
hello: {
handler: "src/functions/hello/handler.main",
handler: "src/functions/trpc/handler.main",
description: "Lambda function to say hello",
memorySize: 256,
events: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {
awsLambdaRequestHandler,
CreateAWSLambdaContextOptions,
} from "@trpc/server/adapters/aws-lambda";
import { appRouter, createTRPCContext } from "@zotmeal/api";
import { APIGatewayProxyEventV2 } from "aws-lambda";

import { appRouter, createTRPCContext } from "@zotmeal/api";

const createContext = ({
event,
context,
Expand All @@ -20,15 +21,4 @@ export const handler = awsLambdaRequestHandler({
createContext,
});

// const handler = async (event) => {
// const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
// return {
// statusCode: 200,
// body: JSON.stringify({
// message: `Hello ${"hello"} !`,
// data: res.data,
// }),
// };
// };

export const main = handler;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean:workspaces": "turbo clean",
"db:push": "pnpm -F db push",
"db:studio": "pnpm -F db studio",
"dev": "turbo dev --parallel",
"dev": "turbo dev --parallel ",
"format": "turbo format --continue -- --cache --cache-location node_modules/.cache/.prettiercache",
"format:fix": "turbo format --continue -- --write --cache --cache-location node_modules/.cache/.prettiercache",
"lint": "turbo lint --continue -- --cache --cache-location node_modules/.cache/.eslintcache",
Expand All @@ -34,4 +34,4 @@
"@auth/core": "0.20.0"
}
}
}
}
7 changes: 5 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
"scripts": {
"dev": "echo 'Add dev script here'",
"build": "echo 'Add build script here'",
"test": "echo 'Add test script here'",
"test": "vitest",
"lint": "echo 'Add lint script here'"
},
"dependencies": {
"@trpc/server": "11.0.0-next-beta.236",
"@zotmeal/db": "workspace:^",
"@zotmeal/eslint-config": "workspace:^",
"@zotmeal/prettier-config": "workspace:^",
"@zotmeal/tsconfig": "workspace:^",
"@zotmeal/utils": "workspace:^",
"@zotmeal/validators": "workspace:^",
"date-fns": "^3.3.1",
"superjson": "2.2.1",
"vitest": "^1.2.2",
"zod": "^3.22.4"
},
"eslintConfig": {
Expand All @@ -25,4 +28,4 @@
]
},
"prettier": "@zotmeal/prettier-config"
}
}
1 change: 0 additions & 1 deletion packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ type RouterInputs = inferRouterInputs<AppRouter>;
**/
type RouterOutputs = inferRouterOutputs<AppRouter>;

export * from "./parse";
export { createTRPCContext, appRouter, createCaller };
export type { AppRouter, RouterInputs, RouterOutputs };
96 changes: 0 additions & 96 deletions packages/api/src/parse.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/api/src/root.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { menuRouter } from "./router/menu";
import { postRouter } from "./router/post";
import { createTRPCRouter } from "./trpc";

export const appRouter = createTRPCRouter({
post: postRouter,
menu: menuRouter,
});

Expand Down
36 changes: 0 additions & 36 deletions packages/api/src/router/menu.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/api/src/router/menu/get.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, it } from "vitest";

describe("", () => {
it("", () => {
console.log("");
});
});
61 changes: 61 additions & 0 deletions packages/api/src/router/menu/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { TRPCError } from "@trpc/server";
import { parse } from "date-fns";
import { z } from "zod";

import { MenuPeriod, RestaurantName } from "@zotmeal/db";

import { publicProcedure } from "../../trpc";

export const GetMenuSchema = z.object({
date: z.string().regex(RegExp("/^d{2}/d{2}/d{4}$/")),
period: z.nativeEnum(MenuPeriod),
restaurant: z.nativeEnum(RestaurantName),
});

export const getMenuProcedure = publicProcedure
.input(GetMenuSchema)
.query(async ({ ctx, input }) => {
// get a menu
const { date: dateString, period, restaurant: restaurantName } = input;
const { db } = ctx;
const restaurant = await db.restaurant.findFirst({
where: {
name: restaurantName,
},
include: {
stations: false,
menu: false,
},
});

// should 404
if (restaurant === null) {
throw new TRPCError({
message: "restaurant not found",
code: "NOT_FOUND",
});
}

const date = parse(dateString, "MM/dd/yyyy", new Date());
if (!date) {
throw new TRPCError({
message: `invalid date string ${dateString}`,
code: "BAD_REQUEST",
});
}
const menu = await db.menu.findFirst({
where: {
restaurantId: restaurant.id,
date: date,
period: period,
},
});
if (!menu) {
throw new TRPCError({
message: `menu not found`,
code: "NOT_FOUND",
});
}

return menu;
});
38 changes: 38 additions & 0 deletions packages/api/src/router/menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from "axios";

import { createTRPCRouter, publicProcedure } from "../../trpc";
import { getMenuProcedure } from "./get";
import { parseMenuProcedure } from "./parse";

// import { createTRPCRouter, publicProcedure } from "../trpc";
// import { parseCampusDish } from "./parse";

const helloProcedure = publicProcedure.query(async (opts) => {
const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
const _ = opts;
console.log(res.data);
console.log("hello");
return "hello";
});

export const menuRouter = createTRPCRouter({
get: getMenuProcedure,
hello: helloProcedure,
parse: parseMenuProcedure,
// parse: publicProcedure.query(async ({ ctx }) => {
// const res = await axios.get(
// "https://uci-campusdish-com.translate.goog/api/menu/GetMenus?locationId=3314&periodId=49&date=1/19/2024",
// );
// try {
// const validated = CampusDishResponseSchema.parse(res.data);
// const parsed = ParsedResponseSchema.parse(parseCampusDish(validated));
// const _ = ctx;
// return parsed;
// } catch (error) {
// if (error instanceof z.ZodError) {
// console.log(error.issues);
// }
// throw error;
// }
// }),
});
Loading
Loading