mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
Merge branch 'codex/sales-at-farm-level' into 'development'
codex/fix: hidden product warehouse depletion and egg <= 0 See merge request mbugroup/lti-api!393
This commit is contained in:
@@ -101,6 +101,25 @@ func (s chickinService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
|
||||
}
|
||||
|
||||
func resolveWarehouseForProjectFlockKandang(ctx context.Context, warehouseRepo rWarehouse.WarehouseRepository, kandangID uint, locationID uint) (*entity.Warehouse, error) {
|
||||
if warehouseRepo == nil {
|
||||
return nil, gorm.ErrRecordNotFound
|
||||
}
|
||||
if kandangID == 0 {
|
||||
return nil, gorm.ErrRecordNotFound
|
||||
}
|
||||
if locationID != 0 {
|
||||
warehouse, err := warehouseRepo.GetByKandangIDAndLocationID(ctx, kandangID, locationID)
|
||||
if err == nil {
|
||||
return warehouse, nil
|
||||
}
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return warehouseRepo.GetByKandangID(ctx, kandangID)
|
||||
}
|
||||
|
||||
func (s chickinService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProjectChickin, int64, error) {
|
||||
if err := s.Validate.Struct(params); err != nil {
|
||||
return nil, 0, err
|
||||
@@ -183,7 +202,12 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) ([]enti
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "Project Flock Kandang not found")
|
||||
}
|
||||
|
||||
warehouse, err := s.WarehouseRepo.GetByKandangID(c.Context(), projectFlockKandang.KandangId)
|
||||
warehouse, err := resolveWarehouseForProjectFlockKandang(
|
||||
c.Context(),
|
||||
s.WarehouseRepo,
|
||||
projectFlockKandang.KandangId,
|
||||
projectFlockKandang.ProjectFlock.LocationId,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "Warehouse for Kandang not found")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user