From 2a9870b3d419635946c87d0d63f32a735b368d8b Mon Sep 17 00:00:00 2001 From: Hoang Date: Mon, 22 Nov 2021 16:05:28 +0700 Subject: [PATCH] update IsDeviceIDExisted --- action_check_exists.go | 3 ++- action_create.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/action_check_exists.go b/action_check_exists.go index 14ae682..bc807f5 100644 --- a/action_check_exists.go +++ b/action_check_exists.go @@ -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 { diff --git a/action_create.go b/action_create.go index 79a9663..832ae1e 100644 --- a/action_create.go +++ b/action_create.go @@ -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") }