{"size": 1059, "ext": "js", "max_stars_repo_path": "packages/medusa/src/api/routes/admin/variants/list-variants.js", "max_stars_repo_name": "sebastiannicolajsen/medusa", "max_stars_repo_stars_event_min_datetime": "2021-11-16T11:11:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T11:11:31.000Z", "max_issues_repo_path": "packages/medusa/src/api/routes/admin/variants/list-variants.js", "max_issues_repo_name": "sebastiannicolajsen/medusa", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/medusa/src/api/routes/admin/variants/list-variants.js", "max_forks_repo_name": "sebastiannicolajsen/medusa", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.0681818182, "max_line_length": 67, "alphanum_fraction": 0.611898017}
import { defaultFields, defaultRelations } from "./"

/**
 * @oas [get] /variants
 * operationId: "GetVariants"
 * summary: "List Product Variants."
 * description: "Retrieves a list of Product Variants"
 * tags:
 *   - Product Variant
 * responses:
 *   200:
 *     description: OK
 *     content:
 *       application/json:
 *         schema:
 *           properties:
 *             variants:
 *               type: array
 *               items:
 *                 $ref: "#/components/schemas/product_variant"
 */
export default async (req, res) => {
  const variantService = req.scope.resolve("productVariantService")

  const limit = parseInt(req.query.limit) || 20
  const offset = parseInt(req.query.offset) || 0

  const selector = {}

  if ("q" in req.query) {
    selector.q = req.query.q
  }

  const listConfig = {
    select: defaultFields,
    relations: defaultRelations,
    skip: offset,
    take: limit,
  }
  const variants = await variantService.list(selector, listConfig)

  res.json({ variants, count: variants.length, offset, limit })
}
