2021-11-05 07:21:57 +00:00
|
|
|
package devicemngmt
|
|
|
|
|
|
|
|
import (
|
2021-11-05 09:10:12 +00:00
|
|
|
"context"
|
2021-11-05 07:21:57 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-11-05 09:10:12 +00:00
|
|
|
"github.com/Selly-Modules/logger"
|
2021-11-05 08:40:07 +00:00
|
|
|
ua "github.com/mssola/user_agent"
|
2021-11-05 09:10:12 +00:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
2021-11-05 07:21:57 +00:00
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
)
|
|
|
|
|
|
|
|
// getDeviceCollection ...
|
|
|
|
func (s Service) getDeviceCollection() *mongo.Collection {
|
2021-11-05 08:40:07 +00:00
|
|
|
return s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableDevice))
|
|
|
|
}
|
|
|
|
|
2021-11-05 09:10:12 +00:00
|
|
|
func (s Service) isDeviceIDExisted(ctx context.Context, deviceID string) bool {
|
|
|
|
var (
|
|
|
|
col = s.getDeviceCollection()
|
|
|
|
device = Device{}
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := col.FindOne(ctx, bson.M{"deviceID": deviceID}).Decode(&device); err != nil {
|
|
|
|
logger.Error("devicemngt - findByDeviceID", logger.LogData{
|
|
|
|
"deviceID": deviceID,
|
|
|
|
"err": err.Error(),
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
}
|
2021-11-05 09:24:53 +00:00
|
|
|
return !device.ID.IsZero()
|
2021-11-05 09:10:12 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 08:40:07 +00:00
|
|
|
func getOSName(userAgent string) string {
|
|
|
|
uaData := ua.New(userAgent)
|
|
|
|
return uaData.OSInfo().Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func getOSVersion(userAgent string) string {
|
|
|
|
uaData := ua.New(userAgent)
|
|
|
|
return uaData.OSInfo().Version
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLanguage(lang string) string {
|
|
|
|
// Language, default is vietnamese(vi)
|
|
|
|
if lang == langEn {
|
|
|
|
return langEn
|
|
|
|
}
|
|
|
|
return langVi
|
2021-11-05 07:21:57 +00:00
|
|
|
}
|