Skip to content

Issue #100: Backend — Orders Module #253

@wumibals

Description

@wumibals

Labels: backend orders nestjs
Area: backend/src/modules/orders/order.entity.ts, backend/src/modules/orders/orders.service.ts, backend/src/modules/orders/orders.controller.ts, backend/src/modules/orders/orders.module.ts
Difficulty: Advanced

Description

While The Lighted's primary ordering flow is via WhatsApp, the platform needs an orders module to track completed orders for analytics, revenue reporting, and loyalty token distribution. Orders are created when a customer confirms their WhatsApp order and an admin marks it as received.

Acceptance Criteria

  • Create backend/src/modules/orders/order.entity.ts:
    • OrderStatus enum: PENDING, CONFIRMED, PREPARING, READY, DELIVERED, CANCELLED
    • OrderItem embedded entity: { menuItemId: string; name: string; price: number; quantity: number }
    • Order entity columns: id (UUID), customerName (varchar), customerPhone (varchar, nullable), customerEmail (varchar, nullable), items (jsonb — OrderItem[]), subtotal (decimal), status (enum, default PENDING), notes (text, nullable), restaurantId (UUID), createdAt, updatedAt
  • Create backend/src/modules/orders/orders.service.ts with OrdersService:
    • create(dto, restaurantId) — calculates subtotal from items, creates order
    • findAll(restaurantId, status?) — ordered createdAt DESC; optionally filtered by status
    • findOne(id, restaurantId) — throws NotFoundException if not found
    • updateStatus(id, status, restaurantId) — updates status, logs to audit
    • getStats(restaurantId, days) — returns { totalOrders, totalRevenue, averageOrderValue, statusBreakdown }
  • Create backend/src/modules/orders/orders.controller.ts with @Controller('orders'):
    • POST /orders — public (no auth), creates order from cart checkout
    • GET /orders@UseGuards(JwtAuthGuard), optional ?status filter
    • GET /orders/stats@UseGuards(JwtAuthGuard), accepts ?days
    • GET /orders/:id@UseGuards(JwtAuthGuard)
    • PUT /orders/:id/status@UseGuards(JwtAuthGuard)
  • Create backend/src/modules/orders/orders.module.ts — exports OrdersService

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions