Skip to content

Danh mục & Sản phẩm ​

Trang sinh tự động

Phần nghiệp vụ viết tay; API, dữ liệu, quyền, đường dẫn và file nguồn do bộ sinh điền từ source tại ad83b0aea.

Làm gì ​

Cây ngành hàng (tối đa 5 cấp, sản phẩm chỉ gắn vào lá), thương hiệu, đơn vị tính có quy đổi, và sản phẩm — loại thường hoặc combo. Thông số sản phẩm là một catalog riêng theo ngành hàng, thừa kế xuống cây. Có nhập và xuất Excel, giới hạn 1.000 dòng mỗi lần nhập.

Quy mô ​

Domain APIcatalog, product, product-attribute, product-file
Query / Mutation25 / 29
Nguồn dữ liệucatalog
Bảng16
Luật phân quyền3
Đường dẫn Web Admin12

Thao tác (mutation) ​

MutationDomainMô tả
addProductAttributeOptionproduct-attributeAdd an option (drawer, or quick add on the product form, Q4). Requires catalog.write.
bulkRestoreProductsproductRestore 1..500 deleted products in ONE transaction, all or nothing: one
bulkSetProductStatusproductDiscontinue, reactivate or delete the selected products in ONE
createProductAttributeproduct-attributeCreate an attribute (drawer, or the product form popup: saved at once). Requires catalog.write.
deleteBrandcatalogSoft-delete a brand; always allowed, its live products lose the link. Requires catalog.write.
deleteBrandscatalogSoft-delete several brands at once, all or none (TH-US-04 AC03). Brands
deleteCategoriescatalogSoft-delete several categories at once, all or none. Refused, deleting
deleteCategorycatalogSoft-delete a category without live children. Requires catalog.write.
deleteProductAttributeproduct-attributeSoft-delete an attribute no product uses (Xoá hẳn; else conflict attribute_in_use). Requires catalog.write.
deleteProductAttributeOptionproduct-attributeRemove an option no product uses. Requires catalog.write.
deleteProductUnitcatalogSoft-delete an unused unit; conflict{reason: unit_in_use, productCount, usedBy, usage} while anything uses it (usedBy: PRODUCTS, BASE_OF_UNITS, ACCESSORIES, ATTRIBUTES, ATTRIBUTE_VALUES). Requires catalog.write.
exportProductHistoryproductExport the change history of one product (the page filters, newest first, last 24 months) as a private .xlsx.
exportProductsproduct-fileExport every product matching the list filters to .xlsx in one step (no
importProductsproduct-fileValidate or import products from an Excel file (<= 1,000 rows): every
mergeProductAttributeproduct-attributeMerge source into target in one transaction (design §4): values move (or convert), the source is soft-deleted
moveProductAttributeproduct-attributeChuyển vào ngành hàng / Chuyển thành Chung (name taken: conflict duplicate_name). Requires catalog.write.
reorderProductAttributeOptionsproduct-attributeOrder the options. Requires catalog.write.
reorderProductAttributesproduct-attributeOrder the attributes of one category (drag and drop). Requires catalog.write.
restoreProductproductRestore one soft-deleted product as Ngừng bán. Requires catalog.write
saveBrandcatalogCreate or edit a brand. Requires catalog.write.
saveCategorycatalogCreate or edit a category. Requires catalog.write.
saveProductproductCreate (Save draft / Save product) or edit a product. Requires catalog.write.
saveProductColumnPreferenceproductSave the calling Admin's product-list columns ("Áp dụng"; "Đặt lại mặc
saveProductUnitcatalogCreate or edit a product unit. Requires catalog.write.
setProductAttributeOptionStatusproduct-attributeDeactivate or reactivate an option. Requires catalog.write.
setProductStatusproductDiscontinue, reactivate or delete a product. Requires catalog.write.
setProductUnitStatuscatalogDeactivate or reactivate a unit; allowed while products use it (they keep it). Requires catalog.write.
updateProductAttributeproduct-attributeEdit an attribute. Requires catalog.write.
updateProductAttributeOptionproduct-attributeRename an option. Requires catalog.write.

Phép đọc (query) ​

QueryDomainMô tả
brandscatalogFlat list of live brands (WEB_ADMIN); a deleted brand never appears.
catalogKeyAvailabilitycatalogIs a category or brand code / name free among live rows (soft-deleted rows
categoriescatalogCategory tree in tree order, siblings by name A to Z (Vietnamese order). Search is case-insensitive and
categoryDeletePreviewcatalogThe delete popup line 'N thông số sẽ chuyển sang Lưu trữ, M sản phẩm giữ giá trị' (single and batch). Requires catalog.write.
categoryTreecatalogThe whole category tree, not paged (WEB_ADMIN). search: case-insensitive,
deletedProductsproductSoft-deleted products only (WEB_ADMIN, ADD-SP-03); never a live row. Search
previewProductAttributeMergeproduct-attributeCompatibility, counts, conflicts and the unit / option mapping of a merge (wizard step 3). Requires catalog.write.
productproductOne product for the detail/edit screen (SP-US-03): every field, creator and
productAttributeproduct-attributeOne live attribute (drawer). A deleted or merged one is not_found. Requires catalog.read.
productAttributeNameSuggestionsproduct-attributeNear-identical names while typing (unaccented, spaces folded, pg_trgm when available), in the scope of
productAttributesproduct-attributeProduct attributes (WEB_ADMIN), deleted and merged ones never included, with the chip counts. Without forProduct:
productBulkPreviewproductThe SP-US-04 popup before confirming (also for one product, ids: [id]):
productCodeAvailabilityproductDuplicate check while typing / on blur (SP-US-02 AC01, SP-US-03 AC05):
productColumnPreferenceproductThe calling Admin's product-list columns, or the default when none are saved. Requires catalog.read.
productComponentSearchproductProducts that may be added to a combo (SP-US-02 AC04-AC06): standard,
productHistoryproductChange events of one product, newest first (occurredAt, ties by sequence),
productHistoryActorsproductAdmins who changed the product (unfiltered, for the actor filter). Requires catalog.read.
productHistoryRecentproductThe latest events of a product (detail card, default 4, at most 20). Requires catalog.read.
productImportPreflightproduct-fileChecks a chosen file before 'Kiểm tra dữ liệu': not an .xlsx template or
productImportTemplateproduct-fileThe .xlsx import template: sheet 1 'Sản phẩm' (the only sheet the import
productsproductProducts (WEB_ADMIN, SP-US-01), deleted ones never included. Search is
productUnitNameAvailabilitycatalogIs a unit name free among live units (excludeId leaves out the unit being
productUnitOptionscatalogACTIVE units only, A to Z (Vietnamese order), for the product form.
productUnitscatalogLive units (WEB_ADMIN); a deleted unit never appears. search: case-insensitive,
productUnitUnmatchedcatalogOld product unit labels without a unit, most affected live products first.

Dữ liệu ​

Bảng được tham chiếu nhiều nhất trong module:

BảngCộtĐược trỏ tớiRLS
products329✓
product_units156✓
product_attributes214✓
categories163✓
product_attribute_options132✓
brands141✓
product_attribute_values181✓
product_import_runs141✓
combo_components60✓
product_accessories140✓

Quyền ​

MãQuyềnỨng dụngVai tròPhạm viTrạng thái
CAT-01catalog.readWEB_ADMINoperations adminALLPROPOSED
CAT-02catalog.writeWEB_ADMINoperations adminALLPROPOSED
CAT-03catalog.readWEB_ADMINsuper_adminALLPROPOSED

Danh sách đầy đủ và cách đọc các cờ: Ma trận quyền.

Giao diện Web Admin ​

Đường dẫnHằng số
/productsPRODUCTS
/products/:idPRODUCT_DETAIL
/products/:id/editPRODUCT_EDIT
/products/:id/historyPRODUCT_HISTORY
/products/attributesPRODUCT_ATTRIBUTES
/products/brandsPRODUCT_BRANDS
/products/categoriesPRODUCT_CATEGORIES
/products/categories/:idPRODUCT_CATEGORY_DETAIL
/products/deletedPRODUCT_DELETED
/products/importPRODUCT_IMPORT
/products/newPRODUCT_NEW
/products/unitsPRODUCT_UNITS

File nguồn ​

Backend:

  • code/apps/api/supabase/functions/graphql/domains/catalog/
  • code/apps/api/supabase/functions/graphql/domains/product/
  • code/apps/api/supabase/functions/graphql/domains/product-attribute/
  • code/apps/api/supabase/functions/graphql/domains/product-file/

Dữ liệu: bảng thuộc domain catalog — xem Cơ sở dữ liệu.

Sinh từ ad83b0aea · 820 migration · PostgreSQL 17