add get staff by supplier

This commit is contained in:
anbuiselly 2023-02-27 14:04:58 +07:00
parent 6db4919231
commit ac81466c86
3 changed files with 32 additions and 0 deletions

View File

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

8
model/staff.go Normal file
View File

@ -0,0 +1,8 @@
package model
// SupplierStaffShort ...
type SupplierStaffShort struct {
ID string `json:"_id"`
Name string `json:"name"`
Role string `json:"role"`
}

View File

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