@merkaly/api 0.1.7 → 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.
- package/package.json +32 -40
- package/src/account/account.module.d.ts +4 -0
- package/src/account/account.module.ts +15 -0
- package/src/account/auth/auth.controller.d.ts +10 -0
- package/src/account/auth/auth.controller.ts +38 -0
- package/src/account/auth/auth.module.d.ts +4 -0
- package/src/account/auth/auth.module.ts +26 -0
- package/src/account/auth/auth.repository.d.ts +6 -0
- package/src/account/auth/auth.repository.ts +39 -0
- package/src/account/organizations/members/member.controller.d.ts +9 -0
- package/src/account/organizations/members/member.controller.ts +33 -0
- package/src/account/organizations/members/member.module.d.ts +4 -0
- package/src/account/organizations/members/member.module.ts +14 -0
- package/src/account/organizations/members/member.repository.d.ts +12 -0
- package/src/account/organizations/members/member.repository.ts +43 -0
- package/src/account/organizations/members/member.validator.d.ts +2 -0
- package/src/account/organizations/members/member.validator.ts +3 -0
- package/src/account/organizations/organization.controller.d.ts +11 -0
- package/src/account/organizations/organization.controller.ts +42 -0
- package/src/account/organizations/organization.entity.d.ts +3 -1
- package/src/account/organizations/organization.entity.ts +4 -1
- package/src/account/organizations/organization.module.d.ts +4 -0
- package/src/account/organizations/organization.module.ts +16 -0
- package/src/account/organizations/organization.repository.d.ts +12 -0
- package/src/account/organizations/organization.repository.ts +74 -0
- package/src/account/organizations/organization.validator.ts +11 -0
- package/src/account/roles/role.controller.d.ts +11 -0
- package/src/account/roles/role.controller.ts +39 -0
- package/src/account/roles/role.module.d.ts +4 -0
- package/src/account/roles/role.module.ts +15 -0
- package/src/account/roles/role.repository.d.ts +12 -0
- package/src/account/roles/role.repository.ts +63 -0
- package/src/account/roles/users/user.controller.d.ts +8 -0
- package/src/account/roles/users/user.controller.ts +28 -0
- package/src/account/roles/users/user.module.d.ts +4 -0
- package/src/account/roles/users/user.module.ts +14 -0
- package/src/account/roles/users/user.repository.d.ts +11 -0
- package/src/account/roles/users/user.repository.ts +34 -0
- package/src/account/roles/users/user.validator.d.ts +2 -4
- package/src/account/roles/users/user.validator.ts +2 -9
- package/src/account/users/roles/role.controller.d.ts +9 -0
- package/src/account/users/roles/role.controller.ts +34 -0
- package/src/account/users/roles/role.module.d.ts +4 -0
- package/src/account/users/roles/role.module.ts +14 -0
- package/src/account/users/roles/role.repository.d.ts +12 -0
- package/src/account/users/roles/role.repository.ts +38 -0
- package/src/account/users/roles/role.validator.d.ts +2 -4
- package/src/account/users/roles/role.validator.ts +2 -9
- package/src/account/users/user.controller.d.ts +11 -0
- package/src/account/users/user.controller.ts +39 -0
- package/src/account/users/user.module.d.ts +4 -0
- package/src/account/users/user.module.ts +15 -0
- package/src/account/users/user.repository.d.ts +12 -0
- package/src/account/users/user.repository.ts +53 -0
- package/src/account/users/user.validator.d.ts +3 -3
- package/src/account/users/user.validator.ts +7 -7
- package/src/app.d.ts +1 -0
- package/src/app.emitter.d.ts +16 -0
- package/src/app.emitter.ts +27 -0
- package/src/app.entity.d.ts +7 -0
- package/src/app.module.d.ts +9 -0
- package/src/app.module.ts +45 -0
- package/src/app.repository.d.ts +5 -0
- package/src/app.repository.ts +12 -0
- package/src/app.routes.d.ts +3 -0
- package/src/app.routes.ts +61 -0
- package/src/inventory/brands/brand.controller.d.ts +11 -0
- package/src/inventory/brands/brand.controller.ts +41 -0
- package/src/inventory/brands/brand.module.d.ts +4 -0
- package/src/inventory/brands/brand.module.ts +14 -0
- package/src/inventory/brands/brand.repository.d.ts +13 -0
- package/src/inventory/brands/brand.repository.ts +36 -0
- package/src/inventory/categories/category.controller.d.ts +11 -0
- package/src/inventory/categories/category.controller.ts +43 -0
- package/src/inventory/categories/category.module.d.ts +4 -0
- package/src/inventory/categories/category.module.ts +14 -0
- package/src/inventory/categories/category.repository.d.ts +13 -0
- package/src/inventory/categories/category.repository.ts +36 -0
- package/src/inventory/inventory.module.d.ts +4 -0
- package/src/inventory/inventory.module.ts +17 -0
- package/src/inventory/products/media/media.controller.d.ts +7 -0
- package/src/inventory/products/media/media.controller.ts +23 -0
- package/src/inventory/products/media/media.module.d.ts +4 -0
- package/src/inventory/products/media/media.module.ts +14 -0
- package/src/inventory/products/media/media.repository.d.ts +10 -0
- package/src/inventory/products/media/media.repository.ts +22 -0
- package/src/inventory/products/product.controller.d.ts +12 -0
- package/src/inventory/products/product.controller.ts +59 -0
- package/src/inventory/products/product.module.d.ts +4 -0
- package/src/inventory/products/product.module.ts +16 -0
- package/src/inventory/products/product.repository.d.ts +18 -0
- package/src/inventory/products/product.repository.ts +94 -0
- package/src/inventory/products/variants/variant.controller.d.ts +7 -0
- package/src/inventory/products/variants/variant.controller.ts +23 -0
- package/src/inventory/products/variants/variant.module.d.ts +4 -0
- package/src/inventory/products/variants/variant.module.ts +14 -0
- package/src/inventory/products/variants/variant.repository.d.ts +10 -0
- package/src/inventory/products/variants/variant.repository.ts +23 -0
- package/src/inventory/properties/property.controller.d.ts +11 -0
- package/src/inventory/properties/property.controller.ts +42 -0
- package/src/inventory/properties/property.module.d.ts +4 -0
- package/src/inventory/properties/property.module.ts +14 -0
- package/src/inventory/properties/property.repository.d.ts +13 -0
- package/src/inventory/properties/property.repository.ts +38 -0
- package/src/store/carts/cart.controller.d.ts +11 -0
- package/src/store/carts/cart.controller.ts +44 -0
- package/src/store/carts/cart.module.d.ts +4 -0
- package/src/store/carts/cart.module.ts +14 -0
- package/src/store/carts/cart.repository.d.ts +13 -0
- package/src/store/carts/cart.repository.ts +36 -0
- package/src/store/orders/items/item.controller.d.ts +11 -0
- package/src/store/orders/items/item.controller.ts +41 -0
- package/src/store/orders/items/item.module.d.ts +4 -0
- package/src/store/orders/items/item.module.ts +14 -0
- package/src/store/orders/items/item.repository.d.ts +13 -0
- package/src/store/orders/items/item.repository.ts +35 -0
- package/src/store/orders/order.controller.d.ts +11 -0
- package/src/store/orders/order.controller.ts +44 -0
- package/src/store/orders/order.module.d.ts +4 -0
- package/src/store/orders/order.module.ts +15 -0
- package/src/store/orders/order.repository.d.ts +13 -0
- package/src/store/orders/order.repository.ts +35 -0
- package/src/store/store.module.d.ts +4 -0
- package/src/store/store.module.ts +14 -0
- package/src/app.ts +0 -40
package/package.json
CHANGED
|
@@ -1,88 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkaly/api",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9-1",
|
|
4
4
|
"description": "NestJS Backend ApiRest Service",
|
|
5
5
|
"author": "Randy Tellez Galan <kronhyx@gmail.com>",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"main": "src",
|
|
8
|
-
"files": [
|
|
9
|
-
"!src/app.*.*",
|
|
10
|
-
"!src/**/*.js",
|
|
11
|
-
"!src/**/*.module.*",
|
|
12
|
-
"!src/**/*.controller.*",
|
|
13
|
-
"!src/**/*.repository.*",
|
|
14
|
-
"src/**/*.entity.ts",
|
|
15
|
-
"src/**/*.validator.ts"
|
|
16
|
-
],
|
|
17
8
|
"scripts": {
|
|
18
|
-
"prebuild": "
|
|
19
|
-
"prepack": "
|
|
9
|
+
"prebuild": "yarn run clean",
|
|
10
|
+
"prepack": "yarn build",
|
|
20
11
|
"build": "nest build",
|
|
21
12
|
"clean": "tsc -b --clean",
|
|
22
13
|
"start": "nest start --preserveWatchOutput",
|
|
23
|
-
"dev": "
|
|
24
|
-
"start:debug": "
|
|
14
|
+
"dev": "yarn run clean && npm start -- --watch",
|
|
15
|
+
"start:debug": "yarn dev -- --debug ",
|
|
25
16
|
"start:prod": "node dist/index.js",
|
|
26
17
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" . ",
|
|
27
18
|
"test": "jest",
|
|
28
|
-
"test:watch": "
|
|
29
|
-
"test:cov": "
|
|
19
|
+
"test:watch": "yarn test -- --watch",
|
|
20
|
+
"test:cov": "yarn test -- --coverage",
|
|
30
21
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
31
|
-
"semantic-release": "
|
|
22
|
+
"semantic-release": "yarn run build:package && semantic-release"
|
|
32
23
|
},
|
|
33
24
|
"dependencies": {
|
|
25
|
+
"@nestjs/axios": "^0.0.5",
|
|
34
26
|
"@nestjs/swagger": "^5.0.9",
|
|
35
27
|
"@types/auth0": "^2.33.4",
|
|
36
|
-
"@types/node": "^
|
|
28
|
+
"@types/node": "^17.0.2",
|
|
37
29
|
"auth0": "^2.35.0",
|
|
38
|
-
"class-transformer": "^0.
|
|
30
|
+
"class-transformer": "^0.5.1",
|
|
39
31
|
"class-validator": "^0.13.1",
|
|
40
|
-
"fireorm": "^0.
|
|
32
|
+
"fireorm": "^0.23.0",
|
|
41
33
|
"reflect-metadata": "^0.1.13"
|
|
42
34
|
},
|
|
43
35
|
"devDependencies": {
|
|
44
|
-
"@commitlint/config-conventional": "^
|
|
36
|
+
"@commitlint/config-conventional": "^16.0.0",
|
|
45
37
|
"@elastic/elasticsearch": "^7.13.0",
|
|
46
|
-
"@nestjs/cli": "8.
|
|
47
|
-
"@nestjs/common": "8.
|
|
38
|
+
"@nestjs/cli": "8.2.0",
|
|
39
|
+
"@nestjs/common": "8.2.6",
|
|
48
40
|
"@nestjs/config": "^1.0.0",
|
|
49
|
-
"@nestjs/core": "8.
|
|
41
|
+
"@nestjs/core": "8.2.6",
|
|
50
42
|
"@nestjs/elasticsearch": "8.0.0",
|
|
51
43
|
"@nestjs/event-emitter": "^1.0.0",
|
|
52
44
|
"@nestjs/jwt": "8.0.0",
|
|
53
|
-
"@nestjs/passport": "8.0
|
|
54
|
-
"@nestjs/platform-express": "8.
|
|
55
|
-
"@nestjs/schematics": "8.0.
|
|
56
|
-
"@nestjs/testing": "8.
|
|
57
|
-
"@semantic-release/exec": "^
|
|
58
|
-
"@semantic-release/git": "^
|
|
45
|
+
"@nestjs/passport": "8.1.0",
|
|
46
|
+
"@nestjs/platform-express": "8.2.6",
|
|
47
|
+
"@nestjs/schematics": "8.0.5",
|
|
48
|
+
"@nestjs/testing": "8.2.6",
|
|
49
|
+
"@semantic-release/exec": "^6.0.1",
|
|
50
|
+
"@semantic-release/git": "^10.0.0",
|
|
59
51
|
"@types/express": "^4.17.12",
|
|
60
|
-
"@types/faker": "^5.5.
|
|
52
|
+
"@types/faker": "^5.5.9",
|
|
61
53
|
"@types/jest": "^27.0.0",
|
|
62
54
|
"@types/multer": "^1.4.7",
|
|
63
55
|
"@types/passport-jwt": "^3.0.5",
|
|
64
56
|
"@types/supertest": "^2.0.11",
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "4.
|
|
66
|
-
"@typescript-eslint/parser": "4.
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "4.33.0",
|
|
58
|
+
"@typescript-eslint/parser": "4.33.0",
|
|
59
|
+
"commitlint": "^16.1.0",
|
|
67
60
|
"eslint": "7.32.0",
|
|
68
61
|
"eslint-plugin-import": "^2.23.4",
|
|
69
62
|
"faker": "^5.5.3",
|
|
70
|
-
"firebase": "^
|
|
71
|
-
"firebase-admin": "^
|
|
63
|
+
"firebase": "^9.0.0",
|
|
64
|
+
"firebase-admin": "^10.0.2",
|
|
72
65
|
"husky": "^7.0.0",
|
|
73
|
-
"jest": "27.
|
|
66
|
+
"jest": "27.4.7",
|
|
74
67
|
"passport": "^0.4.1",
|
|
75
68
|
"passport-jwt": "^4.0.0",
|
|
76
69
|
"rimraf": "^3.0.2",
|
|
77
70
|
"rxjs": "^7.2.0",
|
|
78
|
-
"semantic-release": "^
|
|
71
|
+
"semantic-release": "^18.0.0",
|
|
79
72
|
"supertest": "^6.1.3",
|
|
80
73
|
"swagger-ui-express": "^4.1.5",
|
|
81
|
-
"ts-jest": "27.
|
|
74
|
+
"ts-jest": "27.1.3",
|
|
82
75
|
"ts-loader": "^9.2.3",
|
|
83
76
|
"ts-node": "^10.0.0",
|
|
84
|
-
"tsconfig-paths": "^3.9.0"
|
|
85
|
-
"typescript": "^4.3.4"
|
|
77
|
+
"tsconfig-paths": "^3.9.0"
|
|
86
78
|
},
|
|
87
79
|
"repository": {
|
|
88
80
|
"type": "git",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Module, ModuleMetadata } from '@nestjs/common'
|
|
2
|
+
import OrganizationModule from './organizations/organization.module'
|
|
3
|
+
import RoleModule from './roles/role.module'
|
|
4
|
+
import UserModule from './users/user.module'
|
|
5
|
+
|
|
6
|
+
export const metadata: ModuleMetadata = {
|
|
7
|
+
imports: [UserModule, OrganizationModule, RoleModule],
|
|
8
|
+
controllers: [],
|
|
9
|
+
providers: [],
|
|
10
|
+
exports: []
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Module(metadata)
|
|
14
|
+
export default class AccountModule {
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TokenResponse, User as Auth0User } from 'auth0';
|
|
2
|
+
import UserRepository from '../users/user.repository';
|
|
3
|
+
import AuthRepository from './auth.repository';
|
|
4
|
+
import { LoginValidator } from './auth.validator';
|
|
5
|
+
export default class AuthController {
|
|
6
|
+
protected readonly authRepository: AuthRepository;
|
|
7
|
+
protected readonly userRepository: UserRepository;
|
|
8
|
+
login({ username, password }: LoginValidator): Promise<Partial<TokenResponse>>;
|
|
9
|
+
user(user: string): Promise<Auth0User>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Body, Controller, Get, HttpException, Inject, Post } from '@nestjs/common'
|
|
2
|
+
import { ApiTags } from '@nestjs/swagger'
|
|
3
|
+
import { PasswordGrantOptions, TokenResponse, User as Auth0User } from 'auth0'
|
|
4
|
+
import UserRepository from '../users/user.repository'
|
|
5
|
+
import { Public, User } from './auth.decorator'
|
|
6
|
+
import AuthRepository from './auth.repository'
|
|
7
|
+
import { LoginValidator } from './auth.validator'
|
|
8
|
+
|
|
9
|
+
@Controller()
|
|
10
|
+
@ApiTags(AuthController.name)
|
|
11
|
+
export default class AuthController {
|
|
12
|
+
@Inject() protected readonly authRepository: AuthRepository
|
|
13
|
+
@Inject() protected readonly userRepository: UserRepository
|
|
14
|
+
|
|
15
|
+
@Public()
|
|
16
|
+
@Post('/login')
|
|
17
|
+
async login (@Body() { username, password }: LoginValidator): Promise<Partial<TokenResponse>> {
|
|
18
|
+
const options: PasswordGrantOptions = {
|
|
19
|
+
username,
|
|
20
|
+
password,
|
|
21
|
+
scope: 'openid'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return this.authRepository.client.passwordGrant(options)
|
|
25
|
+
.then(({ access_token, refresh_token, expires_in }) => ({ access_token, refresh_token, expires_in }))
|
|
26
|
+
.catch(({ message, statusCode, originalError }) => {
|
|
27
|
+
const description = originalError.response.res.statusMessage
|
|
28
|
+
|
|
29
|
+
throw new HttpException({ ...JSON.parse(message), message: description }, statusCode)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Get('/user')
|
|
34
|
+
async user (@User() user: string): Promise<Auth0User> {
|
|
35
|
+
return this.userRepository.read(user)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Global, Module, ModuleMetadata } from '@nestjs/common'
|
|
2
|
+
import { ElasticsearchModule } from '@nestjs/elasticsearch'
|
|
3
|
+
import { JwtModule } from '@nestjs/jwt'
|
|
4
|
+
import { PassportModule } from '@nestjs/passport'
|
|
5
|
+
import AppConfig from '../../app.config'
|
|
6
|
+
import UserRepository from '../users/user.repository'
|
|
7
|
+
import AuthController from './auth.controller'
|
|
8
|
+
import AuthGuard from './auth.guard'
|
|
9
|
+
import AuthRepository from './auth.repository'
|
|
10
|
+
import AuthStrategy from './auth.strategy'
|
|
11
|
+
|
|
12
|
+
export const metadata: ModuleMetadata = {
|
|
13
|
+
imports: [
|
|
14
|
+
PassportModule.register({ session: true }),
|
|
15
|
+
JwtModule.register({ signOptions: { expiresIn: '60m' } }),
|
|
16
|
+
ElasticsearchModule.register(AppConfig.elasticsearch)
|
|
17
|
+
],
|
|
18
|
+
controllers: [AuthController],
|
|
19
|
+
providers: [AuthRepository, AuthStrategy, AuthRepository, AuthGuard, UserRepository],
|
|
20
|
+
exports: [AuthRepository, ElasticsearchModule]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Global()
|
|
24
|
+
@Module(metadata)
|
|
25
|
+
export default class AuthModule {
|
|
26
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common'
|
|
2
|
+
import { JwtService } from '@nestjs/jwt'
|
|
3
|
+
import { AuthenticationClient, ClientCredentialsGrantOptions, ManagementClient } from 'auth0'
|
|
4
|
+
import axios from 'axios'
|
|
5
|
+
import AppConfig from '../../app.config'
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export default class AuthRepository {
|
|
9
|
+
@Inject() private jwtService: JwtService
|
|
10
|
+
|
|
11
|
+
get client (): AuthenticationClient {
|
|
12
|
+
return new AuthenticationClient({
|
|
13
|
+
domain: AppConfig.auth0.domain,
|
|
14
|
+
clientId: AppConfig.auth0.client,
|
|
15
|
+
clientSecret: AppConfig.auth0.secret
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
$management (): Promise<ManagementClient> {
|
|
20
|
+
const options: ClientCredentialsGrantOptions = {
|
|
21
|
+
audience: AppConfig.auth0.audience
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return this.client.clientCredentialsGrant(options)
|
|
25
|
+
.then(({ access_token }) => {
|
|
26
|
+
axios.defaults.baseURL = AppConfig.auth0.audience.replace(/^\/|\/$/g, '')
|
|
27
|
+
axios.defaults.headers['authorization'] = `Bearer ${access_token}`
|
|
28
|
+
|
|
29
|
+
const options = {
|
|
30
|
+
domain: AppConfig.auth0.domain,
|
|
31
|
+
clientId: AppConfig.auth0.client,
|
|
32
|
+
clientSecret: AppConfig.auth0.secret,
|
|
33
|
+
token: access_token
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return new ManagementClient(options)
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OrganizationMemberEntity } from './member.entity';
|
|
2
|
+
import MemberRepository from './member.repository';
|
|
3
|
+
import { AddOrganizationMembers, RemoveOrganizationMembers } from './member.validator';
|
|
4
|
+
export default class MemberController {
|
|
5
|
+
protected readonly repository: MemberRepository;
|
|
6
|
+
find(org: string): Promise<OrganizationMemberEntity[]>;
|
|
7
|
+
assign(org: string, members: AddOrganizationMembers): Promise<void>;
|
|
8
|
+
remove(org: string, members: RemoveOrganizationMembers): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Body, Controller, Delete, Get, Inject, Param, Post } from '@nestjs/common'
|
|
2
|
+
import { ApiTags } from '@nestjs/swagger'
|
|
3
|
+
import { OrganizationMemberEntity } from './member.entity'
|
|
4
|
+
import MemberRepository from './member.repository'
|
|
5
|
+
import { AddOrganizationMembers, RemoveOrganizationMembers } from './member.validator'
|
|
6
|
+
|
|
7
|
+
@Controller(':org/' + OrganizationMemberEntity.$path)
|
|
8
|
+
@ApiTags(MemberController.name)
|
|
9
|
+
export default class MemberController {
|
|
10
|
+
@Inject() protected readonly repository: MemberRepository
|
|
11
|
+
|
|
12
|
+
@Get('/')
|
|
13
|
+
async find (@Param('org') org: string): Promise<OrganizationMemberEntity[]> {
|
|
14
|
+
this.repository.organizationId = org
|
|
15
|
+
|
|
16
|
+
return this.repository.find()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Post('/')
|
|
20
|
+
async assign (@Param('org') org: string, @Body() members: AddOrganizationMembers): Promise<void> {
|
|
21
|
+
this.repository.organizationId = org
|
|
22
|
+
|
|
23
|
+
return this.repository.assign(members)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Delete('/')
|
|
27
|
+
async remove (@Param('org') org: string, @Body() members: RemoveOrganizationMembers): Promise<void> {
|
|
28
|
+
this.repository.organizationId = org
|
|
29
|
+
|
|
30
|
+
return this.repository.remove(members)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Module, ModuleMetadata } from '@nestjs/common'
|
|
2
|
+
import MemberController from './member.controller'
|
|
3
|
+
import MemberRepository from './member.repository'
|
|
4
|
+
|
|
5
|
+
export const metadata: ModuleMetadata = {
|
|
6
|
+
imports: [],
|
|
7
|
+
controllers: [MemberController],
|
|
8
|
+
providers: [MemberRepository],
|
|
9
|
+
exports: []
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Module(metadata)
|
|
13
|
+
export default class MemberModule {
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import AuthRepository from '../../auth/auth.repository';
|
|
2
|
+
import { OrganizationMemberEntity } from './member.entity';
|
|
3
|
+
import { AddOrganizationMembers, RemoveOrganizationMembers } from './member.validator';
|
|
4
|
+
export default class MemberRepository {
|
|
5
|
+
protected readonly authService: AuthRepository;
|
|
6
|
+
$organizationId: any;
|
|
7
|
+
set organizationId(id: string);
|
|
8
|
+
find(): Promise<OrganizationMemberEntity[]>;
|
|
9
|
+
assign(members: AddOrganizationMembers): Promise<void>;
|
|
10
|
+
remove(members: RemoveOrganizationMembers): Promise<void>;
|
|
11
|
+
private $auth0;
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common'
|
|
2
|
+
import { ManagementClient } from 'auth0'
|
|
3
|
+
import axios from 'axios'
|
|
4
|
+
import { join } from 'path'
|
|
5
|
+
import AuthRepository from '../../auth/auth.repository'
|
|
6
|
+
import { OrganizationMemberEntity } from './member.entity'
|
|
7
|
+
import { AddOrganizationMembers, RemoveOrganizationMembers } from './member.validator'
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export default class MemberRepository {
|
|
11
|
+
@Inject() protected readonly authService: AuthRepository
|
|
12
|
+
public $organizationId = null
|
|
13
|
+
|
|
14
|
+
public set organizationId (id: string) {
|
|
15
|
+
this.$organizationId = id
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async find (): Promise<OrganizationMemberEntity[]> {
|
|
19
|
+
await this.$auth0()
|
|
20
|
+
|
|
21
|
+
const { data } = await axios.get(join('organizations', this.$organizationId, '/members'))
|
|
22
|
+
|
|
23
|
+
return data
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async assign (members: AddOrganizationMembers): Promise<void> {
|
|
27
|
+
await this.$auth0()
|
|
28
|
+
|
|
29
|
+
await axios.post(join('organizations', this.$organizationId, '/members'), { members })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async remove (members: RemoveOrganizationMembers): Promise<void> {
|
|
33
|
+
await this.$auth0()
|
|
34
|
+
|
|
35
|
+
await axios.delete(join('organizations', this.$organizationId, '/members'), {
|
|
36
|
+
data: { members }
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private async $auth0 (): Promise<ManagementClient> {
|
|
41
|
+
return this.authService.$management()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OrganizationEntity } from './organization.entity';
|
|
2
|
+
import OrganizationRepository from './organization.repository';
|
|
3
|
+
import { CreateOrganizationValidator, UpdateOrganizationValidator } from './organization.validator';
|
|
4
|
+
export default class OrganizationController {
|
|
5
|
+
protected readonly repository: OrganizationRepository;
|
|
6
|
+
find(): Promise<OrganizationEntity[]>;
|
|
7
|
+
create(validator: CreateOrganizationValidator): Promise<OrganizationEntity>;
|
|
8
|
+
read(id: string): Promise<OrganizationEntity>;
|
|
9
|
+
update(validator: UpdateOrganizationValidator, id: string): Promise<OrganizationEntity>;
|
|
10
|
+
delete(id: string): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Body, Controller, Delete, Get, Inject, Param, Patch, Post } from '@nestjs/common'
|
|
2
|
+
import { ApiTags } from '@nestjs/swagger'
|
|
3
|
+
import { OrganizationEntity } from './organization.entity'
|
|
4
|
+
import OrganizationRepository from './organization.repository'
|
|
5
|
+
import { CreateOrganizationValidator, UpdateOrganizationValidator } from './organization.validator'
|
|
6
|
+
|
|
7
|
+
@Controller(OrganizationEntity.$path)
|
|
8
|
+
@ApiTags(OrganizationController.name)
|
|
9
|
+
export default class OrganizationController {
|
|
10
|
+
@Inject() protected readonly repository: OrganizationRepository
|
|
11
|
+
|
|
12
|
+
@Get('/')
|
|
13
|
+
async find (): Promise<OrganizationEntity[]> {
|
|
14
|
+
|
|
15
|
+
return this.repository.find()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Post('/')
|
|
19
|
+
async create (@Body() validator: CreateOrganizationValidator): Promise<OrganizationEntity> {
|
|
20
|
+
|
|
21
|
+
return this.repository.create(validator)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Get('/:id')
|
|
25
|
+
async read (@Param('id') id: string): Promise<OrganizationEntity> {
|
|
26
|
+
|
|
27
|
+
return this.repository.read(id)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Patch('/:id')
|
|
31
|
+
async update (@Body() validator: UpdateOrganizationValidator, @Param('id') id: string): Promise<OrganizationEntity> {
|
|
32
|
+
|
|
33
|
+
return this.repository.update(id, validator)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Delete('/:id')
|
|
37
|
+
async delete (@Param('id') id: string): Promise<void> {
|
|
38
|
+
|
|
39
|
+
return this.repository.delete(id)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Organization } from 'auth0';
|
|
1
2
|
import AppEntity from '../../app.entity';
|
|
2
3
|
export interface OrganizationBrandingColors {
|
|
3
4
|
page_background: string;
|
|
@@ -7,9 +8,10 @@ export interface OrganizationBranding {
|
|
|
7
8
|
logo_url: string;
|
|
8
9
|
colors: OrganizationBrandingColors;
|
|
9
10
|
}
|
|
10
|
-
export declare class OrganizationEntity extends AppEntity {
|
|
11
|
+
export declare class OrganizationEntity extends AppEntity implements Organization {
|
|
11
12
|
static readonly $path = "organizations";
|
|
12
13
|
name: string;
|
|
13
14
|
display_name: string;
|
|
14
15
|
branding: OrganizationBranding;
|
|
16
|
+
metadata: Record<string, string>;
|
|
15
17
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Organization } from 'auth0'
|
|
1
2
|
import AppEntity from '../../app.entity'
|
|
2
3
|
|
|
3
4
|
export interface OrganizationBrandingColors {
|
|
@@ -10,7 +11,7 @@ export interface OrganizationBranding {
|
|
|
10
11
|
colors: OrganizationBrandingColors
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export class OrganizationEntity extends AppEntity {
|
|
14
|
+
export class OrganizationEntity extends AppEntity implements Organization {
|
|
14
15
|
static readonly $path = 'organizations'
|
|
15
16
|
|
|
16
17
|
public name: string
|
|
@@ -18,4 +19,6 @@ export class OrganizationEntity extends AppEntity {
|
|
|
18
19
|
public display_name: string
|
|
19
20
|
|
|
20
21
|
public branding: OrganizationBranding
|
|
22
|
+
|
|
23
|
+
public metadata: Record<string, string>
|
|
21
24
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Module, ModuleMetadata } from '@nestjs/common'
|
|
2
|
+
import MemberModule from './members/member.module'
|
|
3
|
+
import OrganizationController from './organization.controller'
|
|
4
|
+
import OrganizationRepository from './organization.repository'
|
|
5
|
+
|
|
6
|
+
export const metadata: ModuleMetadata = {
|
|
7
|
+
imports: [MemberModule],
|
|
8
|
+
controllers: [OrganizationController],
|
|
9
|
+
providers: [OrganizationRepository],
|
|
10
|
+
exports: []
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Module(metadata)
|
|
14
|
+
export default class OrganizationModule {
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import AuthRepository from '../auth/auth.repository';
|
|
2
|
+
import { OrganizationEntity } from './organization.entity';
|
|
3
|
+
import { CreateOrganizationValidator, UpdateOrganizationValidator } from './organization.validator';
|
|
4
|
+
export default class OrganizationRepository {
|
|
5
|
+
protected readonly authService: AuthRepository;
|
|
6
|
+
find(): Promise<OrganizationEntity[]>;
|
|
7
|
+
read(id: string): Promise<OrganizationEntity>;
|
|
8
|
+
create(validator: CreateOrganizationValidator): Promise<OrganizationEntity>;
|
|
9
|
+
update(id: string, validator: UpdateOrganizationValidator): Promise<OrganizationEntity>;
|
|
10
|
+
delete(id: string): Promise<void>;
|
|
11
|
+
private $auth0;
|
|
12
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common'
|
|
2
|
+
import { CreateOrganization, ManagementClient, UpdateOrganization } from 'auth0'
|
|
3
|
+
import axios from 'axios'
|
|
4
|
+
import { join } from 'path'
|
|
5
|
+
import AuthRepository from '../auth/auth.repository'
|
|
6
|
+
import { OrganizationEntity } from './organization.entity'
|
|
7
|
+
import { CreateOrganizationValidator, UpdateOrganizationValidator } from './organization.validator'
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export default class OrganizationRepository {
|
|
11
|
+
@Inject() protected readonly authService: AuthRepository
|
|
12
|
+
|
|
13
|
+
public async find (): Promise<OrganizationEntity[]> {
|
|
14
|
+
await this.$auth0()
|
|
15
|
+
|
|
16
|
+
return axios.get('organizations')
|
|
17
|
+
.then(({ data }) => data)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public async read (id: string): Promise<OrganizationEntity> {
|
|
21
|
+
await this.$auth0()
|
|
22
|
+
|
|
23
|
+
return axios.get<OrganizationEntity>(join('organizations', id))
|
|
24
|
+
.then(({ data }) => data)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async create (validator: CreateOrganizationValidator): Promise<OrganizationEntity> {
|
|
28
|
+
await this.$auth0()
|
|
29
|
+
|
|
30
|
+
const organization: CreateOrganization = {
|
|
31
|
+
name: validator.name,
|
|
32
|
+
display_name: validator.display_name,
|
|
33
|
+
branding: {
|
|
34
|
+
logo_url: validator.logo_url,
|
|
35
|
+
colors: {
|
|
36
|
+
primary: validator.primary_color,
|
|
37
|
+
page_background: validator.secondary_color
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return axios.post<OrganizationEntity>('organizations', organization)
|
|
43
|
+
.then(({ data }) => data)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async update (id: string, validator: UpdateOrganizationValidator): Promise<OrganizationEntity> {
|
|
47
|
+
await this.$auth0()
|
|
48
|
+
|
|
49
|
+
const organization: UpdateOrganization = {
|
|
50
|
+
display_name: validator.display_name,
|
|
51
|
+
branding: {
|
|
52
|
+
logo_url: validator.logo_url,
|
|
53
|
+
colors: {
|
|
54
|
+
primary: validator.primary_color,
|
|
55
|
+
page_background: validator.secondary_color
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return axios.patch<OrganizationEntity>(join('organizations', id), organization)
|
|
61
|
+
.then(({ data }) => data)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async delete (id: string): Promise<void> {
|
|
65
|
+
await this.$auth0()
|
|
66
|
+
|
|
67
|
+
return axios.delete<void>(join('organizations', id))
|
|
68
|
+
.then(({ data }) => data)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private async $auth0 (): Promise<ManagementClient> {
|
|
72
|
+
return this.authService.$management()
|
|
73
|
+
}
|
|
74
|
+
}
|