@merkaly/api 0.1.4 → 0.1.9-1

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.
Files changed (223) hide show
  1. package/README.md +79 -79
  2. package/package.json +89 -96
  3. package/src/account/account.module.d.ts +4 -0
  4. package/src/account/account.module.ts +15 -0
  5. package/src/account/auth/auth.controller.d.ts +10 -0
  6. package/src/account/auth/auth.controller.ts +38 -0
  7. package/src/account/auth/auth.decorator.d.ts +4 -0
  8. package/src/account/auth/auth.decorator.ts +10 -0
  9. package/src/account/auth/auth.guard.d.ts +15 -0
  10. package/src/account/auth/auth.guard.ts +41 -0
  11. package/src/account/auth/auth.module.d.ts +4 -0
  12. package/src/account/auth/auth.module.ts +26 -0
  13. package/src/account/auth/auth.repository.d.ts +6 -0
  14. package/src/account/auth/auth.repository.ts +39 -0
  15. package/src/account/auth/auth.strategy.d.ts +17 -0
  16. package/src/account/auth/auth.strategy.ts +31 -0
  17. package/src/account/auth/auth.validator.d.ts +4 -0
  18. package/src/account/auth/auth.validator.ts +11 -11
  19. package/src/account/auth/index.d.ts +1 -0
  20. package/src/account/auth/index.ts +1 -0
  21. package/src/account/index.d.ts +4 -0
  22. package/src/account/index.ts +4 -0
  23. package/src/account/organizations/index.d.ts +3 -0
  24. package/src/account/organizations/index.ts +3 -0
  25. package/src/account/organizations/members/index.d.ts +1 -0
  26. package/src/account/organizations/members/index.ts +1 -0
  27. package/src/account/organizations/members/member.controller.d.ts +9 -0
  28. package/src/account/organizations/members/member.controller.ts +33 -0
  29. package/src/account/organizations/members/member.entity.d.ts +9 -0
  30. package/src/account/organizations/members/member.entity.ts +11 -11
  31. package/src/account/organizations/members/member.module.d.ts +4 -0
  32. package/src/account/organizations/members/member.module.ts +14 -0
  33. package/src/account/organizations/members/member.repository.d.ts +12 -0
  34. package/src/account/organizations/members/member.repository.ts +43 -0
  35. package/src/account/organizations/members/member.validator.d.ts +2 -0
  36. package/src/account/organizations/members/member.validator.ts +3 -0
  37. package/src/account/organizations/organization.controller.d.ts +11 -0
  38. package/src/account/organizations/organization.controller.ts +42 -0
  39. package/src/account/organizations/organization.entity.d.ts +17 -0
  40. package/src/account/organizations/organization.entity.ts +24 -21
  41. package/src/account/organizations/organization.module.d.ts +4 -0
  42. package/src/account/organizations/organization.module.ts +16 -0
  43. package/src/account/organizations/organization.repository.d.ts +12 -0
  44. package/src/account/organizations/organization.repository.ts +74 -0
  45. package/src/account/organizations/organization.validator.d.ts +13 -0
  46. package/src/account/organizations/organization.validator.ts +52 -41
  47. package/src/account/roles/index.d.ts +3 -0
  48. package/src/account/roles/index.ts +3 -0
  49. package/src/account/roles/role.controller.d.ts +11 -0
  50. package/src/account/roles/role.controller.ts +39 -0
  51. package/src/account/roles/role.entity.d.ts +7 -0
  52. package/src/account/roles/role.entity.ts +9 -9
  53. package/src/account/roles/role.module.d.ts +4 -0
  54. package/src/account/roles/role.module.ts +15 -0
  55. package/src/account/roles/role.repository.d.ts +12 -0
  56. package/src/account/roles/role.repository.ts +63 -0
  57. package/src/account/roles/role.validator.d.ts +9 -0
  58. package/src/account/roles/role.validator.ts +21 -21
  59. package/src/account/roles/users/index.d.ts +2 -0
  60. package/src/account/roles/users/index.ts +2 -0
  61. package/src/account/roles/users/user.controller.d.ts +8 -0
  62. package/src/account/roles/users/user.controller.ts +28 -0
  63. package/src/account/roles/users/user.entity.d.ts +9 -0
  64. package/src/account/roles/users/user.entity.ts +11 -11
  65. package/src/account/roles/users/user.module.d.ts +4 -0
  66. package/src/account/roles/users/user.module.ts +14 -0
  67. package/src/account/roles/users/user.repository.d.ts +11 -0
  68. package/src/account/roles/users/user.repository.ts +34 -0
  69. package/src/account/roles/users/user.validator.d.ts +2 -0
  70. package/src/account/roles/users/user.validator.ts +3 -10
  71. package/src/account/users/index.d.ts +3 -0
  72. package/src/account/users/index.ts +3 -0
  73. package/src/account/users/roles/index.d.ts +2 -0
  74. package/src/account/users/roles/index.ts +2 -0
  75. package/src/account/users/roles/role.controller.d.ts +9 -0
  76. package/src/account/users/roles/role.controller.ts +34 -0
  77. package/src/account/users/roles/role.entity.d.ts +9 -0
  78. package/src/account/users/roles/role.entity.ts +11 -11
  79. package/src/account/users/roles/role.module.d.ts +4 -0
  80. package/src/account/users/roles/role.module.ts +14 -0
  81. package/src/account/users/roles/role.repository.d.ts +12 -0
  82. package/src/account/users/roles/role.repository.ts +38 -0
  83. package/src/account/users/roles/role.validator.d.ts +2 -0
  84. package/src/account/users/roles/role.validator.ts +3 -10
  85. package/src/account/users/user.controller.d.ts +11 -0
  86. package/src/account/users/user.controller.ts +39 -0
  87. package/src/account/users/user.entity.d.ts +32 -0
  88. package/src/account/users/user.entity.ts +36 -36
  89. package/src/account/users/user.module.d.ts +4 -0
  90. package/src/account/users/user.module.ts +15 -0
  91. package/src/account/users/user.repository.d.ts +12 -0
  92. package/src/account/users/user.repository.ts +53 -0
  93. package/src/account/users/user.validator.d.ts +11 -0
  94. package/src/account/users/user.validator.ts +29 -29
  95. package/src/app.d.ts +1 -0
  96. package/src/app.emitter.d.ts +16 -0
  97. package/src/app.emitter.ts +27 -0
  98. package/src/app.entity.d.ts +7 -0
  99. package/src/app.entity.ts +13 -20
  100. package/src/app.module.d.ts +9 -0
  101. package/src/app.module.ts +45 -0
  102. package/src/app.repository.d.ts +5 -0
  103. package/src/app.repository.ts +12 -0
  104. package/src/app.routes.d.ts +3 -0
  105. package/src/app.routes.ts +61 -0
  106. package/src/index.d.ts +3 -0
  107. package/src/index.ts +3 -0
  108. package/src/inventory/brands/brand.controller.d.ts +11 -0
  109. package/src/inventory/brands/brand.controller.ts +41 -0
  110. package/src/inventory/brands/brand.entity.d.ts +5 -0
  111. package/src/inventory/brands/brand.entity.ts +10 -10
  112. package/src/inventory/brands/brand.module.d.ts +4 -0
  113. package/src/inventory/brands/brand.module.ts +14 -0
  114. package/src/inventory/brands/brand.repository.d.ts +13 -0
  115. package/src/inventory/brands/brand.repository.ts +36 -0
  116. package/src/inventory/brands/brand.validator.d.ts +6 -0
  117. package/src/inventory/brands/brand.validator.ts +12 -12
  118. package/src/inventory/brands/index.d.ts +2 -0
  119. package/src/inventory/brands/index.ts +2 -0
  120. package/src/inventory/categories/category.controller.d.ts +11 -0
  121. package/src/inventory/categories/category.controller.ts +43 -0
  122. package/src/inventory/categories/category.entity.d.ts +5 -0
  123. package/src/inventory/categories/category.entity.ts +10 -10
  124. package/src/inventory/categories/category.module.d.ts +4 -0
  125. package/src/inventory/categories/category.module.ts +14 -0
  126. package/src/inventory/categories/category.repository.d.ts +13 -0
  127. package/src/inventory/categories/category.repository.ts +36 -0
  128. package/src/inventory/categories/category.validator.d.ts +6 -0
  129. package/src/inventory/categories/category.validator.ts +11 -11
  130. package/src/inventory/categories/index.d.ts +2 -0
  131. package/src/inventory/categories/index.ts +2 -0
  132. package/src/inventory/index.d.ts +5 -0
  133. package/src/inventory/index.ts +6 -0
  134. package/src/inventory/inventory.module.d.ts +4 -0
  135. package/src/inventory/inventory.module.ts +17 -0
  136. package/src/inventory/products/index.d.ts +4 -0
  137. package/src/inventory/products/index.ts +4 -0
  138. package/src/inventory/products/media/index.d.ts +2 -0
  139. package/src/inventory/products/media/index.ts +2 -0
  140. package/src/inventory/products/media/media.controller.d.ts +7 -0
  141. package/src/inventory/products/media/media.controller.ts +23 -0
  142. package/src/inventory/products/media/media.entity.d.ts +6 -0
  143. package/src/inventory/products/media/media.entity.ts +10 -10
  144. package/src/inventory/products/media/media.module.d.ts +4 -0
  145. package/src/inventory/products/media/media.module.ts +14 -0
  146. package/src/inventory/products/media/media.repository.d.ts +10 -0
  147. package/src/inventory/products/media/media.repository.ts +22 -0
  148. package/src/inventory/products/media/media.validator.d.ts +4 -0
  149. package/src/inventory/products/media/media.validator.ts +7 -7
  150. package/src/inventory/products/product.controller.d.ts +12 -0
  151. package/src/inventory/products/product.controller.ts +59 -0
  152. package/src/inventory/products/product.entity.d.ts +31 -0
  153. package/src/inventory/products/product.entity.ts +63 -63
  154. package/src/inventory/products/product.module.d.ts +4 -0
  155. package/src/inventory/products/product.module.ts +16 -0
  156. package/src/inventory/products/product.repository.d.ts +18 -0
  157. package/src/inventory/products/product.repository.ts +94 -0
  158. package/src/inventory/products/product.validator.d.ts +21 -0
  159. package/src/inventory/products/product.validator.ts +70 -70
  160. package/src/inventory/products/variants/index.d.ts +2 -0
  161. package/src/inventory/products/variants/index.ts +2 -0
  162. package/src/inventory/products/variants/variant.controller.d.ts +7 -0
  163. package/src/inventory/products/variants/variant.controller.ts +23 -0
  164. package/src/inventory/products/variants/variant.entity.d.ts +6 -0
  165. package/src/inventory/products/variants/variant.entity.ts +11 -11
  166. package/src/inventory/products/variants/variant.module.d.ts +4 -0
  167. package/src/inventory/products/variants/variant.module.ts +14 -0
  168. package/src/inventory/products/variants/variant.repository.d.ts +10 -0
  169. package/src/inventory/products/variants/variant.repository.ts +23 -0
  170. package/src/inventory/products/variants/variant.validator.d.ts +4 -0
  171. package/src/inventory/products/variants/variant.validator.ts +7 -7
  172. package/src/inventory/properties/index.d.ts +2 -0
  173. package/src/inventory/properties/index.ts +2 -0
  174. package/src/inventory/properties/property.controller.d.ts +11 -0
  175. package/src/inventory/properties/property.controller.ts +42 -0
  176. package/src/inventory/properties/property.entity.d.ts +8 -0
  177. package/src/inventory/properties/property.entity.ts +19 -19
  178. package/src/inventory/properties/property.module.d.ts +4 -0
  179. package/src/inventory/properties/property.module.ts +14 -0
  180. package/src/inventory/properties/property.repository.d.ts +13 -0
  181. package/src/inventory/properties/property.repository.ts +38 -0
  182. package/src/inventory/properties/property.validator.d.ts +8 -0
  183. package/src/inventory/properties/property.validator.ts +20 -20
  184. package/src/store/carts/cart.controller.d.ts +11 -0
  185. package/src/store/carts/cart.controller.ts +44 -0
  186. package/src/store/carts/cart.entity.d.ts +14 -0
  187. package/src/store/carts/cart.entity.ts +21 -21
  188. package/src/store/carts/cart.module.d.ts +4 -0
  189. package/src/store/carts/cart.module.ts +14 -0
  190. package/src/store/carts/cart.repository.d.ts +13 -0
  191. package/src/store/carts/cart.repository.ts +36 -0
  192. package/src/store/carts/cart.validator.d.ts +4 -0
  193. package/src/store/carts/cart.validator.ts +7 -7
  194. package/src/store/carts/index.d.ts +2 -0
  195. package/src/store/carts/index.ts +2 -0
  196. package/src/store/index.d.ts +3 -0
  197. package/src/store/index.ts +4 -0
  198. package/src/store/orders/index.d.ts +3 -0
  199. package/src/store/orders/index.ts +3 -0
  200. package/src/store/orders/items/index.d.ts +2 -0
  201. package/src/store/orders/items/index.ts +2 -0
  202. package/src/store/orders/items/item.controller.d.ts +11 -0
  203. package/src/store/orders/items/item.controller.ts +41 -0
  204. package/src/store/orders/items/item.entity.d.ts +7 -0
  205. package/src/store/orders/items/item.entity.ts +14 -14
  206. package/src/store/orders/items/item.module.d.ts +4 -0
  207. package/src/store/orders/items/item.module.ts +14 -0
  208. package/src/store/orders/items/item.repository.d.ts +13 -0
  209. package/src/store/orders/items/item.repository.ts +35 -0
  210. package/src/store/orders/items/item.validator.d.ts +4 -0
  211. package/src/store/orders/items/item.validator.ts +7 -7
  212. package/src/store/orders/order.controller.d.ts +11 -0
  213. package/src/store/orders/order.controller.ts +44 -0
  214. package/src/store/orders/order.entity.d.ts +9 -0
  215. package/src/store/orders/order.entity.ts +18 -18
  216. package/src/store/orders/order.module.d.ts +4 -0
  217. package/src/store/orders/order.module.ts +15 -0
  218. package/src/store/orders/order.repository.d.ts +13 -0
  219. package/src/store/orders/order.repository.ts +35 -0
  220. package/src/store/orders/order.validator.d.ts +4 -0
  221. package/src/store/orders/order.validator.ts +7 -7
  222. package/src/store/store.module.d.ts +4 -0
  223. package/src/store/store.module.ts +14 -0
@@ -1,9 +1,9 @@
1
- import { Role } from 'auth0'
2
- import AppEntity from '../../app.entity'
3
-
4
- export class RoleEntity extends AppEntity implements Role {
5
- static readonly $path = 'roles'
6
-
7
- public name: string | undefined
8
- public description: string | undefined
9
- }
1
+ import { Role } from 'auth0'
2
+ import AppEntity from '../../app.entity'
3
+
4
+ export class RoleEntity extends AppEntity implements Role {
5
+ static readonly $path = 'roles'
6
+
7
+ public name: string | undefined
8
+ public description: string | undefined
9
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class RoleModule {
4
+ }
@@ -0,0 +1,15 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common'
2
+ import RoleController from './role.controller'
3
+ import RoleRepository from './role.repository'
4
+ import UserModule from './users/user.module'
5
+
6
+ export const metadata: ModuleMetadata = {
7
+ imports: [UserModule],
8
+ controllers: [RoleController],
9
+ providers: [RoleRepository],
10
+ exports: []
11
+ }
12
+
13
+ @Module(metadata)
14
+ export default class RoleModule {
15
+ }
@@ -0,0 +1,12 @@
1
+ import AuthRepository from '../auth/auth.repository';
2
+ import { RoleEntity } from './role.entity';
3
+ import { CreateRoleValidator, UpdateRoleValidator } from './role.validator';
4
+ export default class RoleRepository {
5
+ protected readonly authService: AuthRepository;
6
+ private $auth0;
7
+ find(): Promise<RoleEntity[]>;
8
+ read(id: string): Promise<RoleEntity>;
9
+ create(validator: CreateRoleValidator): Promise<RoleEntity>;
10
+ update(id: string, validator: UpdateRoleValidator): Promise<RoleEntity>;
11
+ delete(id: string): Promise<void>;
12
+ }
@@ -0,0 +1,63 @@
1
+ import { Inject, Injectable } from '@nestjs/common'
2
+ import { CreateRoleData, ManagementClient, UpdateRoleData } from 'auth0'
3
+ import axios from 'axios'
4
+ import { join } from 'path'
5
+ import AuthRepository from '../auth/auth.repository'
6
+ import { RoleEntity } from './role.entity'
7
+ import { CreateRoleValidator, UpdateRoleValidator } from './role.validator'
8
+
9
+ @Injectable()
10
+ export default class RoleRepository {
11
+ @Inject() protected readonly authService: AuthRepository
12
+
13
+ private async $auth0 (): Promise<ManagementClient> {
14
+ return this.authService.$management()
15
+ }
16
+
17
+ public async find (): Promise<RoleEntity[]> {
18
+ await this.$auth0()
19
+
20
+ return axios.get('roles')
21
+ .then(({ data }) => data)
22
+ }
23
+
24
+ public async read (id: string): Promise<RoleEntity> {
25
+ await this.$auth0()
26
+
27
+ return axios.get<RoleEntity>(join('roles', id))
28
+ .then(({ data }) => data)
29
+ }
30
+
31
+ public async create (validator: CreateRoleValidator): Promise<RoleEntity> {
32
+ await this.$auth0()
33
+
34
+ const role: CreateRoleData = {
35
+ name: validator.name,
36
+ description: validator.description
37
+ }
38
+
39
+ return axios.post<RoleEntity>('roles', role)
40
+ .then(({ data }) => data)
41
+ }
42
+
43
+ public async update (id: string, validator: UpdateRoleValidator): Promise<RoleEntity> {
44
+ await this.$auth0()
45
+
46
+ const role: UpdateRoleData = {
47
+ name: validator.name,
48
+ description: validator.description
49
+ }
50
+
51
+ return axios.patch<RoleEntity>(join('roles', id), role)
52
+ .then(({ data }) => data)
53
+ }
54
+
55
+ public async delete (id: string): Promise<void> {
56
+ await this.$auth0()
57
+
58
+ return axios.delete<void>(join('roles', id))
59
+ .then(({ data }) => data)
60
+ }
61
+
62
+
63
+ }
@@ -0,0 +1,9 @@
1
+ import { CreateRoleData, UpdateRoleData } from 'auth0';
2
+ export declare class CreateRoleValidator implements CreateRoleData {
3
+ name: string;
4
+ description: string;
5
+ }
6
+ export declare class UpdateRoleValidator implements UpdateRoleData {
7
+ name: string;
8
+ description: string;
9
+ }
@@ -1,21 +1,21 @@
1
- import { CreateRoleData, UpdateRoleData } from 'auth0'
2
- import { IsOptional, IsString } from 'class-validator'
3
-
4
- export class CreateRoleValidator implements CreateRoleData {
5
- @IsString()
6
- name: string
7
-
8
- @IsString()
9
- @IsOptional()
10
- description: string
11
- }
12
-
13
- export class UpdateRoleValidator implements UpdateRoleData {
14
- @IsOptional()
15
- @IsString()
16
- name: string
17
-
18
- @IsString()
19
- @IsOptional()
20
- description: string
21
- }
1
+ import { CreateRoleData, UpdateRoleData } from 'auth0'
2
+ import { IsOptional, IsString } from 'class-validator'
3
+
4
+ export class CreateRoleValidator implements CreateRoleData {
5
+ @IsString()
6
+ name: string
7
+
8
+ @IsString()
9
+ @IsOptional()
10
+ description: string
11
+ }
12
+
13
+ export class UpdateRoleValidator implements UpdateRoleData {
14
+ @IsOptional()
15
+ @IsString()
16
+ name: string
17
+
18
+ @IsString()
19
+ @IsOptional()
20
+ description: string
21
+ }
@@ -0,0 +1,2 @@
1
+ export * from './user.validator';
2
+ export * from './user.entity';
@@ -0,0 +1,2 @@
1
+ export * from './user.validator'
2
+ export * from './user.entity'
@@ -0,0 +1,8 @@
1
+ import { User } from 'auth0';
2
+ import UserRepository from './user.repository';
3
+ import { AddRoleUsers } from './user.validator';
4
+ export default class UserController {
5
+ protected readonly repository: UserRepository;
6
+ find(rol: string): Promise<User[]>;
7
+ assign(rol: string, users: AddRoleUsers): Promise<void>;
8
+ }
@@ -0,0 +1,28 @@
1
+ import { Body, Controller, Get, Inject, Param, Post } from '@nestjs/common'
2
+ import { ApiTags } from '@nestjs/swagger'
3
+ import { User } from 'auth0'
4
+ import RoleController from '../role.controller'
5
+ import { RoleUserEntity } from './user.entity'
6
+ import UserRepository from './user.repository'
7
+ import { AddRoleUsers } from './user.validator'
8
+
9
+ @Controller(':rol/' + RoleUserEntity.$path)
10
+ @ApiTags(RoleController.name)
11
+ export default class UserController {
12
+ @Inject() protected readonly repository: UserRepository
13
+
14
+ @Get('/')
15
+ async find (@Param('rol') rol: string): Promise<User[]> {
16
+ this.repository.rolId = rol
17
+
18
+ return this.repository.find()
19
+ }
20
+
21
+ @Post('/')
22
+ async assign (@Param('rol') rol: string, @Body() users: AddRoleUsers): Promise<void> {
23
+ this.repository.rolId = rol
24
+
25
+ return this.repository.assign(users)
26
+ }
27
+
28
+ }
@@ -0,0 +1,9 @@
1
+ import AppEntity from '../../../app.entity';
2
+ import { UserEntity } from '../../users';
3
+ export declare class RoleUserEntity extends AppEntity implements Pick<UserEntity, 'user_id' | 'email' | 'name' | 'picture'> {
4
+ static readonly $path = "users";
5
+ user_id: string;
6
+ email: string;
7
+ name: string;
8
+ picture: string;
9
+ }
@@ -1,11 +1,11 @@
1
- import AppEntity from '../../../app.entity'
2
- import { UserEntity } from '../../users'
3
-
4
- export class RoleUserEntity extends AppEntity implements Pick<UserEntity, 'user_id' | 'email' | 'name' | 'picture'> {
5
- static readonly $path = 'users'
6
-
7
- public user_id: string
8
- public email: string
9
- public name: string
10
- public picture: string
11
- }
1
+ import AppEntity from '../../../app.entity'
2
+ import { UserEntity } from '../../users'
3
+
4
+ export class RoleUserEntity extends AppEntity implements Pick<UserEntity, 'user_id' | 'email' | 'name' | 'picture'> {
5
+ static readonly $path = 'users'
6
+
7
+ public user_id: string
8
+ public email: string
9
+ public name: string
10
+ public picture: string
11
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class UserModule {
4
+ }
@@ -0,0 +1,14 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common'
2
+ import UserController from './user.controller'
3
+ import UserRepository from './user.repository'
4
+
5
+ export const metadata: ModuleMetadata = {
6
+ imports: [],
7
+ controllers: [UserController],
8
+ providers: [UserRepository],
9
+ exports: []
10
+ }
11
+
12
+ @Module(metadata)
13
+ export default class UserModule {
14
+ }
@@ -0,0 +1,11 @@
1
+ import { User } from 'auth0';
2
+ import AuthRepository from '../../auth/auth.repository';
3
+ import { AddRoleUsers } from './user.validator';
4
+ export default class UserRepository {
5
+ $rolId: string;
6
+ protected readonly authService: AuthRepository;
7
+ private $auth0;
8
+ set rolId(id: string);
9
+ find(): Promise<User[]>;
10
+ assign(users: AddRoleUsers): Promise<void>;
11
+ }
@@ -0,0 +1,34 @@
1
+ import { Inject, Injectable } from '@nestjs/common'
2
+ import { ManagementClient, User } from 'auth0'
3
+ import axios from 'axios'
4
+ import { join } from 'path'
5
+ import AuthRepository from '../../auth/auth.repository'
6
+ import { AddRoleUsers } from './user.validator'
7
+
8
+ @Injectable()
9
+ export default class UserRepository {
10
+ public $rolId: string
11
+ @Inject() protected readonly authService: AuthRepository
12
+
13
+ private async $auth0 (): Promise<ManagementClient> {
14
+ return this.authService.$management()
15
+ }
16
+
17
+ public set rolId (id: string) {
18
+ this.$rolId = id
19
+ }
20
+
21
+ public async find (): Promise<User[]> {
22
+ const { getUsersInRole } = await this.$auth0()
23
+
24
+ return getUsersInRole({ id: this.$rolId })
25
+ }
26
+
27
+ public async assign (users: AddRoleUsers): Promise<void> {
28
+ await this.$auth0()
29
+
30
+ await axios.post(join('roles', this.$rolId, '/users'), { users })
31
+ .then(({ data }) => data)
32
+ }
33
+
34
+ }
@@ -0,0 +1,2 @@
1
+ export declare type AddRoleUsers = string[];
2
+ export declare type RemoveRoleUsers = string[];
@@ -1,10 +1,3 @@
1
- import { IsOptional, IsString } from 'class-validator'
2
-
3
- export class AddRoleUserValidator {
4
- @IsString()
5
- name: string
6
-
7
- @IsString()
8
- @IsOptional()
9
- description: string
10
- }
1
+ export type AddRoleUsers = string[]
2
+
3
+ export type RemoveRoleUsers = string[]
@@ -0,0 +1,3 @@
1
+ export * from './user.validator';
2
+ export * from './user.entity';
3
+ export * from './roles';
@@ -0,0 +1,3 @@
1
+ export * from './user.validator'
2
+ export * from './user.entity'
3
+ export * from './roles'
@@ -0,0 +1,2 @@
1
+ export * from './role.validator';
2
+ export * from './role.entity';
@@ -0,0 +1,2 @@
1
+ export * from './role.validator'
2
+ export * from './role.entity'
@@ -0,0 +1,9 @@
1
+ import { User } from 'auth0';
2
+ import RoleRepository from './role.repository';
3
+ import { AddUserRole, RemoveUserRole } from './role.validator';
4
+ export default class RoleController {
5
+ protected readonly repository: RoleRepository;
6
+ find(id: string): Promise<User[]>;
7
+ assign(id: string, roles: AddUserRole): Promise<void>;
8
+ remove(id: string, roles: RemoveUserRole): Promise<void>;
9
+ }
@@ -0,0 +1,34 @@
1
+ import { Body, Controller, Delete, Get, Inject, Param, Post } from '@nestjs/common'
2
+ import { ApiTags } from '@nestjs/swagger'
3
+ import { User } from 'auth0'
4
+ import { UserRoleEntity } from './role.entity'
5
+ import RoleRepository from './role.repository'
6
+ import { AddUserRole, RemoveUserRole } from './role.validator'
7
+
8
+ @Controller(':user/' + UserRoleEntity.$path)
9
+ @ApiTags(RoleController.name)
10
+ export default class RoleController {
11
+ @Inject() protected readonly repository: RoleRepository
12
+
13
+ @Get('/')
14
+ async find (@Param('user') id: string): Promise<User[]> {
15
+ this.repository.userId = id
16
+
17
+ return this.repository.find()
18
+ }
19
+
20
+ @Post('/')
21
+ async assign (@Param('user') id: string, @Body() roles: AddUserRole): Promise<void> {
22
+ this.repository.userId = id
23
+
24
+ return this.repository.assign(roles)
25
+ }
26
+
27
+ @Delete('/')
28
+ async remove (@Param('user') id: string, @Body() roles: RemoveUserRole): Promise<void> {
29
+ this.repository.userId = id
30
+
31
+ return this.repository.remove(roles)
32
+ }
33
+
34
+ }
@@ -0,0 +1,9 @@
1
+ import AppEntity from '../../../app.entity';
2
+ import { UserEntity } from '../user.entity';
3
+ export declare class UserRoleEntity extends AppEntity implements Pick<UserEntity, 'user_id' | 'email' | 'name' | 'picture'> {
4
+ static readonly $path = "roles";
5
+ user_id: string;
6
+ email: string;
7
+ name: string;
8
+ picture: string;
9
+ }
@@ -1,11 +1,11 @@
1
- import AppEntity from '../../../app.entity'
2
- import { UserEntity } from '../user.entity'
3
-
4
- export class UserRoleEntity extends AppEntity implements Pick<UserEntity, 'user_id' | 'email' | 'name' | 'picture'> {
5
- static readonly $path = 'roles'
6
-
7
- public user_id: string
8
- public email: string
9
- public name: string
10
- public picture: string
11
- }
1
+ import AppEntity from '../../../app.entity'
2
+ import { UserEntity } from '../user.entity'
3
+
4
+ export class UserRoleEntity extends AppEntity implements Pick<UserEntity, 'user_id' | 'email' | 'name' | 'picture'> {
5
+ static readonly $path = 'roles'
6
+
7
+ public user_id: string
8
+ public email: string
9
+ public name: string
10
+ public picture: string
11
+ }
@@ -0,0 +1,4 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ export declare const metadata: ModuleMetadata;
3
+ export default class UserRoleModule {
4
+ }
@@ -0,0 +1,14 @@
1
+ import { Module, ModuleMetadata } from '@nestjs/common'
2
+ import RoleController from './role.controller'
3
+ import RoleRepository from './role.repository'
4
+
5
+ export const metadata: ModuleMetadata = {
6
+ imports: [],
7
+ controllers: [RoleController],
8
+ providers: [RoleRepository],
9
+ exports: []
10
+ }
11
+
12
+ @Module(metadata)
13
+ export default class UserRoleModule {
14
+ }
@@ -0,0 +1,12 @@
1
+ import { Role } from 'auth0';
2
+ import AuthRepository from '../../auth/auth.repository';
3
+ import { AddUserRole } from './role.validator';
4
+ export default class RoleRepository {
5
+ protected readonly authService: AuthRepository;
6
+ $userId: any;
7
+ set userId(id: string);
8
+ private $auth0;
9
+ find(): Promise<Role[]>;
10
+ assign(roles: AddUserRole): Promise<void>;
11
+ remove(roles: AddUserRole): Promise<void>;
12
+ }
@@ -0,0 +1,38 @@
1
+ import { Inject, Injectable } from '@nestjs/common'
2
+ import { ManagementClient, Role } from 'auth0'
3
+ import AuthRepository from '../../auth/auth.repository'
4
+ import { AddUserRole } from './role.validator'
5
+
6
+ @Injectable()
7
+ export default class RoleRepository {
8
+ @Inject() protected readonly authService: AuthRepository
9
+ public $userId = null
10
+
11
+ public set userId (id: string) {
12
+ this.$userId = id
13
+ }
14
+
15
+ private async $auth0 (): Promise<ManagementClient> {
16
+ return this.authService.$management()
17
+ }
18
+
19
+ public async find (): Promise<Role[]> {
20
+ const { getUserRoles } = await this.$auth0()
21
+
22
+ return getUserRoles({ id: this.$userId })
23
+ }
24
+
25
+ public async assign (roles: AddUserRole): Promise<void> {
26
+ const { assignRolestoUser } = await this.$auth0()
27
+
28
+ return assignRolestoUser({ id: this.$userId }, { roles })
29
+ }
30
+
31
+ public async remove (roles: AddUserRole): Promise<void> {
32
+ const { removeRolesFromUser } = await this.$auth0()
33
+
34
+ return removeRolesFromUser({ id: this.$userId }, { roles })
35
+ }
36
+
37
+
38
+ }
@@ -0,0 +1,2 @@
1
+ export declare type AddUserRole = string[];
2
+ export declare type RemoveUserRole = string[];
@@ -1,10 +1,3 @@
1
- import { IsOptional, IsString } from 'class-validator'
2
-
3
- export class AddRoleValidator {
4
- @IsString()
5
- name: string
6
-
7
- @IsString()
8
- @IsOptional()
9
- description: string
10
- }
1
+ export type AddUserRole = string[]
2
+
3
+ export type RemoveUserRole = string[]
@@ -0,0 +1,11 @@
1
+ import { User } from 'auth0';
2
+ import UserRepository from './user.repository';
3
+ import { CreateUserValidator, UpdateUserValidator } from './user.validator';
4
+ export default class UserController {
5
+ protected readonly userRepository: UserRepository;
6
+ find(): Promise<User[]>;
7
+ read(id: string): Promise<User>;
8
+ create(validator: CreateUserValidator): Promise<User>;
9
+ update(id: string, validator: UpdateUserValidator): Promise<User>;
10
+ delete(id: string): Promise<void>;
11
+ }
@@ -0,0 +1,39 @@
1
+ import { Body, Controller, Delete, Get, HttpCode, Inject, Param, Patch, Post } from '@nestjs/common'
2
+ import { ApiTags } from '@nestjs/swagger'
3
+ import { User } from 'auth0'
4
+ import { UserEntity } from './user.entity'
5
+ import UserRepository from './user.repository'
6
+ import { CreateUserValidator, UpdateUserValidator } from './user.validator'
7
+
8
+ @Controller(UserEntity.$path)
9
+ @ApiTags(UserController.name)
10
+ export default class UserController {
11
+ @Inject() protected readonly userRepository: UserRepository
12
+
13
+ @Get('/')
14
+ async find (): Promise<User[]> {
15
+ return this.userRepository.find()
16
+ }
17
+
18
+ @Get('/:id')
19
+ async read (@Param('id') id: string): Promise<User> {
20
+ return this.userRepository.read(id)
21
+ }
22
+
23
+ @Post('/')
24
+ @HttpCode(201)
25
+ async create (@Body() validator: CreateUserValidator): Promise<User> {
26
+ return this.userRepository.create(validator)
27
+ }
28
+
29
+ @Patch('/:id')
30
+ async update (@Param('id') id: string, @Body() validator: UpdateUserValidator): Promise<User> {
31
+ return this.userRepository.update(id, validator)
32
+ }
33
+
34
+ @Delete('/:id')
35
+ @HttpCode(204)
36
+ async delete (@Param('id') id: string): Promise<void> {
37
+ return this.userRepository.delete(id)
38
+ }
39
+ }
@@ -0,0 +1,32 @@
1
+ import { AppMetadata, Identity, User, UserMetadata } from 'auth0';
2
+ import AppEntity from '../../app.entity';
3
+ export interface UserData extends UserMetadata {
4
+ [propName: string]: any;
5
+ }
6
+ export interface AppData extends AppMetadata {
7
+ [propName: string]: any;
8
+ }
9
+ export declare class UserEntity extends AppEntity implements User<AppData, UserData> {
10
+ static readonly $path: string;
11
+ blocked: boolean | undefined;
12
+ created_at: string | undefined;
13
+ email: string | undefined;
14
+ email_verified: boolean | undefined;
15
+ family_name: string | undefined;
16
+ given_name: string | undefined;
17
+ identities: Identity[] | undefined;
18
+ last_ip: string | undefined;
19
+ last_login: string | undefined;
20
+ last_password_reset: string | undefined;
21
+ logins_count: number | undefined;
22
+ multifactor: string[] | undefined;
23
+ name: string | undefined;
24
+ nickname: string | undefined;
25
+ phone_number: string | undefined;
26
+ phone_verified: boolean | undefined;
27
+ picture: string | undefined;
28
+ updated_at: string | undefined;
29
+ user_id: string | undefined;
30
+ user_metadata: UserData | undefined;
31
+ username: string | undefined;
32
+ }