Files
parsshop-back/docs/brands-api.md
2026-03-26 11:49:21 +03:00

2.3 KiB

Brands API

Base URL: /api

All responses follow the standard wrapper:

{
  "success": true,
  "statusCode": 200,
  "path": "/api/brands",
  "timestamp": "2026-03-26T10:00:00.000Z",
  "data": {}
}

Brand Model

  • id
  • name
  • slug
  • imageUrl
  • type
  • createdAt
  • updatedAt

Public Brand APIs

GET /api/brands

Returns brand list for storefront and admin forms.

GET /api/brands/:id

Returns one brand.

Admin Brand APIs

These endpoints require:

  • Bearer token
  • Admin role
  • brands.manage permission

POST /api/brands

Content type: multipart/form-data

Fields:

  • name
  • slug
  • type
  • existingImageUrl
  • image file

Behavior:

  • if image is uploaded, backend stores it and uses the uploaded URL
  • if existingImageUrl is sent, backend uses that existing media URL

PATCH /api/brands/:id

Content type: multipart/form-data

Fields:

  • name
  • slug
  • type
  • existingImageUrl
  • image file

Behavior:

  • if image is uploaded, old image is replaced
  • if existingImageUrl is sent, selected existing media URL is used
  • if existingImageUrl is empty, image is cleared

DELETE /api/brands/:id

Deletes brand and its image.

Product API Changes

Product create and update now support brand selection by brandId.

  • brandId optional
  • brand optional fallback text

Recommended frontend behavior:

  1. Load brands from GET /api/brands
  2. Let admin select one brand
  3. Send brandId
  4. Do not rely on manual brand text unless you explicitly want a fallback

Product list filters

GET /api/admin/products and GET /api/products now support:

  • brandId
  • brand

brandId is the preferred filter.

Product response

Product responses now include:

  • brand
  • brandInfo

brandInfo shape:

{
  "id": "uuid",
  "name": "SKF",
  "slug": "skf",
  "imageUrl": "https://cdn.example.com/brands/skf.jpg",
  "type": "bearing"
}

Frontend Integration Notes

  • Use brand image in admin selects/cards where useful
  • For add/edit product page, load brands first
  • Filter brands by product type on frontend if needed
  • Use the same media picker flow as categories:
    • either upload a new image
    • or pick an existing media URL and send existingImageUrl