Items API Documentation
This document describes the endpoints for managing lens items in the system.Base URL
All endpoints are prefixed with/items
Authentication
All endpoints require authentication and use the@StoreId() decorator to automatically extract the store ID from the authenticated user’s context.
1. Bulk Delete Items
Delete multiple items in a single request. Only items belonging to the authenticated user’s store can be deleted.Endpoint
Request Body
Request Body Schema
ids(array of strings, required, min 1 item): Array of item IDs to delete- Each ID must be a non-empty string
Response (Success)
Response Schema
message(string): Success message indicating how many items were deleteddeletedCount(number): Number of items successfully deleted
Error Responses
400 Bad Request - No item IDs providedNotes
- Only items that belong to the authenticated user’s store will be deleted
- Already deleted items (soft-deleted) are automatically excluded
- Cascade deletes automatically handle related tables:
- Item variants
- Variants
- Variant values
2. Create Single Lens Item
Create a single lens item with all its variants and variant values. This endpoint creates a complete lens item including the product, item, item variant, and all associated variant values.Endpoint
Request Body
Request Body Schema
indice(string, required): The lens index value (e.g., “1.50”, “1.67”)treatment(string, required): The lens treatment type (e.g., “BB”, “AR”)color(string, optional): The lens color/treatment variant (e.g., “PhGy”, “Blue”, “Green”)sph(object, required): Sphere valuevalue(number, required): The sphere value (e.g., 0.00, 1.25, -2.50)sign(string, required): Either ”+” or ”-”
cly(object, required): Cylinder valuevalue(number, required): The cylinder value (e.g., 0.25, 0.50, -0.75)sign(string, required): Either ”+” or ”-“
Response (Success)
Response Schema
The response contains only essential item data for fast response:id(string): The created item IDname(string): The item name (automatically generated)productId(string): The associated product IDisActive(boolean): Whether the item is activecreatedAt(Date): Creation timestampupdatedAt(Date): Last update timestamp
Error Responses
404 Not Found - Product type ‘LENS’ not foundNotes
- The item name is automatically generated from the provided values in the format:
{indice}{color} {treatment} {sphSign}{sphValue} {clySign}{clyValue} - If no color is provided, the color part is omitted from the name (format:
{indice} {treatment} {sphSign}{sphValue} {clySign}{clyValue}) - Example with color:
1.50 PhGy BB +0.00 +0.25 - Example without color:
1.50 BB +0.00 +0.25 - All operations are performed within a database transaction
- Variant values are automatically created for each variant
- The response is simplified for performance, returning only essential item data
3. Update Lens Item
Update an existing lens item. You can update any combination of the variant values (indice, treatment, color, sph, cly) and the item’s active status.Endpoint
Path Parameters
id(string, required): The ID of the item to update
Request Body Examples
Update only SPH value:Request Body Schema
All fields are optional:indice(string, optional): The lens index valuetreatment(string, optional): The lens treatment type (e.g., “BB”, “AR”)color(string, optional): The lens color/treatment variant (e.g., “PhGy”, “Blue”, “Green”). Set to empty string to remove color variantsph(object, optional): Sphere valuevalue(number, required if sph is provided)sign(string, required if sph is provided): Either ”+” or ”-”
cly(object, optional): Cylinder valuevalue(number, required if cly is provided)sign(string, required if cly is provided): Either ”+” or ”-”
isActive(boolean, optional): Whether the item is active
Response (Success)
Response Schema
Returns only essential item data:id(string): The item IDname(string): The updated item nameproductId(string): The associated product IDisActive(boolean): Whether the item is activecreatedAt(Date): Creation timestampupdatedAt(Date): Last update timestamp
Error Responses
404 Not Found - Item not found or doesn’t belong to storeNotes
- Only items belonging to the authenticated user’s store can be updated
- When variant values are updated, the item name and product title are automatically recalculated
- If the SPH or CYL sign changes, a new variant is created and the old one is deleted
- If color is removed (set to empty string), the color variant is deleted
- If color is added to an item that didn’t have one, a new color variant is created
- All updates are performed within a database transaction
- If no variant values are being updated, only the
isActivestatus can be changed
4. Get Item Variants
Retrieve the variant values for a specific item. This endpoint returns the item’s variant values in a structured format that matches the create/update DTO structure.Endpoint
Path Parameters
id(string, required): The ID of the item to retrieve variants for
Response (Success)
Response Schema
itemId(string): The item IDindice(string): The lens index valuetreatment(string): The lens treatment typecolor(string, optional): The lens color/treatment variant (may be undefined if no color variant exists)sph(object): Sphere valuevalue(number): The sphere valuesign(string): Either ”+” or ”-”
cly(object): Cylinder valuevalue(number): The cylinder valuesign(string): Either ”+” or ”-“
Error Responses
404 Not Found - Item not found or doesn’t belong to storeNotes
- Only items belonging to the authenticated user’s store can be accessed
- The
colorfield will beundefinedif the item doesn’t have a color variant - All numeric values are parsed from the stored variant values
- The sign for SPH and CYL is extracted from the variant name (e.g., ”+ sph” or ”- sph”)
Common Error Responses
401 Unauthorized
500 Internal Server Error
Example cURL Requests
Bulk Delete Items
Create Single Item
Update Item
Get Item Variants
Notes
- Store Context: All endpoints automatically use the authenticated user’s store ID. You don’t need to pass the store ID in the request.
-
Item Naming: Item names are automatically generated from variant values in the format:
- With color:
{indice}{color} {treatment} {sphSign}{sphValue} {clySign}{clyValue}(e.g.,1.50 PhGy BB +0.00 +0.25) - Without color:
{indice} {treatment} {sphSign}{sphValue} {clySign}{clyValue}(e.g.,1.50 BB +0.00 +0.25) - Note: There is no space between indice and color when color is present
- With color:
- Transactions: All operations that modify data are wrapped in database transactions to ensure data consistency.
- Cascade Deletes: When deleting items, related records (item variants, variants, variant values) are automatically deleted due to database cascade constraints.
- Validation: All request bodies are validated using class-validator decorators. Invalid requests will return 400 Bad Request with detailed error messages.