Prompt file imported from ezzabuzaid/iworked (
.github/prompts/new-route.prompt.md). Copyright stays with the author.
Create new route similar to the existing ones in the apps/backend/routes directory. The new route should follow the same structure and conventions as the existing routes, including:
- Importing necessary modules
- Using validate middleware
- Using authenticated middleware when needed
- Add route to
apps/backend/src/app.ts
Business Logic
-
Make sure to check
packages/persistence/db/schema.prismafor the database schema and ensure that the new route aligns with the existing data models. -
when reasoning about the route business logic you need to make sure it aligns with existing BL.
-
check
apps/backend/src/app.tsto see the global error handling middleware so you do not end up duplicating error handling logic. -
When you want to make sure a record found but you do not want to use it's value, just use
await prisma.modelName.findUniqueOrThrow({ where: { id } })orfindFirstOrThrowwithout try cache unless custom message needed.
Before starting, always ask me what is the route name and purpose.