changes fixed in the catalogue

This commit is contained in:
2026-08-11 17:10:21 +05:30
parent fba42259ea
commit ff72af9a8a
4 changed files with 65 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"nearle/models"
"nearle/services"
@@ -573,10 +574,43 @@ func (ctl *ProductController) ImportCatalogueProduct(c *fiber.Ctx) error {
}
for _, req := range data {
if req.Tenantid == 0 || req.Locationid == 0 || req.Brand == "" || req.Catalogueid == 0 || req.Categoryid == 0 {
// `categoryid` is deliberately NOT required.
//
// Importing adds a product to the admin catalogue and nothing else — it
// reaches no shop and cannot be sold — so there is nothing yet that
// depends on it being classified. The console matches the tenant's own
// category against the catalogue's where one lines up and sends 0 where
// none does, and the admin corrects it there.
//
// Requiring it forced the console to send *something*, and what it sent
// was the tenant's first category regardless of the product. That is
// worse than uncategorised: an unclassified product is visibly
// unfinished, while a wrongly classified one looks done and is only
// found by someone browsing the wrong aisle.
// Named individually rather than as one list of five.
//
// The old message recited every required field whichever one was
// actually missing, so a request rejected for `categoryid: 0` read as
// "catalogueid is required" and sent somebody looking at the wrong
// field entirely. An error that does not say what is wrong costs more
// than the branch it saves.
var missing []string
if req.Tenantid == 0 {
missing = append(missing, "tenantid")
}
if req.Locationid == 0 {
missing = append(missing, "locationid")
}
if req.Brand == "" {
missing = append(missing, "brand")
}
if req.Catalogueid == 0 {
missing = append(missing, "catalogueid")
}
if len(missing) > 0 {
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
"code": http.StatusBadRequest,
"message": "tenantid, locationid, brand, catalogueid, and categoryid are required",
"message": fmt.Sprintf("missing required field(s): %s", strings.Join(missing, ", ")),
"status": false,
})
}
@@ -703,6 +737,10 @@ func (ctl *ProductController) PublishProduct(c *fiber.Ctx) error {
Tenantid int `json:"tenantid"`
Productid int `json:"productid"`
Price float64 `json:"price"`
// Optional. Omitted leaves the product at 0%, which is a real rate for
// staples rather than a missing value — so it is written as given
// rather than skipped when zero.
Taxpercent float64 `json:"taxpercent"`
}
if err := c.BodyParser(&input); err != nil {
@@ -711,7 +749,7 @@ func (ctl *ProductController) PublishProduct(c *fiber.Ctx) error {
})
}
outlets, err := ctl.productService.PublishProduct(input.Tenantid, input.Productid, input.Price)
outlets, err := ctl.productService.PublishProduct(input.Tenantid, input.Productid, input.Price, input.Taxpercent)
if err != nil {
// 400 rather than 500: every failure here is something the caller can
// act on — no price, no outlets, or a product that is not theirs.