bugs fixed
This commit is contained in:
@@ -350,12 +350,41 @@ func (ctl *OrderController) CreateOrderv3(c *fiber.Ctx) error {
|
||||
data.Deliverytime = time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// An order that does not state its config is an APP order, because that is
|
||||
// the only kind this endpoint takes.
|
||||
//
|
||||
// Every revenue figure in the product filters on `configid = 1` — the
|
||||
// per-branch summary, the tenant revenue summary, the sales summary and the
|
||||
// top-locations list all carry it. An order created with configid 0 is
|
||||
// therefore accepted, deducts stock, appears in the order LIST, and counts
|
||||
// for nothing in any total: the branch reads zero orders and zero revenue
|
||||
// while the stock has genuinely moved.
|
||||
//
|
||||
// Confirmed against live data before defaulting it: every real order across
|
||||
// every tenant carries configid 1. Nothing legitimately arrives here as 0,
|
||||
// so this only ever rescues a caller that forgot the field rather than
|
||||
// relabelling an order that meant something else.
|
||||
if data.Configid == 0 {
|
||||
data.Configid = 1
|
||||
}
|
||||
|
||||
order, err := ctl.orderService.CreateOrder(data)
|
||||
if err != nil {
|
||||
log.Println("CreateOrder service error:", err)
|
||||
// A rejected order is not a server fault, and the status code has to say
|
||||
// so: a client that retries on 5xx will hammer a request that can never
|
||||
// succeed, while a 4xx tells it to fix the request and stop trying.
|
||||
//
|
||||
// "names no outlet" is the caller having omitted locationid, which is
|
||||
// squarely a bad request. It was falling through to the 500 default —
|
||||
// right message, wrong class — because only the stock case was mapped.
|
||||
statusCode := http.StatusInternalServerError
|
||||
if strings.Contains(strings.ToLower(err.Error()), "insufficient stock") {
|
||||
lowered := strings.ToLower(err.Error())
|
||||
switch {
|
||||
case strings.Contains(lowered, "insufficient stock"):
|
||||
statusCode = http.StatusConflict
|
||||
case strings.Contains(lowered, "names no outlet"):
|
||||
statusCode = http.StatusBadRequest
|
||||
}
|
||||
return c.Status(statusCode).JSON(fiber.Map{
|
||||
"code": statusCode,
|
||||
|
||||
Reference in New Issue
Block a user