2024-07-24 09:23:44 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2024-10-31 12:38:50 +00:00
|
|
|
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
|
|
|
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
|
2024-07-24 09:23:44 +00:00
|
|
|
"github.com/samber/lo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetUserAccountGroup(user models.Account) ([]models.AccountGroup, error) {
|
|
|
|
var members []models.AccountGroupMember
|
|
|
|
if err := database.C.Where(&models.AccountGroupMember{
|
|
|
|
AccountID: user.ID,
|
|
|
|
}).Find(&members).Error; err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var groups []models.AccountGroup
|
2024-07-24 10:09:18 +00:00
|
|
|
if err := database.C.Where("id IN ?", lo.Map(members, func(item models.AccountGroupMember, index int) uint {
|
|
|
|
return item.GroupID
|
2024-07-24 09:23:44 +00:00
|
|
|
})).Find(&groups).Error; err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return groups, nil
|
|
|
|
}
|