mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'feat/BE/Sprint-5' of https://gitlab.com/mbugroup/lti-api into dev/teguh
This commit is contained in:
@@ -158,22 +158,13 @@ func (s *expenseService) CreateOne(c *fiber.Ctx, req *validation.Create) (*expen
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nonstockEntity, err := s.NonstockRepo.GetByID(c.Context(), nonstockId, func(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("Suppliers")
|
||||
})
|
||||
// Periksa apakah nonstock terkait dengan supplier
|
||||
supplierFound, err := s.NonstockRepo.IsNonstockAssociatedWithSupplier(c.Context(), nonstockId, req.SupplierID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "Nonstock not found")
|
||||
}
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to get nonstock")
|
||||
}
|
||||
|
||||
supplierFound := false
|
||||
for _, sn := range nonstockEntity.Suppliers {
|
||||
if uint64(sn.Id) == req.SupplierID {
|
||||
supplierFound = true
|
||||
break
|
||||
}
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to check nonstock-supplier relation")
|
||||
}
|
||||
if !supplierFound {
|
||||
return nil, fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Nonstock ID %d does not belong to supplier ID %d", nonstockId, req.SupplierID))
|
||||
|
||||
Reference in New Issue
Block a user