32 lines
915 B
Go
32 lines
915 B
Go
package common
|
|
|
|
import (
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
|
)
|
|
|
|
// ValidateOrganizationIDs verifies that an optional delivery point and staff
|
|
// member belong to the requested gas organization.
|
|
func ValidateOrganizationIDs(gasID, deliveryID, staffID uint64) bool {
|
|
var delivery models.DeliveryBasic
|
|
if deliveryID != 0 {
|
|
if err := impl.DBService.First(&delivery, deliveryID).Error; err != nil {
|
|
return false
|
|
}
|
|
if gasID != 0 && delivery.GasBasicID != 0 && delivery.GasBasicID != gasID {
|
|
return false
|
|
}
|
|
}
|
|
if staffID == 0 {
|
|
return true
|
|
}
|
|
var staff models.StaffAccount
|
|
if err := impl.DBService.First(&staff, staffID).Error; err != nil {
|
|
return false
|
|
}
|
|
if deliveryID != 0 && staff.DeliveryBasicID != deliveryID {
|
|
return false
|
|
}
|
|
return gasID == 0 || staff.GasBasicID == 0 || staff.GasBasicID == gasID
|
|
}
|