CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/postgresql-node-best-practices

PostgreSQL patterns for Node.js with pg — connection pooling, parameterized

99

1.75x
Quality

99%

Does it follow best practices?

Impact

100%

1.75x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-3/

Order Processing System

Problem/Feature Description

A food delivery startup needs an order processing backend built with Node.js, TypeScript, and Express. The service uses PostgreSQL via the pg package. The database is accessible via a DATABASE_URL environment variable.

The system needs to support:

  • Creating a new order: accepts a customer name, delivery address, and a list of order items (each with menu_item_id, quantity, and price_cents). The order and all its items must be saved together atomically -- if any item fails, the entire order must be rolled back.
  • Cancelling an order: sets the order status to "cancelled" and refunds inventory. This also needs to happen atomically.
  • Getting an order by ID, including its items
  • Listing orders by status (received, preparing, ready, delivered, cancelled)

The orders table has: id (serial), customer_name, delivery_address, status (default 'received'), total_cents, created_at, updated_at. The order_items table has: id (serial), order_id (FK), menu_item_id, quantity, price_cents.

Output Specification

Produce:

  • db.ts -- Database connection module
  • orders.ts -- Functions for all four operations listed above
  • package.json -- With required dependencies
  • migrations/001_create_orders.sql -- SQL migration for both tables

The code should be complete TypeScript with no placeholders or TODO comments.

evals

tile.json