update IsDeviceIDExisted

This commit is contained in:
Hoang 2021-11-22 16:05:28 +07:00
parent 59d31f5e63
commit 2a9870b3d4
2 changed files with 3 additions and 2 deletions

View File

@ -7,10 +7,11 @@ import (
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
) )
func (s Service) IsDeviceIDExisted(ctx context.Context, deviceID string) bool { func (s Service) IsDeviceIDExisted(deviceID string) bool {
var ( var (
col = s.getDeviceCollection() col = s.getDeviceCollection()
device = Device{} device = Device{}
ctx = context.Background()
) )
if err := col.FindOne(ctx, bson.M{"deviceId": deviceID}).Decode(&device); err != nil { if err := col.FindOne(ctx, bson.M{"deviceId": deviceID}).Decode(&device); err != nil {

View File

@ -40,7 +40,7 @@ func (s Service) Create(payload CreateOptions) error {
deviceData := payload.newDevice() deviceData := payload.newDevice()
// Find deviceID existed or not // Find deviceID existed or not
if s.IsDeviceIDExisted(ctx, deviceData.DeviceID) { if s.IsDeviceIDExisted(deviceData.DeviceID) {
return errors.New("this device is already existed") return errors.New("this device is already existed")
} }