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, andcurrentRedemptionsfrom 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 paramsObjectYes 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
_idfrom the request body and forwarding the remaining fields toDiscountService.updateDiscount(...).Request Body:
{ "method": "DiscountRpc.update", "params": { "_id": "string", // other fields from `DiscountSchema.partial()` } }Parameters:
The request must include
_idas a string. All other fields come from a partial version ofDiscountSchema, but the schema file was not available for inspection, so the full set of optional update fields cannot be confirmed.Name Type Required Description _idStringYes Identifier of the discount to update. paramsObjectYes 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 _idStringYes 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 _idStringYes 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
skipandlimitoptions forDiscountService.listDiscounts(...).Request Body:
{ "method": "DiscountRpc.getData", "params": { "filter": {}, "sort": {}, "page": 1, "pageSize": 20 } }Parameters:
Name Type Required Description filterAnyYes Filter object forwarded to DiscountService.listDiscounts(...).sortAnyYes Sort specification forwarded to DiscountService.listDiscounts(...).pageNumberYes Page number used to calculate the skip offset. pageSizeNumberYes 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 fieldNameStringYes Field name requesting reference values. The implementation does not use this value directly. referenceObjectYes Reference configuration used to build the output mapping. reference.valueFieldStringYes Property name read from each discount object for the returned value.reference.displayFieldStringYes Property name read from each discount object for the returned label.reference.filterObjectNo 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.