mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
FEAT[BE] :add validation if supplier id not null in transfer stock
This commit is contained in:
@@ -232,11 +232,24 @@ func (s *transferService) CreateOne(c *fiber.Ctx, req *validation.TransferReques
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, delivery := range req.Deliveries {
|
for _, delivery := range req.Deliveries {
|
||||||
// Skip supplier validation if SupplierID is 0 (optional)
|
|
||||||
if delivery.SupplierID == 0 {
|
if delivery.SupplierID == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if delivery.VehiclePlate == "" {
|
||||||
|
return nil, fiber.NewError(fiber.StatusBadRequest, "Vehicle plate wajib diisi ketika supplier dipilih")
|
||||||
|
}
|
||||||
|
if delivery.DriverName == "" {
|
||||||
|
return nil, fiber.NewError(fiber.StatusBadRequest, "Driver name wajib diisi ketika supplier dipilih")
|
||||||
|
}
|
||||||
|
if delivery.DeliveryCost <= 0 {
|
||||||
|
return nil, fiber.NewError(fiber.StatusBadRequest, "Delivery cost harus lebih dari 0 ketika supplier dipilih")
|
||||||
|
}
|
||||||
|
if delivery.DeliveryCostPerItem <= 0 {
|
||||||
|
return nil, fiber.NewError(fiber.StatusBadRequest, "Delivery cost per item harus lebih dari 0 ketika supplier dipilih")
|
||||||
|
}
|
||||||
|
|
||||||
supplier, err := s.SupplierRepo.GetByID(c.Context(), uint(delivery.SupplierID), nil)
|
supplier, err := s.SupplierRepo.GetByID(c.Context(), uint(delivery.SupplierID), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ type TransferDeliveryProduct struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TransferDelivery struct {
|
type TransferDelivery struct {
|
||||||
DeliveryCost float64 `json:"delivery_cost" validate:"required"`
|
DeliveryCost float64 `json:"delivery_cost"`
|
||||||
DeliveryCostPerItem float64 `json:"delivery_cost_per_item" validate:"required"`
|
DeliveryCostPerItem float64 `json:"delivery_cost_per_item"`
|
||||||
DocumentIndex int `json:"document_index" validate:"omitempty,min=-1" default:"-1"`
|
DocumentIndex int `json:"document_index" validate:"omitempty,min=-1" default:"-1"`
|
||||||
DriverName string `json:"driver_name" validate:"required"`
|
DriverName string `json:"driver_name"`
|
||||||
VehiclePlate string `json:"vehicle_plate" validate:"required"`
|
VehiclePlate string `json:"vehicle_plate"`
|
||||||
SupplierID uint `json:"supplier_id" `
|
SupplierID uint `json:"supplier_id" `
|
||||||
Products []TransferDeliveryProduct `json:"products" validate:"required,dive"`
|
Products []TransferDeliveryProduct `json:"products" validate:"required,dive"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user