update IsDeviceIDExisted
This commit is contained in:
parent
59d31f5e63
commit
2a9870b3d4
|
@ -7,10 +7,11 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func (s Service) IsDeviceIDExisted(ctx context.Context, deviceID string) bool {
|
||||
func (s Service) IsDeviceIDExisted(deviceID string) bool {
|
||||
var (
|
||||
col = s.getDeviceCollection()
|
||||
device = Device{}
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
if err := col.FindOne(ctx, bson.M{"deviceId": deviceID}).Decode(&device); err != nil {
|
||||
|
|
|
@ -40,7 +40,7 @@ func (s Service) Create(payload CreateOptions) error {
|
|||
deviceData := payload.newDevice()
|
||||
|
||||
// Find deviceID existed or not
|
||||
if s.IsDeviceIDExisted(ctx, deviceData.DeviceID) {
|
||||
if s.IsDeviceIDExisted(deviceData.DeviceID) {
|
||||
return errors.New("this device is already existed")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue