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