fix code #14

Merged
nguyenphamquangtue merged 1 commits from feature/merchant into master 2022-10-06 07:10:06 +00:00
2 changed files with 38 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package internal
import ( import (
"fmt" "fmt"
"github.com/thoas/go-funk"
"go.mongodb.org/mongo-driver/bson/primitive"
"strings" "strings"
"github.com/Selly-Modules/mongodb" "github.com/Selly-Modules/mongodb"
@ -46,3 +48,10 @@ func GenerateCode(s string) string {
) )
return strings.ReplaceAll(mongodb.NonAccentVietnamese(s), emptySpace, underscore) 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)
}

View File

@ -1,6 +1,9 @@
package model package model
import ( import (
"github.com/Selly-Modules/usermngmt/internal"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"time" "time"
) )
@ -19,6 +22,32 @@ type User struct {
UpdatedAt time.Time `json:"updatedAt"` 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 ( type (
// UserAll ... // UserAll ...
UserAll struct { UserAll struct {