CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/mongoose-best-practices

Mongoose and MongoDB patterns — schema design, validation, indexes, virtuals,

99

1.11x
Quality

99%

Does it follow best practices?

Impact

100%

1.11x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-5/

Event Ticketing Platform — Schema Design

Problem/Feature Description

A startup is building an event ticketing platform where users can browse events, purchase tickets, and manage their bookings. The engineering team has been asked to implement the core Mongoose data layer before the first sprint review. The platform needs to handle concurrent ticket purchases (with potential for duplicate email registrations), enforce valid ticket statuses throughout the purchase lifecycle, and make it easy to query upcoming events by category and date.

The team lead has asked you to write the schema definitions for three core models: Event, Ticket, and Session. The Event model holds event metadata and must support efficient queries that filter by category and sort by date. The Ticket model tracks individual ticket purchases tied to an event and must enforce valid status values. The Session model stores short-lived authentication sessions that should expire automatically after 7 days to keep the database clean.

Output Specification

Write a TypeScript file at schemas.ts that exports the three Mongoose schemas and models: Event, Ticket, and Session.

The schemas should reflect realistic field requirements for a ticketing platform. The Event model should have at minimum: a title, a category (from a fixed set of genres), a date, a venue, and a price. The Ticket model should have at minimum: a reference to the event, a buyer email, and a status field with a small set of valid values. The Session model should store a userId and a creation timestamp, and sessions should auto-expire after 7 days.

Include any indexes that would make common queries efficient, and enforce data integrity at the schema level.

evals

tile.json