1
1
import { Injectable } from '@nestjs/common' ;
2
- import { NotImplementedException , PublicOf } from '~/common' ;
2
+ import { ID , NotImplementedException , PublicOf } from '~/common' ;
3
3
import { e , RepoFor , ScopeOf } from '~/core/edgedb' ;
4
4
import {
5
5
AssignOrganizationToUser ,
@@ -9,13 +9,35 @@ import {
9
9
} from './dto' ;
10
10
import type { UserRepository } from './user.repository' ;
11
11
12
+ const hydrateUser = e . shape ( e . User , ( user ) => ( {
13
+ ...user [ '*' ] ,
14
+ __typename : e . str ( 'User' ) ,
15
+ } ) ) ;
16
+ const hydrateSystemAgent = e . shape ( e . SystemAgent , ( agent ) => ( {
17
+ ...agent [ '*' ] ,
18
+ __typename : e . str ( 'SystemAgent' ) ,
19
+ } ) ) ;
20
+
12
21
@Injectable ( )
13
22
export class UserEdgeDBRepository
14
- extends RepoFor ( User , {
15
- hydrate : ( user ) => user [ '*' ] ,
16
- } )
23
+ extends RepoFor ( User , { hydrate : hydrateUser } )
17
24
implements PublicOf < UserRepository >
18
25
{
26
+ async readManyActors ( ids : readonly ID [ ] ) {
27
+ const res = await this . db . run ( this . readManyActorsQuery , { ids } ) ;
28
+ return [ ...res . users , ...res . agents ] ;
29
+ }
30
+ private readonly readManyActorsQuery = e . params (
31
+ { ids : e . array ( e . uuid ) } ,
32
+ ( { ids } ) => {
33
+ const actors = e . cast ( e . Actor , e . array_unpack ( ids ) ) ;
34
+ return e . select ( {
35
+ users : e . select ( actors . is ( e . User ) , hydrateUser ) ,
36
+ agents : e . select ( actors . is ( e . SystemAgent ) , hydrateSystemAgent ) ,
37
+ } ) ;
38
+ } ,
39
+ ) ;
40
+
19
41
async doesEmailAddressExist ( email : string ) {
20
42
const query = e . select ( e . User , ( ) => ( {
21
43
filter_single : { email } ,
0 commit comments