CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/prisma-best-practices

Prisma ORM patterns — schema design, migrations, type-safe queries, testing, error handling, and performance

96

1.28x
Quality

95%

Does it follow best practices?

Impact

100%

1.28x

Average score across 3 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-2/

Order Management API — Data Access Layer

Problem/Feature Description

A restaurant management platform needs a TypeScript data access module for handling orders. The team has an existing Prisma setup and needs well-structured service functions that handle the common operations: listing orders for a dashboard view, fetching a single order's full details, placing a new order (creating the order and its line items atomically), and bulk-cancelling stale orders that were never picked up.

The dashboard shows a compact list of orders (no product details needed), while the order detail page needs the full order record with all line items and their associated products. The team has been bitten by slow queries in the past from loading too much data and from hitting the database multiple times per record in a loop. They also need the order placement to be crash-safe — if anything fails mid-creation (e.g., a product no longer exists), nothing should be partially written.

Additionally, the team expects the service to gracefully report when a requested order doesn't exist, rather than crashing with an unhandled database exception.

Output Specification

Produce a TypeScript file src/order-service.ts that exports the following functions:

  • listOrders() — returns a list of orders for a dashboard view
  • getOrderDetail(orderId: number) — returns one order with all line items and product info; throws a typed error if not found
  • placeOrder(input: { customerName: string; items: Array<{ productId: number; quantity: number; priceCents: number }> }) — creates an order and all its items atomically
  • cancelStaleOrders(cutoffDate: Date) — bulk-cancels all orders in RECEIVED status created before the cutoff

Also produce a lib/prisma.ts file containing the shared Prisma client used by the service.

Assume a schema with Order, OrderItem, and Product models (similar to a café ordering system). Include type imports from @prisma/client where needed. You do not need to install packages or run migrations — just write the TypeScript source files.

evals

tile.json