-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaccount_manager.go
More file actions
51 lines (42 loc) · 1.17 KB
/
account_manager.go
File metadata and controls
51 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package model
import (
"context"
"github.com/google/uuid"
"github.com/samber/lo"
"github.com/traPtitech/Jomon/internal/ent"
"github.com/traPtitech/Jomon/internal/ent/user"
"github.com/traPtitech/Jomon/internal/service"
)
func (repo *EntRepository) GetAccountManagers(
ctx context.Context,
) ([]*service.AccountManager, error) {
users, err := repo.client.User.
Query().
Where(user.AccountManager(true)).
All(ctx)
if err != nil {
return nil, defaultEntErrorConverter.convert(err)
}
accountManagers := lo.Map(users, func(u *ent.User, _ int) *service.AccountManager {
return &service.AccountManager{
ID: u.ID,
}
})
return accountManagers, nil
}
func (repo *EntRepository) AddAccountManagers(ctx context.Context, userIDs []uuid.UUID) error {
_, err := repo.client.User.
Update().
Where(user.IDIn(userIDs...)).
SetAccountManager(true).
Save(ctx)
return defaultEntErrorConverter.convert(err)
}
func (repo *EntRepository) DeleteAccountManagers(ctx context.Context, userIDs []uuid.UUID) error {
_, err := repo.client.User.
Update().
Where(user.IDIn(userIDs...)).
SetAccountManager(false).
Save(ctx)
return defaultEntErrorConverter.convert(err)
}