update deviceModel
This commit is contained in:
		
							parent
							
								
									09cc989cc8
								
							
						
					
					
						commit
						b3a42ef4b2
					
				| 
						 | 
					@ -63,6 +63,7 @@ func (payload CreateOptions) newDevice() Device {
 | 
				
			||||||
	// Get userAgent data
 | 
						// Get userAgent data
 | 
				
			||||||
	osName, osVersion, isMobile := getUserAgentData(payload.UserAgent)
 | 
						osName, osVersion, isMobile := getUserAgentData(payload.UserAgent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						userID, _ := mongodb.NewIDFromString(payload.UserID)
 | 
				
			||||||
	return Device{
 | 
						return Device{
 | 
				
			||||||
		ID:              mongodb.NewObjectID(),
 | 
							ID:              mongodb.NewObjectID(),
 | 
				
			||||||
		DeviceID:        payload.DeviceID,
 | 
							DeviceID:        payload.DeviceID,
 | 
				
			||||||
| 
						 | 
					@ -76,7 +77,7 @@ func (payload CreateOptions) newDevice() Device {
 | 
				
			||||||
		FCMToken:        payload.FCMToken,
 | 
							FCMToken:        payload.FCMToken,
 | 
				
			||||||
		Model:           payload.Model,
 | 
							Model:           payload.Model,
 | 
				
			||||||
		Manufacturer:    payload.Manufacturer,
 | 
							Manufacturer:    payload.Manufacturer,
 | 
				
			||||||
		UserID:          payload.UserID,
 | 
							UserID:          userID,
 | 
				
			||||||
		IsMobile:        isMobile,
 | 
							IsMobile:        isMobile,
 | 
				
			||||||
		AppVersion:      payload.AppVersion,
 | 
							AppVersion:      payload.AppVersion,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/Selly-Modules/logger"
 | 
						"github.com/Selly-Modules/logger"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/mongodb"
 | 
				
			||||||
	"go.mongodb.org/mongo-driver/bson"
 | 
						"go.mongodb.org/mongo-driver/bson"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,8 +14,9 @@ func (s Service) FindAllDevicesByUserID(userID string) []Device {
 | 
				
			||||||
		ctx    = context.Background()
 | 
							ctx    = context.Background()
 | 
				
			||||||
		col    = s.getDeviceCollection()
 | 
							col    = s.getDeviceCollection()
 | 
				
			||||||
		result = make([]Device, 0)
 | 
							result = make([]Device, 0)
 | 
				
			||||||
 | 
							id, _  = mongodb.NewIDFromString(userID)
 | 
				
			||||||
		cond   = bson.M{
 | 
							cond   = bson.M{
 | 
				
			||||||
			"userId": userID,
 | 
								"userId": id,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,6 +27,6 @@ func (s Service) GetUserIDByAuthToken(authToken string) (userID string) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	userID = device.UserID
 | 
						userID = device.UserID.Hex()
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								model.go
								
								
								
								
							
							
						
						
									
										2
									
								
								model.go
								
								
								
								
							| 
						 | 
					@ -17,7 +17,7 @@ type Device struct {
 | 
				
			||||||
	Language        string             `bson:"language" json:"language"` // vi, en
 | 
						Language        string             `bson:"language" json:"language"` // vi, en
 | 
				
			||||||
	IsMobile        bool               `bson:"isMobile" json:"isMobile"`
 | 
						IsMobile        bool               `bson:"isMobile" json:"isMobile"`
 | 
				
			||||||
	LastActivatedAt time.Time          `bson:"lastActivatedAt" json:"lastActivatedAt"`
 | 
						LastActivatedAt time.Time          `bson:"lastActivatedAt" json:"lastActivatedAt"`
 | 
				
			||||||
	UserID          string             `bson:"userId" json:"userId"`
 | 
						UserID          primitive.ObjectID `bson:"userId" json:"userId"`
 | 
				
			||||||
	AuthToken       string             `bson:"authToken" json:"authToken"`
 | 
						AuthToken       string             `bson:"authToken" json:"authToken"`
 | 
				
			||||||
	FCMToken        string             `bson:"fcmToken" json:"fcmToken"`
 | 
						FCMToken        string             `bson:"fcmToken" json:"fcmToken"`
 | 
				
			||||||
	Model           string             `bson:"model" json:"model"`
 | 
						Model           string             `bson:"model" json:"model"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/Selly-Modules/logger"
 | 
						"github.com/Selly-Modules/logger"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/mongodb"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (co CreateOptions) validate() error {
 | 
					func (co CreateOptions) validate() error {
 | 
				
			||||||
| 
						 | 
					@ -38,6 +39,9 @@ func (co CreateOptions) validate() error {
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
		return errors.New("no userID data")
 | 
							return errors.New("no userID data")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if _, isValid := mongodb.NewIDFromString(co.UserID); !isValid {
 | 
				
			||||||
 | 
							return errors.New("invalid userID data")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// AuthToken
 | 
						// AuthToken
 | 
				
			||||||
	if co.AuthToken == "" {
 | 
						if co.AuthToken == "" {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue