mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE): add validation for product category based on flock category in CreateOne method
This commit is contained in:
@@ -156,6 +156,25 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) ([]enti
|
|||||||
return nil, fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Product warehouse %d belongs to different flock. Only product warehouses with project_flock_kandang_id = NULL or = %d can be used", chickinReq.ProductWarehouseId, req.ProjectFlockKandangId))
|
return nil, fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Product warehouse %d belongs to different flock. Only product warehouses with project_flock_kandang_id = NULL or = %d can be used", chickinReq.ProductWarehouseId, req.ProjectFlockKandangId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CRITICAL: Validate product category based on flock category
|
||||||
|
// GROWING: Input DOC, Output PULLET
|
||||||
|
// LAYING: Input PULLET, Output LAYER
|
||||||
|
if productWarehouse.Product.Id != 0 {
|
||||||
|
productCategoryCode := productWarehouse.Product.ProductCategory.Code
|
||||||
|
var allowedCategory string
|
||||||
|
if projectFlockKandang.ProjectFlock.Category == string(utils.ProjectFlockCategoryGrowing) {
|
||||||
|
allowedCategory = "DOC"
|
||||||
|
} else if projectFlockKandang.ProjectFlock.Category == string(utils.ProjectFlockCategoryLaying) {
|
||||||
|
allowedCategory = "PULLET"
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("invalid flock category for chickin")
|
||||||
|
}
|
||||||
|
|
||||||
|
if productCategoryCode != allowedCategory {
|
||||||
|
return nil, fmt.Errorf("product warehouse %d cannot be used for %s chickin. Only %s products can be used as input (current: %s)", chickinReq.ProductWarehouseId, projectFlockKandang.ProjectFlock.Category, allowedCategory, productCategoryCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chickinDate, err := utils.ParseDateString(chickinReq.ChickInDate)
|
chickinDate, err := utils.ParseDateString(chickinReq.ChickInDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Invalid ChickInDate format for product warehouse %d", chickinReq.ProductWarehouseId))
|
return nil, fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Invalid ChickInDate format for product warehouse %d", chickinReq.ProductWarehouseId))
|
||||||
|
|||||||
Reference in New Issue
Block a user