rider partner
This commit is contained in:
@@ -710,3 +710,50 @@ func (ctl *TenantController) UpdateOwnProfile(c *fiber.Ctx) error {
|
||||
}
|
||||
return c.JSON(fiber.Map{"code": 200, "status": true, "message": "Success"})
|
||||
}
|
||||
|
||||
// AssignPartner puts a merchant under a delivery partner, or takes them out of
|
||||
// one.
|
||||
//
|
||||
// `partnerid` 0 is a real instruction here — it means "this merchant uses their
|
||||
// own riders" — so it is read as sent rather than treated as absent. Everywhere
|
||||
// else in the tenant API a zero means "not supplied"; this is the exception and
|
||||
// it is the reason the route exists separately.
|
||||
func (ctl *TenantController) AssignPartner(c *fiber.Ctx) error {
|
||||
var body struct {
|
||||
Tenantid int `json:"tenantid"`
|
||||
Partnerid *int `json:"partnerid"`
|
||||
}
|
||||
|
||||
if err := c.BodyParser(&body); err != nil {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest, "status": false, "message": "Invalid request body",
|
||||
})
|
||||
}
|
||||
if tid, _ := strconv.Atoi(c.Query("tenantid")); tid != 0 {
|
||||
body.Tenantid = tid
|
||||
}
|
||||
if body.Tenantid <= 0 {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest, "status": false, "message": "tenantid is required",
|
||||
})
|
||||
}
|
||||
// A pointer, so "no partner" and "field omitted" are different requests.
|
||||
// Sent as a plain int, an omitted field would read as 0 and quietly unassign
|
||||
// a merchant's partner.
|
||||
if body.Partnerid == nil {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest, "status": false,
|
||||
"message": "partnerid is required — send 0 to take the partner away",
|
||||
})
|
||||
}
|
||||
|
||||
if err := ctl.tenantService.AssignPartner(body.Tenantid, *body.Partnerid); err != nil {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest, "status": false, "message": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"code": http.StatusOK, "status": true, "message": "Successfully Updated",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user