Merge pull request #14 from Selly-Modules/feature/merchant

fix code
This commit is contained in:
nguyenphamquangtue 2022-10-06 14:10:06 +07:00 committed by GitHub
commit e87f36995b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -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)
}

View File

@ -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 {