@things-factory/auth-base 6.4.2 → 6.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/auth-base",
3
- "version": "6.4.2",
3
+ "version": "6.4.7",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -30,10 +30,10 @@
30
30
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
31
31
  },
32
32
  "dependencies": {
33
- "@things-factory/email-base": "^6.4.2",
33
+ "@things-factory/email-base": "^6.4.7",
34
34
  "@things-factory/env": "^6.3.0",
35
- "@things-factory/i18n-base": "^6.4.2",
36
- "@things-factory/shell": "^6.4.2",
35
+ "@things-factory/i18n-base": "^6.4.7",
36
+ "@things-factory/shell": "^6.4.7",
37
37
  "@things-factory/utils": "^6.3.1",
38
38
  "jsonwebtoken": "^9.0.0",
39
39
  "koa-passport": "^6.0.0",
@@ -43,5 +43,5 @@
43
43
  "passport-local": "^1.0.0",
44
44
  "popsicle-cookie-jar": "^1.0.0"
45
45
  },
46
- "gitHead": "786d16d546045fba8e1c3542ec31d4eddbf4e7a1"
46
+ "gitHead": "62f53151fc9d182969416f07f91ed47ee03d67ce"
47
47
  }
@@ -5,10 +5,10 @@ import { SelectQueryBuilder } from 'typeorm'
5
5
  import { config } from '@things-factory/env'
6
6
  import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
7
7
 
8
- import { Privilege } from '../privilege/privilege'
9
- import { User } from '../user/user'
10
- import { Role } from './role'
11
- import { RoleList, RolePrivilege, UserRole } from './role-types'
8
+ import { Privilege } from '../privilege/privilege.js'
9
+ import { User } from '../user/user.js'
10
+ import { Role } from './role.js'
11
+ import { RoleList, RolePrivilege, UserRole, RoleBrief } from './role-types.js'
12
12
 
13
13
  @Resolver(Role)
14
14
  export class RoleQuery {
@@ -96,19 +96,20 @@ export class RoleQuery {
96
96
  return userRoles
97
97
  }
98
98
 
99
- @Query(returns => [Role], { description: 'To fetch roles of current user' })
100
- async myRoles(@Ctx() context: ResolverContext): Promise<Role[]> {
99
+ @Query(returns => [RoleBrief], { description: 'To fetch roles of current user (id, name only)' })
100
+ async myRoles(@Ctx() context: ResolverContext): Promise<RoleBrief[]> {
101
101
  const { user, domain } = context.state
102
102
 
103
- const qb: SelectQueryBuilder<User> = await getRepository(User).createQueryBuilder('USER')
104
- const { roles }: User = await qb
105
- .leftJoinAndSelect('USER.roles', 'ROLE')
103
+ const roles = await getRepository(Role)
104
+ .createQueryBuilder('ROLE')
105
+ .leftJoin('ROLE.users', 'USER')
106
106
  .leftJoin('ROLE.domain', 'ROLE_DOMAIN')
107
107
  .where('USER.id = :userId', { userId: user.id })
108
108
  .andWhere('ROLE_DOMAIN.id In(:...domainIds)', { domainIds: [domain.id, domain.parentId].filter(Boolean) })
109
- .getOne()
109
+ .select(['ROLE.id', 'ROLE.name'])
110
+ .getMany()
110
111
 
111
- return roles || []
112
+ return roles
112
113
  }
113
114
 
114
115
  @Query(returns => [Role], { description: 'To fetch the preset of role for new user' })
@@ -47,6 +47,15 @@ export class RoleList {
47
47
  total?: number
48
48
  }
49
49
 
50
+ @ObjectType()
51
+ export class RoleBrief {
52
+ @Field({ nullable: true })
53
+ id?: string
54
+
55
+ @Field({ nullable: true })
56
+ name?: string
57
+ }
58
+
50
59
  @ObjectType()
51
60
  export class RolePrivilege {
52
61
  @Field({ nullable: true })