2021-11-05 08:40:07 +00:00
|
|
|
package devicemngmt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2022-10-11 07:33:56 +00:00
|
|
|
"git.selly.red/Selly-Modules/logger"
|
|
|
|
"git.selly.red/Selly-Modules/mongodb"
|
2021-11-05 08:40:07 +00:00
|
|
|
)
|
|
|
|
|
2021-11-05 09:57:33 +00:00
|
|
|
func (co CreateOptions) validate() error {
|
2021-11-05 08:40:07 +00:00
|
|
|
// DeviceID
|
|
|
|
if co.DeviceID == "" {
|
2021-11-10 10:08:39 +00:00
|
|
|
logger.Error("devicemngmt - Create: no deviceID data", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.validate",
|
|
|
|
Message: "devicemngmt - Create: no deviceID data",
|
|
|
|
Data: co,
|
2021-11-05 08:40:07 +00:00
|
|
|
})
|
|
|
|
return errors.New("no deviceID data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// IP
|
|
|
|
if co.IP == "" {
|
2021-11-10 10:08:39 +00:00
|
|
|
logger.Error("devicemngmt - Create: no ip data", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.validate",
|
|
|
|
Message: "devicemngmt - Create: no ip data",
|
|
|
|
Data: co,
|
2021-11-05 08:40:07 +00:00
|
|
|
})
|
|
|
|
return errors.New("no ip data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserID
|
|
|
|
if co.UserID == "" {
|
2021-11-10 10:08:39 +00:00
|
|
|
logger.Error("devicemngmt - Create: no userID data", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.validate",
|
|
|
|
Message: "devicemngmt - Create: no userID data",
|
|
|
|
Data: co,
|
2021-11-05 08:40:07 +00:00
|
|
|
})
|
|
|
|
return errors.New("no userID data")
|
|
|
|
}
|
2021-11-22 08:14:36 +00:00
|
|
|
if _, isValid := mongodb.NewIDFromString(co.UserID); !isValid {
|
|
|
|
return errors.New("invalid userID data")
|
|
|
|
}
|
2021-11-05 08:40:07 +00:00
|
|
|
|
|
|
|
// AuthToken
|
|
|
|
if co.AuthToken == "" {
|
2021-11-10 10:08:39 +00:00
|
|
|
logger.Error("devicemngmt - Create: no authToken data", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.validate",
|
|
|
|
Message: "devicemngmt - Create: no authToken data",
|
|
|
|
Data: co,
|
2021-11-05 08:40:07 +00:00
|
|
|
})
|
|
|
|
return errors.New("no authToken data")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-11-08 01:52:10 +00:00
|
|
|
|
|
|
|
func (uo UpdateOptions) validate() error {
|
2021-11-26 10:37:15 +00:00
|
|
|
// UserID
|
|
|
|
if uo.UserID == "" {
|
|
|
|
logger.Error("devicemngmt - Update: no userID data", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.validate",
|
|
|
|
Message: "devicemngmt - Update: no userID data",
|
|
|
|
Data: uo,
|
2021-11-26 10:37:15 +00:00
|
|
|
})
|
|
|
|
return errors.New("no userID data")
|
|
|
|
}
|
|
|
|
if _, isValid := mongodb.NewIDFromString(uo.UserID); !isValid {
|
|
|
|
return errors.New("invalid userID data")
|
|
|
|
}
|
|
|
|
|
2021-11-08 01:52:10 +00:00
|
|
|
// IP
|
|
|
|
if uo.IP == "" {
|
2021-11-10 10:08:39 +00:00
|
|
|
logger.Error("devicemngmt - Update: no ip data", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.validate",
|
|
|
|
Message: "devicemngmt - Update: no ip data",
|
|
|
|
Data: uo,
|
2021-11-08 01:52:10 +00:00
|
|
|
})
|
|
|
|
return errors.New("no ip data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuthToken
|
|
|
|
if uo.AuthToken == "" {
|
2021-11-10 10:08:39 +00:00
|
|
|
logger.Error("devicemngmt - Update: no authToken data", logger.LogData{
|
2022-10-05 10:23:29 +00:00
|
|
|
Source: "devicemngmt.validate",
|
|
|
|
Message: "devicemngmt - Update: no authToken data",
|
|
|
|
Data: uo,
|
2021-11-08 01:52:10 +00:00
|
|
|
})
|
|
|
|
return errors.New("no authToken data")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|