Merge branch 'feat/BE/Sprint-5' of https://gitlab.com/mbugroup/lti-api into dev/teguh

This commit is contained in:
aguhh18
2025-11-21 10:46:50 +07:00
77 changed files with 1453 additions and 3969 deletions
@@ -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))