u
This commit is contained in:
@@ -4,6 +4,130 @@ description: >-
|
||||
Reference documentation for backend service.
|
||||
Use this skill whenever working with backend APIs.
|
||||
---
|
||||
# we should cache in client (at least) : company,language,tax,unit,unittext,customergroup,warehouse,account,brand,category,categorytext,attributename,attributevalue,propertyname,companysetting,printer,labeltemplate,posterminal,posterminalcategory
|
||||
|
||||
todos:
|
||||
|
||||
1. Replace 13 List GETs with 1 /bootstrap Endpoint
|
||||
Because these reference tables are cached in memory on login/company-switch and invalidated via GET /events SSE, all individual list endpoints can be merged into a single GET /bootstrap (or folded into GET /auth/me / PUT /auth/selected-company):
|
||||
|
||||
GET /account
|
||||
|
||||
GET /attributename (already returns nested values: T28[] in T16)
|
||||
|
||||
GET /brand (unless you have thousands of brands requiring server pagination)
|
||||
|
||||
GET /carrier
|
||||
|
||||
GET /category/tree
|
||||
|
||||
GET /company & GET /company/setting
|
||||
|
||||
GET /customergroup
|
||||
|
||||
GET /labeltemplate (metadata list without the heavy content.objects array)
|
||||
|
||||
GET /posterminal
|
||||
|
||||
GET /printer
|
||||
|
||||
GET /propertyname
|
||||
|
||||
GET /supplier
|
||||
|
||||
GET /unit
|
||||
|
||||
GET /warehouse
|
||||
|
||||
|
||||
Drop 6 Redundant Single-Item & Child GET Endpoints
|
||||
Once the parent lists above are in the client cache, looking up a single item by ID or key over the network is dead weight:
|
||||
|
||||
Endpoint to Remove,Why It's Redundant with Client Cache
|
||||
GET /attributename/{attributeId}/value,"GET /attributename returns T16[], which already embeds values: T28[]."
|
||||
GET /carrier/{id},Already in cached carriers: T31[].
|
||||
GET /company/setting/{key},Already in cached settings map.
|
||||
GET /printer/{id},Already in cached printers: T22[].
|
||||
GET /warehouse/{id},Already in cached warehouses list.
|
||||
GET /order/{id}/paymentGET /order/{id}/shipmentGET /order/{id}/shipping,"GET /order/{id} returns T1, which already embeds payments: T30[], shipments: T3[], and shippings: T19[]."
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Consolidate Micro-Mutation Endpoints (~20 Routes Saved)
|
||||
Several resources expose separate endpoints for single-column updates or duplicate HTTP verbs. Folding these into their parent PATCH or PUT routes cuts massive routing boilerplate:
|
||||
|
||||
Article single-field setters (Save 4 routes):
|
||||
PUT /article/{sku}/brand, PUT /article/{sku}/track_stock, PUT /article/{sku}/weight, and POST /article/{sku}/parent all return T2/T32. Fold brandId, track_stock, weight, isParent, and attributeNameId directly into PATCH /article/{sku}.
|
||||
|
||||
Article sub-resource getters (Save 4 routes):
|
||||
If you embed attributeValueIds: int[], properties: { propertyId: int, value: str }[], articlelist, and optionslist directly inside T2 (GET /article/{sku}), you can drop GET /article/{sku}/attributevalue, GET /article/{sku}/property, GET /article/{sku}/articlelist, and GET /article/{sku}/optionslist.
|
||||
|
||||
POS Terminal category toggles (Save 4 routes):
|
||||
DELETE /posterminal/{id}/all, PUT /posterminal/{id}/all, DELETE /posterminal/{id}/category/{categoryId}, and PUT /posterminal/{id}/category/{categoryId} can all be replaced by passing categoryIds?: int[] to PATCH /posterminal/{id}.
|
||||
|
||||
|
||||
|
||||
|
||||
Duplicate PUT + PATCH & Export verbs (Save 4 routes):
|
||||
|
||||
labeltemplate/{id}, printer/{id}, and warehouse/{id} each define both PATCH and PUT with identical request bodies and 200 responses. Drop the PUT routes.
|
||||
|
||||
company/export defines both GET and POST for the exact same SSE stream.
|
||||
|
||||
Ledger & Supplier query duplicates (Save 4 routes):
|
||||
|
||||
GET /ledger/manifestarticle/{id} and GET /ledger/sku/{sku} are 100% covered by GET /ledger?manifestarticle_id=...&sku=....
|
||||
|
||||
GET /supplier/{id}/articles?skus=... and POST /supplier/{id}/articles do the exact same thing.
|
||||
|
||||
DELETE /article/{sku}/property/{propertyId} and DELETE /category/{id}/property/{propertyId} are redundant when you already use bulk PUT .../property to replace the property array.
|
||||
|
||||
|
||||
|
||||
|
||||
Unify Document File Attachments (Save 8 Routes)
|
||||
delivery, order, quote, and shipment all repeat identical attachment routes because they are all backed by manifest and manifestattachment in the database:
|
||||
|
||||
GET /{delivery|order|quote|shipment}/{id}/file/{fileId} (4 routes)
|
||||
|
||||
DELETE /{delivery|order|quote|shipment}/{id}/file/{fileId} (4 routes)
|
||||
|
||||
POST /{delivery|order|quote|shipment}/{id}/pdf (4 routes)
|
||||
|
||||
Since file.id is a primary key (or scoped via manifestattachment), you can replace all 8 file routes with GET /file/{fileId} and DELETE /file/{fileId} (saving 6 routes).
|
||||
|
||||
|
||||
|
||||
|
||||
5. Slim Down API Payloads (Stop Joining Cached Data on the Server)
|
||||
Even for endpoints you keep, the client cache lets you remove server-side SQL JOINs and strip redundant strings from your response types:
|
||||
|
||||
T2 (GET /article/{sku}) & GET /category/{id}/articles:
|
||||
|
||||
Currently returns full unit: T27 ({ si, basesi, basesifactor, symbol, name }) and brand: T26 ({ id, name, fullHash, thumbW, thumbH, thumbHash }).
|
||||
|
||||
Reduction: Return only unitId: int (or unitSi: str) and brandId: int|null. The client resolves the unit symbols, conversion factors, brand name, and brand logo hash instantly from the cache.
|
||||
|
||||
GET /article/{sku}/attributevalue & GET /category/{id}/attributevalue:
|
||||
|
||||
Currently joins and returns attributeId, attributeName, value, sort, exclusive.
|
||||
|
||||
Reduction: Return only attributeValueIds: int[]. The client already has the entire attributename -> attributevalue tree cached.
|
||||
|
||||
GET /article/{sku}/property & GET /category/{id}/property:
|
||||
|
||||
Currently joins propertyname to return name: str and exclusive: bool on every property row.
|
||||
|
||||
Reduction: Return { propertyId: int, value: str, sort: int }[] and resolve name and exclusive from the cached propertyname table.
|
||||
|
||||
T11 (articlesupplier) & T19 (shipping):
|
||||
|
||||
Strip supplierName?: str from T11 (resolve via entityId in cached supplier list) and strip carrier?: str from T19 (resolve via carrierId in cached carrier list).
|
||||
|
||||
|
||||
|
||||
|
||||
# Dash API Routes Overview (All)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user