update CreateOptions

This commit is contained in:
Hoang 2021-12-10 11:46:25 +07:00
parent 348a8ddb13
commit 43fc966f9a
2 changed files with 17 additions and 0 deletions

View File

@ -21,6 +21,9 @@ type CreateOptions struct {
Language string Language string
Model string Model string
Manufacturer string Manufacturer string
OsName string
OsVersion string
IsMobile bool
} }
// Create ... // Create ...
@ -63,6 +66,12 @@ func (payload CreateOptions) newDevice() Device {
// Get userAgent data // Get userAgent data
osName, osVersion, isMobile := getUserAgentData(payload.UserAgent) osName, osVersion, isMobile := getUserAgentData(payload.UserAgent)
if osName == "" || osVersion == "" {
osName = payload.OsName
osVersion = payload.OsVersion
isMobile = payload.IsMobile
}
userID, _ := mongodb.NewIDFromString(payload.UserID) userID, _ := mongodb.NewIDFromString(payload.UserID)
return Device{ return Device{
ID: mongodb.NewObjectID(), ID: mongodb.NewObjectID(),

View File

@ -21,6 +21,9 @@ type UpdateOptions struct {
Language string Language string
Model string Model string
Manufacturer string Manufacturer string
OsName string
OsVersion string
IsMobile bool
} }
// UpdateByDeviceID ... // UpdateByDeviceID ...
@ -46,6 +49,11 @@ func (s Service) UpdateByDeviceID(deviceID string, payload UpdateOptions) error
// Get userAgent data // Get userAgent data
osName, osVersion, isMobile := getUserAgentData(payload.UserAgent) osName, osVersion, isMobile := getUserAgentData(payload.UserAgent)
if osName == "" || osVersion == "" {
osName = payload.OsName
osVersion = payload.OsVersion
isMobile = payload.IsMobile
}
// Setup update data // Setup update data
userID, _ := mongodb.NewIDFromString(payload.UserID) userID, _ := mongodb.NewIDFromString(payload.UserID)