diff --git a/api/assign_device.go b/api/assign_device.go index 3d6676b..5a7a583 100644 --- a/api/assign_device.go +++ b/api/assign_device.go @@ -161,7 +161,7 @@ func (handler *AssignDevice) PutAssignDeviceToHomeRoom(c *gin.Context) { return nil, errClean } - // 5. assign device with id = `deviceID` to room with id = `assignDeviceReq.RoomID` of home with id = `assignDeviceReq.HomeID` + // 5. assign device with id = `deviceID` to room with id = `roomObjID` of home with id = `homeObjID` filterHome := bson.D{bson.E{Key: "_id", Value: homeObjID}} arrayFiltersRoom := options.ArrayFilters{Filters: bson.A{bson.M{"x._id": roomObjID}}} opts := options.UpdateOptions{ @@ -173,8 +173,8 @@ func (handler *AssignDevice) PutAssignDeviceToHomeRoom(c *gin.Context) { }, "$set": bson.M{ "rooms.$[x].modifiedAt": time.Now(), + "modifiedAt": time.Now(), }, - // TODO I should update `modifiedAt` of both `home` and `room` documents } _, errUpdate := handler.collHomes.UpdateOne(sessionCtx, filterHome, update, &opts) if errUpdate != nil { diff --git a/api/register.go b/api/register.go index 9b55f89..dfe1324 100644 --- a/api/register.go +++ b/api/register.go @@ -344,7 +344,7 @@ func (handler *Register) insertDevice(device *models.Device, profile *models.Pro _, errUpd := handler.collProfiles.UpdateOne( sessionCtx, bson.M{"_id": profile.ID}, - bson.M{"$push": bson.M{"devices": device.ID}}, + bson.M{"$addToSet": bson.M{"devices": device.ID}}, ) if errUpd != nil { return nil, customerrors.Wrap(http.StatusInternalServerError, errUpd, "Cannot update profile with the new device") diff --git a/testuutils/db_utils.go b/testuutils/db_utils.go index ac18b80..10ec93f 100644 --- a/testuutils/db_utils.go +++ b/testuutils/db_utils.go @@ -90,7 +90,6 @@ func AssignDeviceToHomeAndRoom(ctx context.Context, collectionHomes *mongo.Colle "$set": bson.M{ "rooms.$[x].modifiedAt": time.Now(), }, - // TODO I should update `modifiedAt` of both `home` and `room` documents } _, err = collectionHomes.UpdateOne(ctx, filterHome, update, &opts) return err