diff --git a/action.go b/action.go index c31feb7..e7fd80a 100644 --- a/action.go +++ b/action.go @@ -6,6 +6,7 @@ import ( "git.selly.red/Selly-Modules/usermngmt/permission" "git.selly.red/Selly-Modules/usermngmt/role" "git.selly.red/Selly-Modules/usermngmt/user" + "go.mongodb.org/mongo-driver/bson/primitive" ) // @@ -170,3 +171,8 @@ func (s Service) DeletePermission(permissionID string) error { func (s Service) GetAllPermissions(query model.PermissionAllQuery) model.PermissionAll { return permission.All(query) } + +// GetStaffsBySupplier ... +func (s Service) GetStaffsBySupplier(supplierID primitive.ObjectID) []model.SupplierStaffShort { + return user.GetStaffBySupplier(supplierID) +} diff --git a/model/staff.go b/model/staff.go new file mode 100644 index 0000000..0cb9713 --- /dev/null +++ b/model/staff.go @@ -0,0 +1,8 @@ +package model + +// SupplierStaffShort ... +type SupplierStaffShort struct { + ID string `json:"_id"` + Name string `json:"name"` + Role string `json:"role"` +} diff --git a/user/handle.go b/user/handle.go index 5adf5d7..82baaaa 100644 --- a/user/handle.go +++ b/user/handle.go @@ -749,3 +749,21 @@ func Delete(userID string) error { return nil } + +// GetStaffBySupplier ... +func GetStaffBySupplier(supplierID primitive.ObjectID) (r []model.SupplierStaffShort) { + var ( + ctx = context.Background() + ) + + users := findByCondition(ctx, bson.M{"other.supplier": supplierID}) + for _, user := range users { + r = append(r, model.SupplierStaffShort{ + ID: user.ID.Hex(), + Name: user.Name, + Role: user.RoleID.Hex(), + }) + } + + return +}