|
|
@@ -475,6 +475,18 @@ func (s *ClientService) Create(inboundSvc *InboundService, payload *ClientCreate
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if client.SubID != "" {
|
|
|
+ var subTaken int64
|
|
|
+ if err := database.GetDB().Model(&model.ClientRecord{}).
|
|
|
+ Where("sub_id = ? AND email <> ?", client.SubID, client.Email).
|
|
|
+ Count(&subTaken).Error; err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+ if subTaken > 0 {
|
|
|
+ return false, common.NewError("subId already in use:", client.SubID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
needRestart := false
|
|
|
for _, ibId := range payload.InboundIds {
|
|
|
inbound, getErr := inboundSvc.GetInbound(ibId)
|
|
|
@@ -646,6 +658,18 @@ func (s *ClientService) Update(inboundSvc *InboundService, id int, updated model
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if updated.SubID != "" {
|
|
|
+ var subCollision int64
|
|
|
+ if err := database.GetDB().Model(&model.ClientRecord{}).
|
|
|
+ Where("sub_id = ? AND id <> ?", updated.SubID, id).
|
|
|
+ Count(&subCollision).Error; err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+ if subCollision > 0 {
|
|
|
+ return false, common.NewError("Duplicate subId:", updated.SubID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
needRestart := false
|
|
|
for _, ibId := range inboundIds {
|
|
|
inbound, getErr := inboundSvc.GetInbound(ibId)
|