fix code
This commit is contained in:
parent
2224a68c98
commit
fb660c6715
|
@ -2,6 +2,8 @@ package internal
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/thoas/go-funk"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"strings"
|
||||
|
||||
"github.com/Selly-Modules/mongodb"
|
||||
|
@ -46,3 +48,10 @@ func GenerateCode(s string) string {
|
|||
)
|
||||
return strings.ReplaceAll(mongodb.NonAccentVietnamese(s), emptySpace, underscore)
|
||||
}
|
||||
|
||||
// ConvertObjectIDsToStrings ...
|
||||
func ConvertObjectIDsToStrings(ids []primitive.ObjectID) []string {
|
||||
return funk.Map(ids, func(item primitive.ObjectID) string {
|
||||
return item.Hex()
|
||||
}).([]string)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/Selly-Modules/usermngmt/internal"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -19,6 +22,32 @@ type User struct {
|
|||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// UserOtherBson ...
|
||||
type UserOtherBson struct {
|
||||
Supplier primitive.ObjectID `bson:"supplier"`
|
||||
Inventories []primitive.ObjectID `bson:"inventories"`
|
||||
IsPresident bool `bson:"isPresident"`
|
||||
}
|
||||
|
||||
type UserOther struct {
|
||||
Supplier string `json:"supplier"`
|
||||
Inventories []string `json:"inventories"`
|
||||
IsPresident bool `json:"isPresident"`
|
||||
}
|
||||
|
||||
func (m User) GetUserOther() UserOther {
|
||||
var (
|
||||
userOtherBson UserOtherBson
|
||||
)
|
||||
bsonBytes, _ := bson.Marshal(m.Other)
|
||||
bson.Unmarshal(bsonBytes, &userOtherBson)
|
||||
return UserOther{
|
||||
Supplier: userOtherBson.Supplier.Hex(),
|
||||
Inventories: internal.ConvertObjectIDsToStrings(userOtherBson.Inventories),
|
||||
IsPresident: userOtherBson.IsPresident,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// UserAll ...
|
||||
UserAll struct {
|
||||
|
|
Loading…
Reference in New Issue