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

View File

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