AppMage

Discounts

This endpoint group provides RPC methods for creating, updating, deactivating, looking up, and listing discounts. It also includes a reference-data helper for populating UI fields with discount value/label pairs.

Endpoints

POST /api/rpc (Method: DiscountRpc.create)

  • Description: Creates a discount by forwarding the validated request data to DiscountService.createDiscount(...).

  • Request Body:

    {
      "method": "DiscountRpc.create",
      "params": {
        // fields from `DiscountSchema` except `_id`, `createdAt`, `updatedAt`, and `currentRedemptions`
      }
    }
  • Parameters:

    The exact field list is defined by DiscountSchema, but the RPC explicitly excludes _id, createdAt, updatedAt, and currentRedemptions from the accepted input. Because the schema file was not available for inspection, the remaining required and optional fields cannot be stated here with certainty.

    Name Type Required Description
    params Object Yes Discount creation payload validated against the schema derived from DiscountSchema.omit(...).
  • Response:

    {
      "success": true,
      "data": {
        // result returned by `DiscountService.createDiscount(...)`
      }
    }
  • Example (cURL):

    curl -X POST "${APP_BASE_URL}/api/rpc" \
      -H "Content-Type: application/json" \
      -d '{
        "method": "DiscountRpc.create",
        "params": {
          "...": "..."
        }
      }'

POST /api/rpc (Method: DiscountRpc.update)

  • Description: Updates an existing discount by extracting _id from the request body and forwarding the remaining fields to DiscountService.updateDiscount(...).

  • Request Body:

    {
      "method": "DiscountRpc.update",
      "params": {
        "_id": "string",
        // other fields from `DiscountSchema.partial()`
      }
    }
  • Parameters:

    The request must include _id as a string. All other fields come from a partial version of DiscountSchema, but the schema file was not available for inspection, so the full set of optional update fields cannot be confirmed.

    Name Type Required Description
    _id String Yes Identifier of the discount to update.
    params Object Yes Discount update payload validated against DiscountSchema.partial().extend({ _id: z.string() }).
  • Response:

    {
      "success": true,
      "data": {
        // result returned by `DiscountService.updateDiscount(...)`
      }
    }
  • Example (cURL):

    curl -X POST "${APP_BASE_URL}/api/rpc" \
      -H "Content-Type: application/json" \
      -d '{
        "method": "DiscountRpc.update",
        "params": {
          "_id": "discount-id",
          "...": "..."
        }
      }'

POST /api/rpc (Method: DiscountRpc.delete)

  • Description: Deactivates a discount using DiscountService.deactivateDiscount(...) and returns a success message. The source comments identify this as a soft delete.

  • Request Body:

    {
      "method": "DiscountRpc.delete",
      "params": {
        "_id": "string"
      }
    }
  • Parameters:

    Name Type Required Description
    _id String Yes Identifier of the discount to deactivate.
  • Response:

    {
      "success": true,
      "data": {
        "success": true,
        "message": "Discount deactivated."
      }
    }
  • Example (cURL):

    curl -X POST "${APP_BASE_URL}/api/rpc" \
      -H "Content-Type: application/json" \
      -d '{
        "method": "DiscountRpc.delete",
        "params": {
          "_id": "discount-id"
        }
      }'

POST /api/rpc (Method: DiscountRpc.findById)

  • Description: Retrieves a discount by identifier through DiscountService.getDiscountById(...).

  • Request Body:

    {
      "method": "DiscountRpc.findById",
      "params": {
        "_id": "string"
      }
    }
  • Parameters:

    Name Type Required Description
    _id String Yes Identifier of the discount to retrieve.
  • Response:

    {
      "success": true,
      "data": {
        // result returned by `DiscountService.getDiscountById(...)`
      }
    }
  • Example (cURL):

    curl -X POST "${APP_BASE_URL}/api/rpc" \
      -H "Content-Type: application/json" \
      -d '{
        "method": "DiscountRpc.findById",
        "params": {
          "_id": "discount-id"
        }
      }'

POST /api/rpc (Method: DiscountRpc.getData)

  • Description: Returns a paginated list of discounts by converting the incoming page arguments into skip and limit options for DiscountService.listDiscounts(...).

  • Request Body:

    {
      "method": "DiscountRpc.getData",
      "params": {
        "filter": {},
        "sort": {},
        "page": 1,
        "pageSize": 20
      }
    }
  • Parameters:

    Name Type Required Description
    filter Any Yes Filter object forwarded to DiscountService.listDiscounts(...).
    sort Any Yes Sort specification forwarded to DiscountService.listDiscounts(...).
    page Number Yes Page number used to calculate the skip offset.
    pageSize Number Yes Maximum number of items to return.
  • Response:

    {
      "success": true,
      "data": {
        // result returned by `DiscountService.listDiscounts(...)`
      }
    }
  • Example (cURL):

    curl -X POST "${APP_BASE_URL}/api/rpc" \
      -H "Content-Type: application/json" \
      -d '{
        "method": "DiscountRpc.getData",
        "params": {
          "filter": {},
          "sort": {},
          "page": 1,
          "pageSize": 20
        }
      }'

POST /api/rpc (Method: DiscountRpc.getFieldValues)

  • Description: Provides reference values for discount-backed fields by querying up to 1000 discounts and mapping each result to a { value, label } object.

  • Request Body:

    {
      "method": "DiscountRpc.getFieldValues",
      "params": {
        "fieldName": "string",
        "reference": {
          "valueField": "string",
          "displayField": "string",
          "filter": {}
        }
      }
    }
  • Parameters:

    Name Type Required Description
    fieldName String Yes Field name requesting reference values. The implementation does not use this value directly.
    reference Object Yes Reference configuration used to build the output mapping.
    reference.valueField String Yes Property name read from each discount object for the returned value.
    reference.displayField String Yes Property name read from each discount object for the returned label.
    reference.filter Object No Optional filter object passed to DiscountService.listDiscounts(...); defaults to {} when omitted.
  • Response:

    {
      "success": true,
      "data": [
        {
          "value": "string",
          "label": "string"
        }
      ]
    }
  • Example (cURL):

    curl -X POST "${APP_BASE_URL}/api/rpc" \
      -H "Content-Type: application/json" \
      -d '{
        "method": "DiscountRpc.getFieldValues",
        "params": {
          "fieldName": "discountId",
          "reference": {
            "valueField": "_id",
            "displayField": "name",
            "filter": {}
          }
        }
      }'

Request Validation and Processing

The endpoint methods are defined with @rpcMethod(...) schemas, which means the RPC runtime validates incoming params before invoking the handler. The create and update schemas are derived from DiscountSchema, but the source for that schema was not available here, so the complete field-level contract cannot be documented beyond what is explicitly shown in this file.

Data Flow

graph TD A[Client calls POST /api/rpc] --> B[RPC runtime validates params] B --> C{Method} C --> D[DiscountRpc.create] C --> E[DiscountRpc.update] C --> F[DiscountRpc.delete] C --> G[DiscountRpc.findById] C --> H[DiscountRpc.getData] C --> I[DiscountRpc.getFieldValues] D --> J[DiscountService.createDiscount] E --> K[DiscountService.updateDiscount] F --> L[DiscountService.deactivateDiscount] G --> M[DiscountService.getDiscountById] H --> N[DiscountService.listDiscounts] I --> O[DiscountService.listDiscounts] O --> P[Map results to value/label pairs]