mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-23 12:29:08 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b20f67e8b8 | ||
|
|
4a8a8eb463 | ||
|
|
d52f8b78c8 | ||
|
|
bfbe7cce87 | ||
|
|
1ab8c1dd10 | ||
|
|
246de83142 | ||
|
|
dfa6222538 | ||
|
|
b64619ede1 | ||
|
|
4a08e5f560 | ||
|
|
92041f453c | ||
|
|
f2f09cc9c7 | ||
|
|
d486231fd6 | ||
|
|
526a3bddcd | ||
|
|
45108d3019 | ||
|
|
ac3e26b851 | ||
|
|
7fbc919716 | ||
|
|
5b1eb19511 | ||
|
|
b714f3cf36 | ||
|
|
48c1e29168 | ||
|
|
04ea1d0f04 | ||
|
|
0de5e1d5d1 | ||
|
|
b8c41fad1b | ||
|
|
ef9ec5ad42 | ||
|
|
65e71f21a0 | ||
|
|
b921393ba1 | ||
|
|
18aa7d8674 | ||
|
|
f2dd871de2 | ||
|
|
cf3fa88196 | ||
|
|
131810533c | ||
|
|
ea06f3f571 | ||
|
|
81921a7eb2 | ||
|
|
e9fdd0285b | ||
|
|
167470adba | ||
|
|
fbb9a59214 | ||
|
|
ef6d8594a3 | ||
|
|
ac73c0b046 | ||
|
|
5a30bf08b2 | ||
|
|
62b4eb709e | ||
|
|
b37a18d1da | ||
|
|
379bac704f | ||
|
|
9178530a21 | ||
|
|
667d3f874d | ||
|
|
475af224bf | ||
|
|
11f1df5537 | ||
|
|
e3b02571c8 | ||
|
|
979a12aa7f | ||
|
|
7646d7a3c5 | ||
|
|
8f0e851a88 | ||
|
|
779418f471 | ||
|
|
6e6d03f302 | ||
|
|
85f41521ed | ||
|
|
e2bb119745 | ||
|
|
3d5ce59b52 | ||
|
|
1c63271f64 | ||
|
|
31a51c20aa | ||
|
|
62730eb969 | ||
|
|
5a2c760bab | ||
|
|
28b4f3ac4b | ||
|
|
43d181a429 | ||
|
|
a72fe1b60d | ||
|
|
b52a1227b1 | ||
|
|
31478ed61d | ||
|
|
79b1ba910e | ||
|
|
7fd929915b | ||
|
|
e4b27c5f76 | ||
|
|
92e449d6d3 | ||
|
|
5073b2e188 | ||
|
|
8a11eda24d | ||
|
|
9d732d4a48 | ||
|
|
5fa10a939b | ||
|
|
4be3ffe3a2 | ||
|
|
8af9c638ef | ||
|
|
97d6f914cc | ||
|
|
9ad2e3770e | ||
|
|
ea2cc8809f | ||
|
|
410e190e7c | ||
|
|
c1b213c34c | ||
|
|
a6c58eb82d | ||
|
|
b756cb5a1e | ||
|
|
46cafc2d50 | ||
|
|
a087775e3a | ||
|
|
69305610ff | ||
|
|
69008a9ffb | ||
|
|
687b4e40e1 | ||
|
|
d56544568b | ||
|
|
63fbfa6b52 | ||
|
|
2b03c4e4a9 | ||
|
|
18c3c9c58c | ||
|
|
166c45728f | ||
|
|
d0f5da0270 | ||
|
|
dade8d59e5 | ||
|
|
fe261667f8 | ||
|
|
722bb1ec7c | ||
|
|
a371db355b | ||
|
|
1ff135c0d7 |
Generated
+7
-7
@@ -12,7 +12,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.18.7",
|
"@dadosfera/protospack-v2": "3.18.18",
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"@grpc/proto-loader": "^0.6.13",
|
"@grpc/proto-loader": "^0.6.13",
|
||||||
"@nestjs/common": "^8.4.7",
|
"@nestjs/common": "^8.4.7",
|
||||||
@@ -1726,9 +1726,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.18.7",
|
"version": "3.18.18",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.7.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.18.tgz",
|
||||||
"integrity": "sha512-MloW230CUyK+g+HFkSv1OuaJNT5mfEGRh7tpZjjKxO2Qxm4eKkmI9uh/cNXCDzUpRBFXzBJ+5w12bxw2UnMRSw==",
|
"integrity": "sha512-4KiuMUDMZu8ouic0RBBuM7Ky9wfczeS4GKLRyD29GV371m/NOo+1ujrcLysc8OuevPdXmaqzCgE6WWi6SIt9sQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
@@ -12306,9 +12306,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@dadosfera/protospack-v2": {
|
"@dadosfera/protospack-v2": {
|
||||||
"version": "3.18.7",
|
"version": "3.18.18",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.7.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.18.tgz",
|
||||||
"integrity": "sha512-MloW230CUyK+g+HFkSv1OuaJNT5mfEGRh7tpZjjKxO2Qxm4eKkmI9uh/cNXCDzUpRBFXzBJ+5w12bxw2UnMRSw==",
|
"integrity": "sha512-4KiuMUDMZu8ouic0RBBuM7Ky9wfczeS4GKLRyD29GV371m/NOo+1ujrcLysc8OuevPdXmaqzCgE6WWi6SIt9sQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
|
|||||||
+2
-1
@@ -10,6 +10,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "aws codeartifact login --tool npm --namespace @dadosfera --repository dadosfera-npm --domain dadosfera --domain-owner 611330257153 --region us-east-1",
|
"preinstall": "aws codeartifact login --tool npm --namespace @dadosfera --repository dadosfera-npm --domain dadosfera --domain-owner 611330257153 --region us-east-1",
|
||||||
|
"proto-update": "npm i @dadosfera/protospack-v2@latest --save-exact",
|
||||||
"prebuild": "rimraf dist",
|
"prebuild": "rimraf dist",
|
||||||
"build": "nest build",
|
"build": "nest build",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.18.7",
|
"@dadosfera/protospack-v2": "3.18.18",
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"@grpc/proto-loader": "^0.6.13",
|
"@grpc/proto-loader": "^0.6.13",
|
||||||
"@nestjs/common": "^8.4.7",
|
"@nestjs/common": "^8.4.7",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { HealthModule } from './modules/health/health.module';
|
|||||||
import { CatalogModule } from './modules/catalog/catalog.module';
|
import { CatalogModule } from './modules/catalog/catalog.module';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
||||||
|
import { ProductboardModule } from './modules/productboard/productboard.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [],
|
controllers: [],
|
||||||
@@ -54,6 +55,7 @@ import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
|||||||
OauthModule,
|
OauthModule,
|
||||||
PipelinesV2Module,
|
PipelinesV2Module,
|
||||||
CatalogModule,
|
CatalogModule,
|
||||||
|
ProductboardModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
name: {
|
name: {
|
||||||
'pt-br': 'Excluir Fonte',
|
'pt-br': 'Excluir Fonte',
|
||||||
'en-us': 'Remove Source',
|
'en-us': 'Remove Source',
|
||||||
'es-s': 'Eliminar Source',
|
'es-es': 'Eliminar Source',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UPDATE: {
|
UPDATE: {
|
||||||
@@ -325,6 +325,16 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
'es-es': 'Eliminar atributos',
|
'es-es': 'Eliminar atributos',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
DATA_MANAGER: {
|
||||||
|
seqid: 42,
|
||||||
|
claim: 'catalog:data_manager',
|
||||||
|
usage: PermissionUsages.PUBLIC,
|
||||||
|
name: {
|
||||||
|
'pt-br': 'Vizualizar todos os recursos do catálogo.',
|
||||||
|
'en-us': 'View all data assets.',
|
||||||
|
'es-es': 'Ver todos los activos de datos',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import { AuthClientService } from './auth.service';
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@@ -59,20 +60,27 @@ export class AuthController {
|
|||||||
|
|
||||||
@Post('sign-in')
|
@Post('sign-in')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async signIn(@Body() { username, password, totp }: AuthSignInRequest) {
|
async signIn(
|
||||||
|
@Body() { username, password, totp }: AuthSignInRequest,
|
||||||
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
|
) {
|
||||||
this.logger.info('/auth - SignIn');
|
this.logger.info('/auth - SignIn');
|
||||||
|
const metadata = new Metadata();
|
||||||
return this.authClient.signIn({ username, password, totp });
|
metadata.add('language', language || 'pt-br');
|
||||||
|
return this.authClient.signIn({ username, password, totp }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('refresh-access-token')
|
@Post('refresh-access-token')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async refreshAccessToken(
|
async refreshAccessToken(
|
||||||
@Body() { refreshToken }: AuthRefreshAccessTokenRequest,
|
@Body() { refreshToken }: AuthRefreshAccessTokenRequest,
|
||||||
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
) {
|
) {
|
||||||
this.logger.info('/auth - RefreshAccessToken');
|
this.logger.info('/auth - RefreshAccessToken');
|
||||||
|
const metadata = new Metadata();
|
||||||
|
metadata.add('language', language || 'pt-br');
|
||||||
|
|
||||||
return this.authClient.refreshAccessToken({ refreshToken });
|
return this.authClient.refreshAccessToken({ refreshToken }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('change-password')
|
@Post('change-password')
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
AuthConfirmResetPasswordRequest,
|
AuthConfirmResetPasswordRequest,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthClientService implements OnModuleInit {
|
export class AuthClientService implements OnModuleInit {
|
||||||
@@ -51,19 +52,25 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
return lastValueFrom(this.authService.AuthSnowflakeSignIn(input));
|
return lastValueFrom(this.authService.AuthSnowflakeSignIn(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
async signIn({ username, password, totp }: AuthSignInRequest) {
|
async signIn(
|
||||||
|
{ username, password, totp }: AuthSignInRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
) {
|
||||||
this.logger.info('SignIn');
|
this.logger.info('SignIn');
|
||||||
|
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
this.authService.AuthSignIn({ username, password, totp }),
|
this.authService.AuthSignIn({ username, password, totp }, metadata),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshAccessToken({ refreshToken }: AuthRefreshAccessTokenRequest) {
|
async refreshAccessToken(
|
||||||
|
{ refreshToken }: AuthRefreshAccessTokenRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
) {
|
||||||
this.logger.info('RefreshAccessToken');
|
this.logger.info('RefreshAccessToken');
|
||||||
|
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
this.authService.AuthRefreshAccessToken({ refreshToken }),
|
this.authService.AuthRefreshAccessToken({ refreshToken }, metadata),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,23 +3,41 @@ import {
|
|||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
|
Headers,
|
||||||
|
HttpException,
|
||||||
Inject,
|
Inject,
|
||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
|
UnsupportedMediaTypeException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthenticateCondition } from '../../authentication/authentication.decorator';
|
import {
|
||||||
|
AuthenticateCondition,
|
||||||
|
Authenticated,
|
||||||
|
} from '../../authentication/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { CatalogService } from './catalog.service';
|
import { CatalogService } from './catalog.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
|
import {
|
||||||
|
ICatalogAllResponse,
|
||||||
|
IColumnsMetadataResponse,
|
||||||
|
IDeleteComment,
|
||||||
|
IDocsResponse,
|
||||||
|
IMakeAComment,
|
||||||
|
IOneDataAsset,
|
||||||
|
IPreviewResponse,
|
||||||
|
IUpdateDataRequest,
|
||||||
|
} from './dtos';
|
||||||
|
|
||||||
@ApiTags('Catalog')
|
@ApiTags('Catalog')
|
||||||
@Controller('catalog')
|
@Controller('catalog')
|
||||||
|
@Authenticated()
|
||||||
@AuthenticateCondition((req, user) => {
|
@AuthenticateCondition((req, user) => {
|
||||||
|
if (req.path.includes('/manage_permissions/')) return true;
|
||||||
let action;
|
let action;
|
||||||
|
|
||||||
switch (req.method) {
|
switch (req.method) {
|
||||||
@@ -49,56 +67,21 @@ export class CatalogController {
|
|||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('manage_permissions/:id')
|
@Get()
|
||||||
async manageDataAssetPermissions(
|
async catalogAll(
|
||||||
@Param('id') id: string,
|
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body,
|
@Query() query,
|
||||||
) {
|
): Promise<ICatalogAllResponse> {
|
||||||
const { customer_id, customer_name, user_id, username } = user;
|
const { user_id, customer_name, customer_id, username, permissions } = user;
|
||||||
const metadata = PackTheMetadata({
|
this.logger.info(`/catalog - Catalog all data assets`, {
|
||||||
customer_id,
|
|
||||||
customer_name,
|
|
||||||
user_id,
|
user_id,
|
||||||
username,
|
|
||||||
});
|
|
||||||
const response = await this.catalogService.managePermissions(
|
|
||||||
{ ...body, id },
|
|
||||||
metadata,
|
|
||||||
);
|
|
||||||
|
|
||||||
return { data_asset: JSON.parse(response.data_asset) };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put('revoke_permissions/:id')
|
|
||||||
async revokeDataAssetPermissions(
|
|
||||||
@Param('id') id: string,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Body() body,
|
|
||||||
) {
|
|
||||||
const { customer_id, customer_name, user_id, username } = user;
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
customer_id,
|
|
||||||
customer_name,
|
customer_name,
|
||||||
user_id,
|
|
||||||
username,
|
|
||||||
});
|
});
|
||||||
const response = await this.catalogService.revokePermissions(
|
|
||||||
{ ...body, id },
|
const is_data_manager = permissions.includes(
|
||||||
metadata,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
||||||
);
|
);
|
||||||
|
|
||||||
return { message: response.message };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('all')
|
|
||||||
async catalogAll(@User() user: RequestUser, @Body() body, @Query() params) {
|
|
||||||
const { user_id, customer_name, customer_id, username } = user;
|
|
||||||
this.logger.info(`/catalog - ON CATALOG ALL ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const roles = await this.catalogService.getUserRolesIds(user_id);
|
const roles = await this.catalogService.getUserRolesIds(user_id);
|
||||||
|
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
@@ -107,329 +90,16 @@ export class CatalogController {
|
|||||||
customer_name,
|
customer_name,
|
||||||
username,
|
username,
|
||||||
roles,
|
roles,
|
||||||
|
is_data_manager,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.getAllOpenSearchDataAssets(
|
const res = await this.catalogService.getAllOpenSearchDataAssets(
|
||||||
params,
|
query,
|
||||||
metadata,
|
metadata,
|
||||||
|
customer_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.data_assets;
|
return { ...res };
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data_apps')
|
|
||||||
async dataAppsAll(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON FIND ALL DATA APPS ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.dataAppsAll(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete('data_apps/:id')
|
|
||||||
async dataAppsOne(@Param() params, @Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON FIND ONE DATA APP ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
const { id } = params;
|
|
||||||
|
|
||||||
const res = await this.catalogService.dataAppsOne(id, body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('dashboard-metabase')
|
|
||||||
async getAllDashboardMetabase(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET ALL DASHBOARDS METABASE ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getAllDashboardMetabase(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('dashboard-metabase/:id')
|
|
||||||
async getOneDashboardMetabase(
|
|
||||||
@Body() body,
|
|
||||||
@Param() params,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
) {
|
|
||||||
const { id } = params;
|
|
||||||
this.logger.info(`/catalog - ON GET ONE DASHBOARD METABASE ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { username, user_id, customer_id, customer_name } = user;
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
username,
|
|
||||||
user_id,
|
|
||||||
customer_id,
|
|
||||||
customer_name,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getOneDashboardMetabase(
|
|
||||||
id,
|
|
||||||
body,
|
|
||||||
metadata,
|
|
||||||
);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('table-metadata')
|
|
||||||
async getAllTableMetadata(
|
|
||||||
@Body() body,
|
|
||||||
@Query() query,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
) {
|
|
||||||
this.logger.info(`/catalog - ON GET ALL TABLES METADATA ROUTE`, {
|
|
||||||
user: user.user_id,
|
|
||||||
customer: user.customer_name,
|
|
||||||
});
|
|
||||||
const { user_id, customer_name, customer_id } = user;
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
user_id,
|
|
||||||
customer_id,
|
|
||||||
customer_name,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!query) {
|
|
||||||
const res = await this.catalogService.getAllTableMetadata(body);
|
|
||||||
return res;
|
|
||||||
} else {
|
|
||||||
const res = await this.catalogService.getOneTableMetadata(
|
|
||||||
body,
|
|
||||||
query,
|
|
||||||
metadata,
|
|
||||||
);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete('table-metadata/:id')
|
|
||||||
async deleteOneTableMetadata(@Param() params, @Body() body) {
|
|
||||||
const { id } = params;
|
|
||||||
this.logger.info(`/catalog - ON DELETE ONE TABLE METADATA ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.deleteOneTableMetadata(id, body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('column-metadata')
|
|
||||||
async getOneColumnMetadata(@Body() body, @Query() params) {
|
|
||||||
this.logger.info(`/catalog - ON GET ONE COLUMN METADATA ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getOneColumnMetadata(body, params);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete('column-metadata/:id')
|
|
||||||
async deleteOneColumnMetadata(@Param() params, @Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON DELETE ONE COLUMN METADATA ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
const { id } = params;
|
|
||||||
|
|
||||||
const res = await this.catalogService.deleteOneColumnMetadata(id, body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-preview')
|
|
||||||
async getOneDataPreview(@Body() body, @Query() params) {
|
|
||||||
this.logger.info(`/catalog - ON GET ONE DATAPREVIEW ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getOneDataPreview(body, params);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-status')
|
|
||||||
async getDataStatus(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA STATUS ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getDataStatus(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-status')
|
|
||||||
async createDataStatus(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON CREATE DATA STATUS ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.createDataStatus(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-description')
|
|
||||||
async getDataDescription(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA DESCRIPTION ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getDataDescription(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('data-description')
|
|
||||||
async createDataDescription(@Body() body, @User() user: RequestUser) {
|
|
||||||
this.logger.info(`/catalog - ON CREATE DATA DESCRIPTION ROUTE`, {
|
|
||||||
user: user.user_id,
|
|
||||||
customer: user.customer_name,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { user_id, customer_name, customer_id } = user;
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
user_id,
|
|
||||||
customer_id,
|
|
||||||
customer_name,
|
|
||||||
});
|
|
||||||
return await this.catalogService.createDataDescription(body, metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-docs')
|
|
||||||
async getDataDocs(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA DOCS ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getDataDocs(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('data-docs')
|
|
||||||
async createDataDocs(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON CREATE DATA DOCS ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.createDataDocs(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-rating')
|
|
||||||
async getDataRating(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA RATING ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getDataRating(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('data-rating')
|
|
||||||
async createDataRating(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA RATING ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.createDataRating(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('summary-rating/:id')
|
|
||||||
async getSummaryRating() {
|
|
||||||
this.logger.info(`/catalog - ON GET SUMMARY RATING ROUTE`);
|
|
||||||
//const { id } = params;
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
//const res = await this.catalogService.getSummaryRating(id, body);
|
|
||||||
|
|
||||||
return {
|
|
||||||
avg_rating: 0,
|
|
||||||
rating_count: 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-comment')
|
|
||||||
async getDataComment(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA COMMENT ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getDataComment(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('data-comment')
|
|
||||||
async createDataComment(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA COMMENT ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.createDataComment(body);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('data-review')
|
|
||||||
async getDataReview(@Body() body, @Query() params) {
|
|
||||||
this.logger.info(`/catalog - ON GET DATA REVIEW ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.getDataReview(body, params);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('tags')
|
|
||||||
async createTags(@Body() body, @User() user: RequestUser) {
|
|
||||||
this.logger.info(`/catalog - ON CREATE TAG ROUTE`, {
|
|
||||||
user: user.user_id,
|
|
||||||
customer: user.customer_name,
|
|
||||||
});
|
|
||||||
const { user_id, customer_name, customer_id } = user;
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
user_id,
|
|
||||||
customer_id,
|
|
||||||
customer_name,
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await this.catalogService.createTags(body, metadata);
|
|
||||||
|
|
||||||
return res.data_assets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('tags')
|
@Get('tags')
|
||||||
@@ -451,89 +121,379 @@ export class CatalogController {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('tags/:id')
|
@Get('data-asset/:id')
|
||||||
async deleteTags(@Param() params, @Body() body) {
|
async getDataAsset(
|
||||||
this.logger.info(`/catalog - ON DELETE TAG ROUTE`, {
|
@User() user: RequestUser,
|
||||||
user: body.info.user_id,
|
@Headers() headers,
|
||||||
customer: body.info.customer,
|
@Param('id') id,
|
||||||
|
) {
|
||||||
|
const { username, user_id, customer_id, customer_name, permissions } = user;
|
||||||
|
const [data_asset_type, data_asset_id] = id.split('-');
|
||||||
|
|
||||||
|
this.logger.info(`/catalog - ON GET ONE DASHBOARD METABASE ROUTE`, {
|
||||||
|
username,
|
||||||
|
customer_name,
|
||||||
});
|
});
|
||||||
const { id } = params;
|
|
||||||
body.data_asset_id = id;
|
const is_data_manager = permissions.includes(
|
||||||
const { user_id, customer, customer_id } = body.info;
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
||||||
|
);
|
||||||
|
let has_permission = false;
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
|
username,
|
||||||
|
user_id: undefined,
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const user_roles = await this.catalogService.getUserRolesIds(user_id);
|
||||||
|
|
||||||
|
const { data_asset } = await this.catalogService.getOneDataAsset({
|
||||||
|
customer_id,
|
||||||
|
data_asset_id,
|
||||||
|
data_asset_type,
|
||||||
|
metadata,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data_asset?.owner === username) has_permission = true;
|
||||||
|
|
||||||
|
for (const role of user_roles) {
|
||||||
|
if (data_asset.p_roles.includes(role)) has_permission = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data_asset.p_users.includes(user_id)) has_permission = true;
|
||||||
|
|
||||||
|
if (is_data_manager || has_permission) {
|
||||||
|
delete data_asset.p_roles;
|
||||||
|
delete data_asset.p_users;
|
||||||
|
return { data_asset };
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpException(
|
||||||
|
'You do not have permission to access this data asset.',
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('data-asset/rls/:id')
|
||||||
|
async getDataAssetRls(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Headers() headers,
|
||||||
|
@Param('id') id,
|
||||||
|
) {
|
||||||
|
const { username, user_id, customer_id, customer_name, permissions } = user;
|
||||||
|
const [data_asset_type, data_asset_id] = id.split('-');
|
||||||
|
|
||||||
|
this.logger.info(`/catalog - ON GET ONE DASHBOARD METABASE ROUTE`, {
|
||||||
|
username,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const is_data_manager = permissions.includes(
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
||||||
|
);
|
||||||
|
let has_permission = false;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
username,
|
||||||
user_id,
|
user_id,
|
||||||
customer_id,
|
customer_id,
|
||||||
customer_name: customer,
|
customer_name,
|
||||||
});
|
|
||||||
const res = await this.catalogService.deleteTags(body, metadata);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('table-tags')
|
|
||||||
async createTableTags(@Body() body) {
|
|
||||||
this.logger.info(`/catalog - ON CREATE TABLE TAG ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.createTableTags(body);
|
const user_roles = await this.catalogService.getUserRolesIds(user_id);
|
||||||
|
|
||||||
return res;
|
const { data_asset } = await this.catalogService.getOneDataAsset({
|
||||||
}
|
|
||||||
|
|
||||||
@Get('table-tags/:data_asset_id')
|
|
||||||
async getAllTableTags(@Body() body, @Param() params) {
|
|
||||||
this.logger.info(`/catalog - ON GET ALL TABLE TAGS ROUTE`, {
|
|
||||||
user: body.info.user_id,
|
|
||||||
customer: body.info.customer,
|
|
||||||
});
|
|
||||||
const { user_id, customer, customer_id } = body.info;
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
user_id,
|
|
||||||
customer_id,
|
customer_id,
|
||||||
customer_name: customer,
|
data_asset_id,
|
||||||
|
data_asset_type,
|
||||||
|
metadata,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data_asset?.owner === username) has_permission = true;
|
||||||
|
|
||||||
|
for (const role of user_roles) {
|
||||||
|
if (data_asset.p_roles.includes(role)) has_permission = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data_asset.p_users.includes(user_id)) has_permission = true;
|
||||||
|
|
||||||
|
if (is_data_manager || has_permission) {
|
||||||
|
delete data_asset.p_roles;
|
||||||
|
delete data_asset.p_users;
|
||||||
|
return { data_asset };
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpException(
|
||||||
|
'You do not have permission to access this data asset.',
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('data-asset/:id/columns-metadata')
|
||||||
|
async getDataAssetColumnsMetadata(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Headers('Dadosfera-Lang') language,
|
||||||
|
@Param('id') id,
|
||||||
|
): Promise<IColumnsMetadataResponse> {
|
||||||
|
const { customer_name, customer_id, user_id, username } = user;
|
||||||
|
const data_asset_type = id.split('-')[0];
|
||||||
|
|
||||||
|
const supported_data_assets = ['dataset'];
|
||||||
|
|
||||||
|
if (!supported_data_assets.includes(data_asset_type)) {
|
||||||
|
throw new UnsupportedMediaTypeException(
|
||||||
|
`${data_asset_type} does not have a preview function for the time being.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(`/catalog - ON GET DATA DOCS ROUTE`, {
|
||||||
|
user_id,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_name,
|
||||||
|
customer_id,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
language,
|
||||||
|
});
|
||||||
|
|
||||||
|
const columns_metadata =
|
||||||
|
await this.catalogService.getDatasetColumnsMetadata(id, metadata);
|
||||||
|
|
||||||
|
return { columns_metadata };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('data-asset/:id/preview')
|
||||||
|
async getDataAssetPreview(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Headers('Dadosfera-lang') language,
|
||||||
|
@Param('id') id,
|
||||||
|
): Promise<IPreviewResponse> {
|
||||||
|
const { customer_name, customer_id, user_id, username } = user;
|
||||||
|
const data_asset_type = id.split('-')[0];
|
||||||
|
|
||||||
|
const supported_data_assets = ['dataset'];
|
||||||
|
|
||||||
|
if (!supported_data_assets.includes(data_asset_type)) {
|
||||||
|
throw new UnsupportedMediaTypeException(
|
||||||
|
`${data_asset_type} does not have a preview function for the time being.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(`/catalog - ON GET DATA DOCS ROUTE`, {
|
||||||
|
user_id,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_name,
|
||||||
|
customer_id,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
language,
|
||||||
|
});
|
||||||
|
|
||||||
|
const preview = await this.catalogService.getDatasetPreview(id, metadata);
|
||||||
|
|
||||||
|
return { preview };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('data-asset/:id/docs')
|
||||||
|
async getDataAssetDocs(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Headers('Dadosfera-Lang') language,
|
||||||
|
@Param('id') id,
|
||||||
|
): Promise<IDocsResponse> {
|
||||||
|
const { customer_name, customer_id, user_id, username } = user;
|
||||||
|
const data_asset_type = id.split('-')[0];
|
||||||
|
|
||||||
|
const supported_data_assets = ['dataset'];
|
||||||
|
|
||||||
|
if (!supported_data_assets.includes(data_asset_type)) {
|
||||||
|
throw new UnsupportedMediaTypeException(
|
||||||
|
`${data_asset_type} does not have a documentation function for the time being.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(`/catalog - ON GET DATA DOCS ROUTE`, {
|
||||||
|
user_id,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_name,
|
||||||
|
customer_id,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
language,
|
||||||
|
});
|
||||||
|
|
||||||
|
const docs = await this.catalogService.getDataDocs(id, metadata);
|
||||||
|
|
||||||
|
return { docs };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('data-asset/:id')
|
||||||
|
async updateDataAsset(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Headers('Dadosfera-Lang') language,
|
||||||
|
@Param('id') id,
|
||||||
|
@Body() body: IUpdateDataRequest,
|
||||||
|
): Promise<IOneDataAsset> {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
language,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.catalogService.updateOneDataAsset({
|
||||||
|
body,
|
||||||
|
data_asset_id: id,
|
||||||
|
customer_id,
|
||||||
|
metadata,
|
||||||
|
});
|
||||||
|
|
||||||
|
delete result.data_asset.p_roles;
|
||||||
|
delete result.data_asset.p_users;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('data-asset/:id/docs')
|
||||||
|
async manageDataAssetDocs(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Headers() headers,
|
||||||
|
@Param('id') data_asset_id,
|
||||||
|
@Body('docs') docs: string,
|
||||||
|
) {
|
||||||
|
const { user_id, customer_name } = user;
|
||||||
|
const [data_asset_type, id] = data_asset_id.split('-');
|
||||||
|
|
||||||
|
this.logger.info(`/catalog - ON GET DATA DOCS ROUTE`, {
|
||||||
|
user_id,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await this.catalogService.createDataDocs({
|
||||||
|
table_id: id,
|
||||||
|
docs,
|
||||||
|
info: {
|
||||||
|
customer: customer_name,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const res = await this.catalogService.findAllTableTags(params, metadata);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('table-tags/:id')
|
@Put('data-asset/:id/manage-permissions')
|
||||||
async deleteTableTags(@Param() params, @Body() body) {
|
async manageDataAssetPermissions(
|
||||||
this.logger.info(`/catalog - ON CREATE TABLE TAGS ROUTE`, {
|
@Param('id') id: string,
|
||||||
user: body.info.user_id,
|
@User() user: RequestUser,
|
||||||
customer: body.info.customer,
|
@Body() body,
|
||||||
|
) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
});
|
});
|
||||||
const { id } = params;
|
const response = await this.catalogService.managePermissions(
|
||||||
|
{ ...body, id },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
const res = await this.catalogService.deleteTableTags(id, body);
|
return { data_asset: JSON.parse(response.data_asset) };
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('table-rules')
|
@Put('data-asset/:id/revoke-permissions')
|
||||||
async getTableRules(@Body() body) {
|
async revokeDataAssetPermissions(
|
||||||
this.logger.info(`/catalog - ON GET TABLE RULES ROUTE`, {
|
@Param('id') id: string,
|
||||||
user: body.info.user_id,
|
@User() user: RequestUser,
|
||||||
customer: body.info.customer,
|
@Body() body,
|
||||||
|
) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
});
|
});
|
||||||
|
const response = await this.catalogService.revokePermissions(
|
||||||
|
{ ...body, id },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
const res = await this.catalogService.getTableRules(body);
|
return { message: response.message };
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('table-rules/:id')
|
@Post('data-asset/:id/comment')
|
||||||
async deleteTableRules(@Param() params, @Body() body) {
|
async commentOnDataAsset(
|
||||||
this.logger.info(`/catalog - ON DELETE TABLE RULES ROUTE`, {
|
@Param('id') id: string,
|
||||||
user: body.info.user_id,
|
@User() user: RequestUser,
|
||||||
customer: body.info.customer,
|
@Body() body: IMakeAComment,
|
||||||
|
) {
|
||||||
|
const { message } = body;
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
});
|
});
|
||||||
const { id } = params;
|
const response = await this.catalogService.commentOnDataAsset(
|
||||||
|
{ data_asset_id: id, username, message },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
const res = await this.catalogService.deleteTableRules(id, body);
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
@Delete('data-asset/:id')
|
||||||
|
async deleteDataAsset(
|
||||||
|
@Param('id') data_asset_id: string,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [type, id] = data_asset_id.split('-');
|
||||||
|
const response = await this.catalogService.deleteDataAsset(
|
||||||
|
{ id, type },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete('data-asset/:id/comment')
|
||||||
|
async deleteComment(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body() body: IDeleteComment,
|
||||||
|
) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
const response = await this.catalogService.deleteComment(
|
||||||
|
{ data_asset_id: id, comment: body.comment },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { CatalogClientConfiguration } from './catalog-client';
|
|||||||
import { ClientsModule } from '@nestjs/microservices';
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
import { PipelinesModule as OldPipelineModule } from 'src/modules/pipelines/pipelines.module';
|
import { PipelinesModule as OldPipelineModule } from 'src/modules/pipelines/pipelines.module';
|
||||||
import { UsersModule } from '../users/users.module';
|
import { UsersModule } from '../users/users.module';
|
||||||
|
import { RolesModule } from '../roles/roles.module';
|
||||||
|
|
||||||
const client = new CatalogClientConfiguration();
|
const client = new CatalogClientConfiguration();
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ const client = new CatalogClientConfiguration();
|
|||||||
ClientsModule.register([client.providerOptions]),
|
ClientsModule.register([client.providerOptions]),
|
||||||
OldPipelineModule,
|
OldPipelineModule,
|
||||||
UsersModule,
|
UsersModule,
|
||||||
|
RolesModule,
|
||||||
],
|
],
|
||||||
controllers: [CatalogController],
|
controllers: [CatalogController],
|
||||||
providers: [CatalogService, DadosferaLogger],
|
providers: [CatalogService, DadosferaLogger],
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
||||||
import { ReadService } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
import {
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
WriteService,
|
||||||
import { Messages } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
ReadService,
|
||||||
import { WriteService } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
ProtoServices,
|
||||||
|
Messages,
|
||||||
|
} from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
||||||
import {
|
import {
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
@@ -14,6 +16,8 @@ import axios from 'axios';
|
|||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
import { CatalogClientConfiguration } from './catalog-client';
|
import { CatalogClientConfiguration } from './catalog-client';
|
||||||
import { UsersService } from '../users/users.service';
|
import { UsersService } from '../users/users.service';
|
||||||
|
import { RolesService } from '../roles/roles.service';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
class CatalogService implements OnModuleInit {
|
class CatalogService implements OnModuleInit {
|
||||||
catalogReadService: ReadService.CatalogReadServices;
|
catalogReadService: ReadService.CatalogReadServices;
|
||||||
@@ -25,6 +29,7 @@ class CatalogService implements OnModuleInit {
|
|||||||
@Inject(CatalogClientConfiguration.name)
|
@Inject(CatalogClientConfiguration.name)
|
||||||
private readonly grpcClient: ClientGrpc,
|
private readonly grpcClient: ClientGrpc,
|
||||||
private readonly userService: UsersService,
|
private readonly userService: UsersService,
|
||||||
|
private readonly roleService: RolesService,
|
||||||
) {
|
) {
|
||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
}
|
}
|
||||||
@@ -79,34 +84,43 @@ class CatalogService implements OnModuleInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async catalogAll(body) {
|
async commentOnDataAsset(data: Messages.MakeACommentRequest, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
this.logger.info('CatalogService - Manage Data assets permissions');
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/all/`);
|
|
||||||
|
|
||||||
return data;
|
return lastValueFrom(
|
||||||
|
this.catalogWriteService.MakeAComment(data, metadata),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 404,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async dataAppsAll(body) {
|
async deleteComment(data: Messages.UpdateACommentRequest, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
this.logger.info('CatalogService - Manage Data assets permissions');
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/data_apps/`);
|
|
||||||
return data;
|
return lastValueFrom(
|
||||||
|
this.catalogWriteService.UpdateAComment(data, metadata),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 404,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async dataAppsOne(id, body) {
|
async deleteDataAsset(data: Messages.DeleteDataAssetRequest, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
this.logger.info('CatalogService - Manage Data assets permissions');
|
||||||
const { data } = await axios.get(
|
|
||||||
`${nimbusUrl}/api/catalog/data_apps/${id}/`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return data;
|
return lastValueFrom(
|
||||||
}
|
this.catalogWriteService.DeleteDataAsset(data, metadata),
|
||||||
|
).catch((err) => {
|
||||||
async getAllDashboardMetabase(body) {
|
throw new HttpException(
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
err.details,
|
||||||
const { data } = await axios.get(
|
err.code === 6 ? HttpStatus.CONFLICT : 404,
|
||||||
`${nimbusUrl}/api/catalog/dashboard-metabase/`,
|
);
|
||||||
);
|
});
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserRolesIds(userId: string) {
|
async getUserRolesIds(userId: string) {
|
||||||
@@ -117,66 +131,111 @@ class CatalogService implements OnModuleInit {
|
|||||||
return roles_ids;
|
return roles_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllOpenSearchDataAssets(
|
async getUsernamesAndRolesByCustomerId(customerId: string) {
|
||||||
data: Messages.GetAllDataAssetsRequest,
|
const resultUsers = await this.userService.findAllUsersByCustomerId(
|
||||||
metadata,
|
customerId,
|
||||||
) {
|
);
|
||||||
this.logger.info('CatalogService - getAllOpenSearchDashboard');
|
const resultRoles = await this.roleService.roleSearch(
|
||||||
|
{},
|
||||||
const response = await lastValueFrom(
|
{ customer_id: customerId },
|
||||||
this.catalogReadService.GetAllDataAssets(data, metadata),
|
|
||||||
)
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return JSON.parse(res.data_assets);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const asset of response.tables) {
|
|
||||||
const condition =
|
|
||||||
asset.owner && !asset.owner.includes('@') ? true : false;
|
|
||||||
const result = condition
|
|
||||||
? await this.userService.findOneById(asset.owner).catch(() => null)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const owner = result !== null ? result.user.username : null;
|
|
||||||
|
|
||||||
Object.assign(asset, { ...asset, owner });
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const asset of response.dashboards) {
|
|
||||||
const condition =
|
|
||||||
asset.owner && !asset.owner.includes('@') ? true : false;
|
|
||||||
const result = condition
|
|
||||||
? await this.userService.findOneById(asset.owner).catch(() => null)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const owner = result !== null ? result.user.username : null;
|
|
||||||
|
|
||||||
Object.assign(asset, { ...asset, owner });
|
|
||||||
}
|
|
||||||
|
|
||||||
return { data_assets: response };
|
|
||||||
}
|
|
||||||
|
|
||||||
async getOneDashboardMetabase(id, body, metadata) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(
|
|
||||||
`${nimbusUrl}/api/catalog/dashboard-metabase/${id}`,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const customer_users = resultUsers.users.map((user) => {
|
||||||
|
return {
|
||||||
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const customer_roles = resultRoles.roles.map((role) => {
|
||||||
|
return {
|
||||||
|
id: role.id,
|
||||||
|
name: role.name,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return [customer_users, customer_roles];
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllOpenSearchDataAssets(query, metadata, customer_id) {
|
||||||
|
this.logger.info('CatalogService - getAllOpenSearchDashboard');
|
||||||
|
|
||||||
|
const { search, page, size, sort_by, order, ...filters } = query;
|
||||||
|
|
||||||
|
const { data_assets, total } = await lastValueFrom(
|
||||||
|
this.catalogReadService.GetAllDataAssets(
|
||||||
|
{
|
||||||
|
search,
|
||||||
|
page,
|
||||||
|
size,
|
||||||
|
sort_by,
|
||||||
|
order,
|
||||||
|
filters: JSON.stringify(filters),
|
||||||
|
},
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 404,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = JSON.parse(data_assets);
|
||||||
|
|
||||||
|
const [customer_users, customer_roles] =
|
||||||
|
await this.getUsernamesAndRolesByCustomerId(customer_id);
|
||||||
|
|
||||||
|
for (const asset of result.data_assets) {
|
||||||
|
const condition =
|
||||||
|
asset.owner && !asset.owner.includes('@') ? true : false;
|
||||||
|
const result = condition
|
||||||
|
? await this.userService.findOneById(asset.owner).catch(() => null)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
|
const roles = [];
|
||||||
|
const users = [];
|
||||||
|
|
||||||
|
for (const role of customer_roles) {
|
||||||
|
for (const role_id of asset.roles) {
|
||||||
|
if (role.id === role_id) roles.push(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const user of customer_users) {
|
||||||
|
for (const user_id of asset.users) {
|
||||||
|
if (user.id === user_id) users.push(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(asset, {
|
||||||
|
...asset,
|
||||||
|
owner,
|
||||||
|
roles,
|
||||||
|
users,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { data_assets: result.data_assets, total };
|
||||||
|
}
|
||||||
|
|
||||||
|
async getOneDataAsset({
|
||||||
|
data_asset_id,
|
||||||
|
data_asset_type,
|
||||||
|
customer_id,
|
||||||
|
metadata,
|
||||||
|
}) {
|
||||||
const { data_asset } = await lastValueFrom(
|
const { data_asset } = await lastValueFrom(
|
||||||
this.catalogReadService.GetOneDataAsset(
|
this.catalogReadService.GetOneDataAsset(
|
||||||
{ id, type: 'dashboard' },
|
{ id: data_asset_id, type: data_asset_type },
|
||||||
metadata,
|
metadata,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
const opensearchTable = JSON.parse(data_asset);
|
const opensearchTable = JSON.parse(data_asset);
|
||||||
|
|
||||||
const result = opensearchTable.user_id
|
const result = opensearchTable.owner
|
||||||
? await this.userService
|
? await this.userService
|
||||||
.findOneById(opensearchTable.owner)
|
.findOneById(opensearchTable.owner)
|
||||||
.catch(() => null)
|
.catch(() => null)
|
||||||
@@ -184,146 +243,120 @@ class CatalogService implements OnModuleInit {
|
|||||||
|
|
||||||
const owner = result !== null ? result.user.username : null;
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
return {
|
const [customer_users, customer_roles] =
|
||||||
...data,
|
await this.getUsernamesAndRolesByCustomerId(customer_id);
|
||||||
tags: opensearchTable.tags,
|
|
||||||
description: opensearchTable.description || null,
|
|
||||||
owner,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async getAllTableMetadata(body) {
|
const users = [];
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const roles = [];
|
||||||
const { data } = await axios.get(
|
|
||||||
`${nimbusUrl}/api/catalog/table-metadata/`,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getOneTableMetadata(body, params, metadata) {
|
for (const role of customer_roles) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
for (const role_id of opensearchTable.roles) {
|
||||||
const { data } = await axios.get(
|
if (role.id === role_id) roles.push(role);
|
||||||
`${nimbusUrl}/api/catalog/table-metadata/`,
|
}
|
||||||
{ params: params },
|
|
||||||
);
|
|
||||||
if (data?.length === 1) {
|
|
||||||
const { data_asset } = await lastValueFrom(
|
|
||||||
this.catalogReadService.GetOneDataAsset(
|
|
||||||
{ id: data[0].id, type: 'dataset' },
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const opensearchTable = JSON.parse(data_asset);
|
|
||||||
const result = opensearchTable.user_id
|
|
||||||
? await this.userService
|
|
||||||
.findOneById(opensearchTable.owner)
|
|
||||||
.catch(() => null)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const owner = result !== null ? result.user.username : null;
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
...data[0],
|
|
||||||
tags: opensearchTable.tags,
|
|
||||||
table_description: opensearchTable.description,
|
|
||||||
owner,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteOneTableMetadata(id, body) {
|
for (const user of customer_users) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
for (const user_id of opensearchTable.users) {
|
||||||
const { data } = await axios.delete(
|
if (user.id === user_id) users.push(user);
|
||||||
`${nimbusUrl}/api/catalog/table-metadata/${id}`,
|
}
|
||||||
);
|
}
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getOneColumnMetadata(body, params) {
|
Object.assign(opensearchTable, {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
p_roles: opensearchTable.roles,
|
||||||
const { data } = await axios.get(
|
p_users: opensearchTable.users,
|
||||||
`${nimbusUrl}/api/catalog/column-metadata/`,
|
roles,
|
||||||
{ params: params },
|
users,
|
||||||
);
|
owner,
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteOneColumnMetadata(id, body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.delete(
|
|
||||||
`${nimbusUrl}/api/catalog/column-metadata/${id}/`,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getOneDataPreview(body, params) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/data-preview/`, {
|
|
||||||
params: params,
|
|
||||||
});
|
});
|
||||||
return data;
|
|
||||||
|
return { data_asset: opensearchTable };
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDataStatus(body) {
|
async updateOneDataAsset({ data_asset_id, customer_id, body, metadata }) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const { data_asset } = await lastValueFrom(
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/data-status/`);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createDataStatus(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.post(
|
|
||||||
`${nimbusUrl}/api/catalog/data-status/`,
|
|
||||||
body,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getDataDescription(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(
|
|
||||||
`${nimbusUrl}/api/catalog/data-description/`,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createDataDescription(body, metadata) {
|
|
||||||
const response = await lastValueFrom(
|
|
||||||
this.catalogWriteService.UpdateDataAsset(
|
this.catalogWriteService.UpdateDataAsset(
|
||||||
{
|
{ id: data_asset_id, ...body },
|
||||||
id: `dataset-${body.table_id}`,
|
|
||||||
description: body.description,
|
|
||||||
tags: undefined,
|
|
||||||
},
|
|
||||||
metadata,
|
metadata,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// {
|
|
||||||
// description: 'descrição nova';
|
const opensearchTable = JSON.parse(data_asset);
|
||||||
// id: 5;
|
|
||||||
// table_id: 4;
|
const result = opensearchTable.owner
|
||||||
// }
|
? await this.userService
|
||||||
// const nimbusUrl = this._getNimbusUrl(body);
|
.findOneById(opensearchTable.owner)
|
||||||
// const { data } = await axios.post(
|
.catch(() => null)
|
||||||
// `${nimbusUrl}/api/catalog/data-description/`,
|
: null;
|
||||||
// body,
|
|
||||||
// );
|
const owner = result !== null ? result.user.username : null;
|
||||||
// {"id":5,"description":"descrição nova","updated_at":"2022-09-28T14:35:15.618750Z","table_id":4}
|
|
||||||
return {
|
const [customer_users, customer_roles] =
|
||||||
id: 0,
|
await this.getUsernamesAndRolesByCustomerId(customer_id);
|
||||||
description: body.description,
|
|
||||||
updated_at: new Date().toISOString(),
|
const users = [];
|
||||||
table_id: body.table_id,
|
const roles = [];
|
||||||
};
|
|
||||||
|
for (const role of customer_roles) {
|
||||||
|
for (const role_id of opensearchTable.roles) {
|
||||||
|
if (role.id === role_id) roles.push(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const user of customer_users) {
|
||||||
|
for (const user_id of opensearchTable.users) {
|
||||||
|
if (user.id === user_id) users.push(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(opensearchTable, {
|
||||||
|
p_roles: opensearchTable.roles,
|
||||||
|
p_users: opensearchTable.users,
|
||||||
|
roles,
|
||||||
|
users,
|
||||||
|
owner,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { data_asset: opensearchTable };
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDataDocs(body) {
|
async getDataDocs(data_asset_id: string, metadata: Metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const [data_asset_type, id] = data_asset_id.split('-');
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/data-docs/`);
|
|
||||||
return data;
|
const { documentation } = await lastValueFrom(
|
||||||
|
this.catalogReadService.GetDatasetDoc(
|
||||||
|
{ id, type: data_asset_type },
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
console.log(documentation);
|
||||||
|
const docs = JSON.parse(documentation);
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDatasetPreview(data_asset_id: string, metadata: Metadata) {
|
||||||
|
const [data_asset_type, id] = data_asset_id.split('-');
|
||||||
|
|
||||||
|
const { preview } = await lastValueFrom(
|
||||||
|
this.catalogReadService.GetDatasetPreview(
|
||||||
|
{ id, type: data_asset_type },
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const result = JSON.parse(preview);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDatasetColumnsMetadata(data_asset_id: string, metadata: Metadata) {
|
||||||
|
const [data_asset_type, id] = data_asset_id.split('-');
|
||||||
|
|
||||||
|
const { columns_metadata } = await lastValueFrom(
|
||||||
|
this.catalogReadService.GetDatasetColumnsMetadata(
|
||||||
|
{ id, type: data_asset_type },
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const result = JSON.parse(columns_metadata);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createDataDocs(body) {
|
async createDataDocs(body) {
|
||||||
@@ -335,70 +368,6 @@ class CatalogService implements OnModuleInit {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDataRating(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/data-rating/`);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createDataRating(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.post(
|
|
||||||
`${nimbusUrl}/api/catalog/data-rating/`,
|
|
||||||
body,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSummaryRating(id, body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(
|
|
||||||
`${nimbusUrl}/api/catalog/summary-rating/${id}`,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getDataComment(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/data-comment/`);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createDataComment(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.post(
|
|
||||||
`${nimbusUrl}/api/catalog/data-comment/`,
|
|
||||||
body,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getDataReview(body, params) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/data-review/`, {
|
|
||||||
params: params,
|
|
||||||
});
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createTags(data: Messages.TagTableRequest, metadata) {
|
|
||||||
this.logger.info('CatalogService - createTags');
|
|
||||||
|
|
||||||
const response = await lastValueFrom(
|
|
||||||
this.catalogWriteService.TagTable(data, metadata),
|
|
||||||
)
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return { data_assets: response };
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAllTags(data, metadata) {
|
async findAllTags(data, metadata) {
|
||||||
this.logger.info('CatalogService - findAllCustomerTags');
|
this.logger.info('CatalogService - findAllCustomerTags');
|
||||||
|
|
||||||
@@ -416,76 +385,6 @@ class CatalogService implements OnModuleInit {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllTableTags(data, metadata) {
|
|
||||||
this.logger.info('CatalogService - findAllTableTags');
|
|
||||||
|
|
||||||
const response = await lastValueFrom(
|
|
||||||
this.catalogReadService.GetTableTags(data, metadata),
|
|
||||||
)
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteTags(data, metadata) {
|
|
||||||
this.logger.info('CatalogService - deleteTags');
|
|
||||||
|
|
||||||
const response = await lastValueFrom(
|
|
||||||
this.catalogWriteService.UntagTable(data, metadata),
|
|
||||||
)
|
|
||||||
.then((res) => {
|
|
||||||
this.logger.info('Done');
|
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
async createTableTags(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.post(
|
|
||||||
`${nimbusUrl}/api/catalog/table-tags/`,
|
|
||||||
body,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteTableTags(id, body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.delete(
|
|
||||||
`${nimbusUrl}/api/catalog/table-tags/${id}`,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getTableRules(body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.get(
|
|
||||||
`${nimbusUrl}/api/catalog/table-rules/`,
|
|
||||||
body,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteTableRules(id, body) {
|
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
|
||||||
const { data } = await axios.delete(
|
|
||||||
`${nimbusUrl}/api/catalog/table-rules/${id}`,
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { CatalogService };
|
export { CatalogService };
|
||||||
|
|||||||
@@ -0,0 +1,203 @@
|
|||||||
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class IRole {
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IUser {
|
||||||
|
@ApiProperty()
|
||||||
|
username: string;
|
||||||
|
@ApiProperty()
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IComment {
|
||||||
|
@ApiProperty()
|
||||||
|
id: number;
|
||||||
|
@ApiProperty()
|
||||||
|
message: string;
|
||||||
|
@ApiProperty()
|
||||||
|
created_at: string;
|
||||||
|
@ApiProperty()
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IDataAsset {
|
||||||
|
@ApiProperty()
|
||||||
|
id: number;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
database_name?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
table_name?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
num_columns?: number;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
location?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
created_time?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
table_type?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
size_in_bytes?: number;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
num_files?: number;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
data_encrypted?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
num_rows?: number;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
display_name?: string;
|
||||||
|
@ApiProperty()
|
||||||
|
pipeline_id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
user_id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
description: string;
|
||||||
|
@ApiProperty()
|
||||||
|
data_asset_type: string;
|
||||||
|
@ApiProperty()
|
||||||
|
tags: string[];
|
||||||
|
@ApiProperty()
|
||||||
|
owner: string;
|
||||||
|
@ApiProperty({ type: [IRole] })
|
||||||
|
roles: IRole[];
|
||||||
|
@ApiProperty({ type: [IUser] })
|
||||||
|
users: IUser[];
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
dashboard_id?: number;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
name?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
parameters?: string[];
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
embedding_params?: object;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
created_at?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
updated_at?: string;
|
||||||
|
@ApiProperty({ type: [IComment] })
|
||||||
|
comments: IComment[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IOneDataAsset {
|
||||||
|
@ApiProperty()
|
||||||
|
data_asset: IDataAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IMakeAComment {
|
||||||
|
@ApiProperty()
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IDeleteComment {
|
||||||
|
@ApiProperty()
|
||||||
|
comment: IComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ICatalogAllResponse {
|
||||||
|
@ApiProperty({ type: [IDataAsset] })
|
||||||
|
data_assets: IDataAsset[];
|
||||||
|
@ApiProperty()
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IData {
|
||||||
|
@ApiProperty()
|
||||||
|
var: number;
|
||||||
|
@ApiProperty()
|
||||||
|
date: string;
|
||||||
|
@ApiProperty()
|
||||||
|
last: number;
|
||||||
|
@ApiProperty()
|
||||||
|
maximum: number;
|
||||||
|
@ApiProperty()
|
||||||
|
minimum: number;
|
||||||
|
@ApiProperty()
|
||||||
|
day_opening: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IUpdateDataRequest {
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
description: string;
|
||||||
|
@ApiProperty()
|
||||||
|
tags: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IPreview {
|
||||||
|
@ApiProperty()
|
||||||
|
id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
database_name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
table_name: string;
|
||||||
|
@ApiProperty({ type: [IData] })
|
||||||
|
data: IData[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IDocs {
|
||||||
|
@ApiProperty()
|
||||||
|
id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
docs: string;
|
||||||
|
@ApiProperty()
|
||||||
|
updated_at: string;
|
||||||
|
@ApiProperty()
|
||||||
|
table_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IColumnMetadata {
|
||||||
|
@ApiProperty()
|
||||||
|
id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
table_name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
column_name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
data_type: string;
|
||||||
|
@ApiProperty()
|
||||||
|
missing_count: string;
|
||||||
|
@ApiProperty()
|
||||||
|
min: string;
|
||||||
|
@ApiProperty()
|
||||||
|
max: string;
|
||||||
|
@ApiProperty()
|
||||||
|
count: string;
|
||||||
|
@ApiProperty()
|
||||||
|
histogram: string;
|
||||||
|
@ApiProperty()
|
||||||
|
mean: string;
|
||||||
|
@ApiProperty()
|
||||||
|
median: string;
|
||||||
|
@ApiProperty()
|
||||||
|
missing_rate: string;
|
||||||
|
@ApiProperty()
|
||||||
|
stddev: string;
|
||||||
|
@ApiProperty()
|
||||||
|
unique_count: string;
|
||||||
|
@ApiProperty()
|
||||||
|
unique_rate: string;
|
||||||
|
@ApiProperty()
|
||||||
|
analyzer_rules: string[];
|
||||||
|
@ApiProperty()
|
||||||
|
version: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IPreviewResponse {
|
||||||
|
@ApiProperty()
|
||||||
|
preview: IPreview;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IDocsResponse {
|
||||||
|
@ApiProperty()
|
||||||
|
docs: IDocs;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IColumnsMetadataResponse {
|
||||||
|
@ApiProperty({ type: [IColumnMetadata] })
|
||||||
|
columns_metadata: IColumnMetadata[];
|
||||||
|
}
|
||||||
@@ -71,27 +71,174 @@ export class ConnectorClientService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadConnectorsFile(uploadFile) {
|
async uploadConnectorsFile(uploadFile: Express.Multer.File) {
|
||||||
const connectors = JSON.parse(uploadFile.file.buffer.toString('utf8'));
|
const res = await lastValueFrom(
|
||||||
|
this.connectorServiceWrite.RegisterMultipleConnectorsWithoutImage({
|
||||||
const body = connectors.map((connector) => {
|
connectors: uploadFile.buffer,
|
||||||
return JSON.stringify(connector);
|
}),
|
||||||
});
|
|
||||||
|
|
||||||
const request = {
|
|
||||||
connectors: body,
|
|
||||||
};
|
|
||||||
|
|
||||||
return lastValueFrom(
|
|
||||||
this.connectorServiceWrite.RegisterMultipleConnectorsWithoutImage(
|
|
||||||
request,
|
|
||||||
),
|
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
err.details,
|
err.details,
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
const responseParsed = JSON.parse(res.message);
|
||||||
|
const connectorErrors = responseParsed.items
|
||||||
|
.filter((i) => i.update._index === 'connector' && i.update.error)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
reason: i.update.error,
|
||||||
|
status: i.error.status,
|
||||||
|
}));
|
||||||
|
const connectionControlsErrors = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) => i.update._index === 'connection_controls' && i.update.error,
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
reason: i.update.error,
|
||||||
|
status: i.error.status,
|
||||||
|
}));
|
||||||
|
const connectionStepsErrors = responseParsed.items
|
||||||
|
.filter((i) => i.update._index === 'connection_steps' && i.update.error)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
reason: i.update.error,
|
||||||
|
status: i.error.status,
|
||||||
|
}));
|
||||||
|
const configControlsErrors = responseParsed.items
|
||||||
|
.filter((i) => i.update._index === 'config_controls' && i.update.error)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
reason: i.update.error,
|
||||||
|
status: i.error.status,
|
||||||
|
}));
|
||||||
|
const connectorCreated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) => i.update._index === 'connector' && i.update.result === 'created',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectionControlsCreated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'connection_controls' &&
|
||||||
|
i.update.result === 'created',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectionStepsCreated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'connection_steps' &&
|
||||||
|
i.update.result === 'created',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const configControlsCreated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'config_controls' &&
|
||||||
|
i.update.result === 'created',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectorUpdated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) => i.update._index === 'connector' && i.update.result === 'updated',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectionControlsUpdated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'connection_controls' &&
|
||||||
|
i.update.result === 'updated',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectionStepsUpdated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'connection_steps' &&
|
||||||
|
i.update.result === 'updated',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const configControlsUpdated = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'config_controls' &&
|
||||||
|
i.update.result === 'updated',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectorNoop = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) => i.update._index === 'connector' && i.update.result === 'noop',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectionControlsNoop = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'connection_controls' &&
|
||||||
|
i.update.result === 'noop',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const connectionStepsNoop = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'connection_steps' && i.update.result === 'noop',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
const configControlsNoop = responseParsed.items
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.update._index === 'config_controls' && i.update.result === 'noop',
|
||||||
|
)
|
||||||
|
.map((i) => ({
|
||||||
|
id: i.update._id,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
errors: {
|
||||||
|
connectors: connectorErrors,
|
||||||
|
connection_controls: connectionControlsErrors,
|
||||||
|
connection_steps: connectionStepsErrors,
|
||||||
|
config_controls: configControlsErrors,
|
||||||
|
},
|
||||||
|
created: {
|
||||||
|
connectors: connectorCreated,
|
||||||
|
connection_controls: connectionControlsCreated,
|
||||||
|
connection_steps: connectionStepsCreated,
|
||||||
|
config_controls: configControlsCreated,
|
||||||
|
},
|
||||||
|
updated: {
|
||||||
|
connectors: connectorUpdated,
|
||||||
|
connection_controls: connectionControlsUpdated,
|
||||||
|
connection_steps: connectionStepsUpdated,
|
||||||
|
config_controls: configControlsUpdated,
|
||||||
|
},
|
||||||
|
noop: {
|
||||||
|
connectors: connectorNoop,
|
||||||
|
connection_controls: connectionControlsNoop,
|
||||||
|
connection_steps: connectionStepsNoop,
|
||||||
|
config_controls: configControlsNoop,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllConnectors(body) {
|
async getAllConnectors(body) {
|
||||||
@@ -116,13 +263,13 @@ export class ConnectorClientService implements OnModuleInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getConnectorDetails(plugin: string, language: string) {
|
async getConnectorDetails(connectorId: string, language: string) {
|
||||||
const meta = new Metadata();
|
const meta = new Metadata();
|
||||||
meta.add('Language', language);
|
meta.add('Language', language);
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
this.connectorServiceRead.GetConnectorDetails(
|
this.connectorServiceRead.GetConnectorDetails(
|
||||||
{
|
{
|
||||||
plugin,
|
plugin: connectorId,
|
||||||
},
|
},
|
||||||
meta,
|
meta,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
|||||||
import { ConnectorClientService } from './client.service';
|
import { ConnectorClientService } from './client.service';
|
||||||
import { AddTagDto } from './dtos/add-tag';
|
import { AddTagDto } from './dtos/add-tag';
|
||||||
import { CreateConnectorDto } from './dtos/create-connector';
|
import { CreateConnectorDto } from './dtos/create-connector';
|
||||||
import { UploadConnectorsFileDto } from './dtos/create-multiple-connector';
|
|
||||||
import { DeleteConnectorDto } from './dtos/delete-connector';
|
import { DeleteConnectorDto } from './dtos/delete-connector';
|
||||||
import { GetAllDto } from './dtos/get-all';
|
import { GetAllDto } from './dtos/get-all';
|
||||||
import { RemoveTagDto } from './dtos/remove-tag';
|
import { RemoveTagDto } from './dtos/remove-tag';
|
||||||
@@ -85,14 +84,10 @@ export class ConnectorController {
|
|||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.CREATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
async uploadConnectorsFile(@UploadedFile() file: UploadConnectorsFileDto) {
|
async uploadConnectorsFile(@UploadedFile() file: Express.Multer.File) {
|
||||||
this.logger.info(`/upload`, 'Upload Connector Route');
|
this.logger.info(`/upload`, 'Upload Connector Route');
|
||||||
|
|
||||||
const response = await this.connectorClientService.uploadConnectorsFile({
|
return await this.connectorClientService.uploadConnectorsFile(file);
|
||||||
file,
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
|||||||
@@ -19,17 +19,18 @@ import { RequestUser, User } from 'src/authentication/user.decorator';
|
|||||||
import {
|
import {
|
||||||
CreateNetworkConfigReq,
|
CreateNetworkConfigReq,
|
||||||
CreateNetworkConfigRes,
|
CreateNetworkConfigRes,
|
||||||
DeleteNetworkConfigRes,
|
|
||||||
FindAllNetworkConfigsRes,
|
FindAllNetworkConfigsRes,
|
||||||
UpdateNetworkConfigReq,
|
|
||||||
UpdateNetworkConfigRes,
|
|
||||||
} from './dto/network-config';
|
} from './dto/network-config';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/authentication/authentication.decorator';
|
||||||
|
|
||||||
const networkConfigPermissions = PERMISSIONS_GROUPS.NETWORK_CONFIG.permissions;
|
const networkConfigPermissions = PERMISSIONS_GROUPS.NETWORK_CONFIG.permissions;
|
||||||
@ApiTags('Network Config')
|
@ApiTags('Network Config')
|
||||||
|
@Authenticated()
|
||||||
@Controller('network-config')
|
@Controller('network-config')
|
||||||
export class NetworkConfigController {
|
export class NetworkConfigController {
|
||||||
logger: any;
|
logger: any;
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ export class OauthController {
|
|||||||
switch (process.env.ENV) {
|
switch (process.env.ENV) {
|
||||||
case 'dev':
|
case 'dev':
|
||||||
case 'stg':
|
case 'stg':
|
||||||
this.redirectUrl = `https://app.${process.env.ENV}.dadosfera.ai/coletix/auth-callback`;
|
this.redirectUrl = `https://app.${process.env.ENV}.dadosfera.ai/collect/auth-callback`;
|
||||||
break;
|
break;
|
||||||
case 'prd':
|
case 'prd':
|
||||||
this.redirectUrl = `https://app.dadosfera.ai/coletix/auth-callback`;
|
this.redirectUrl = `https://app.dadosfera.ai/collect/auth-callback`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.redirectUrl = `http://localhost:4200/coletix/auth-callback`;
|
this.redirectUrl = `http://localhost:4200/collect/auth-callback`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Get('hubspot')
|
@Get('hubspot')
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { GetPublicPermissionsRes } from './dto/entities';
|
|||||||
import { PermissionsService } from './permissions.service';
|
import { PermissionsService } from './permissions.service';
|
||||||
|
|
||||||
@ApiTags('Permissions')
|
@ApiTags('Permissions')
|
||||||
|
@Authenticated()
|
||||||
@Controller('permissions')
|
@Controller('permissions')
|
||||||
@ApiHeader({
|
@ApiHeader({
|
||||||
name: 'dadosfera-lang',
|
name: 'dadosfera-lang',
|
||||||
@@ -22,7 +23,6 @@ import { PermissionsService } from './permissions.service';
|
|||||||
required: false,
|
required: false,
|
||||||
description: 'Defaults to pt-br',
|
description: 'Defaults to pt-br',
|
||||||
})
|
})
|
||||||
@Authenticated()
|
|
||||||
export class PermissionsController {
|
export class PermissionsController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
@@ -36,7 +36,6 @@ export class PermissionsController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse({ type: GetPublicPermissionsRes })
|
@ApiOkResponse({ type: GetPublicPermissionsRes })
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
getPublicPermissions(
|
getPublicPermissions(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
|
|||||||
@@ -1,21 +1,9 @@
|
|||||||
import {
|
import { ConflictException, Inject, OnModuleInit } from '@nestjs/common';
|
||||||
BadRequestException,
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
ConflictException,
|
|
||||||
Inject,
|
|
||||||
InternalServerErrorException,
|
|
||||||
OnModuleInit,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ClientGrpc, Payload } from '@nestjs/microservices';
|
|
||||||
import { PipelineServicesNames, PipelinesServiceInterface } from 'protospack';
|
import { PipelineServicesNames, PipelinesServiceInterface } from 'protospack';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
import { objectSnakeToCamel } from 'src/utils/CaseConverter';
|
|
||||||
|
|
||||||
import {
|
import { IIdRequest } from './interfaces';
|
||||||
ICreatePipelineDto,
|
|
||||||
IGetPipelineLogsRequest,
|
|
||||||
IIdRequest,
|
|
||||||
IUpdatePipelineRequest,
|
|
||||||
} from './interfaces';
|
|
||||||
|
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { PipelinesClientConfiguration } from './pipelines-client';
|
import { PipelinesClientConfiguration } from './pipelines-client';
|
||||||
@@ -39,91 +27,6 @@ export class PipelinesClientService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(@Payload() createPipelineDto: ICreatePipelineDto) {
|
|
||||||
this.logger.info('PipelinesClientService - Create');
|
|
||||||
const createPipelineResponse = await lastValueFrom(
|
|
||||||
this.pipelineService.Create(objectSnakeToCamel(createPipelineDto)),
|
|
||||||
).catch((error: { details: string }) => {
|
|
||||||
if (error.details.includes('INVALID_REQUEST')) {
|
|
||||||
const [, message] = error.details.split('|');
|
|
||||||
throw new BadRequestException(message);
|
|
||||||
}
|
|
||||||
throw new InternalServerErrorException(error.details);
|
|
||||||
});
|
|
||||||
this.logger.info('Done');
|
|
||||||
|
|
||||||
return createPipelineResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll(data) {
|
|
||||||
this.logger.info('PipelinesClientService - FindAll');
|
|
||||||
const findAllPipelineResponse = await lastValueFrom(
|
|
||||||
this.pipelineService.FindAll(data),
|
|
||||||
).catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
this.logger.info('Done');
|
|
||||||
|
|
||||||
return findAllPipelineResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOne(data: IIdRequest) {
|
|
||||||
this.logger.info('PipelinesClientService - FindOne');
|
|
||||||
|
|
||||||
const findOnePipelineResponse = await lastValueFrom(
|
|
||||||
this.pipelineService.FindOne(data),
|
|
||||||
).catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
this.logger.info('Done');
|
|
||||||
|
|
||||||
return findOnePipelineResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(UpdatePipelineRequest: IUpdatePipelineRequest) {
|
|
||||||
this.logger.info('PipelinesClientService - Update');
|
|
||||||
|
|
||||||
const updatePipelineResponse = await lastValueFrom(
|
|
||||||
this.pipelineService.Update(UpdatePipelineRequest),
|
|
||||||
).catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
this.logger.info('Done');
|
|
||||||
|
|
||||||
return updatePipelineResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
async remove(data: IIdRequest) {
|
|
||||||
this.logger.info('PipelinesClientService - Remove');
|
|
||||||
|
|
||||||
const removePipelineResponse = await lastValueFrom(
|
|
||||||
this.pipelineService.remove(data),
|
|
||||||
).catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
this.logger.info('Done');
|
|
||||||
|
|
||||||
return removePipelineResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPipelineLogsMessages(data: IGetPipelineLogsRequest) {
|
|
||||||
this.logger.info('PipelinesClientService - GetPipelineLogsMessages');
|
|
||||||
|
|
||||||
const logsPipelineResponse = await lastValueFrom(
|
|
||||||
this.pipelineService.getPipelineLogs(data),
|
|
||||||
).catch((err) => {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
this.logger.info('Done');
|
|
||||||
|
|
||||||
return logsPipelineResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPipelineStatus(data) {
|
async getPipelineStatus(data) {
|
||||||
this.logger.info('PipelinesClientService - GetPipelineStatus');
|
this.logger.info('PipelinesClientService - GetPipelineStatus');
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,16 @@
|
|||||||
import {
|
import { Body, Controller, Get, Inject, Param, Post } from '@nestjs/common';
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Delete,
|
|
||||||
Get,
|
|
||||||
Inject,
|
|
||||||
Param,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
import {
|
||||||
|
AuthenticateCondition,
|
||||||
|
Authenticated,
|
||||||
|
} from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { PipelinesService } from './pipelines.service';
|
import { PipelinesService } from './pipelines.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
|
||||||
|
|
||||||
@ApiTags('Pipelines')
|
@ApiTags('Pipelines')
|
||||||
@Controller('pipelines')
|
@Controller('pipelines')
|
||||||
|
@Authenticated()
|
||||||
@AuthenticateCondition((req, user) => {
|
@AuthenticateCondition((req, user) => {
|
||||||
let action;
|
let action;
|
||||||
|
|
||||||
@@ -82,84 +76,4 @@ export class PipelinesController {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/:details')
|
|
||||||
async getPipelineLogs(@Param() params) {
|
|
||||||
const { id, details } = params;
|
|
||||||
this.logger.info(
|
|
||||||
process.env.DEV_URL + `/pipeline/${id} - ON GET PIPELINE LOGS ROUTE`,
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
const response = await this.pipelineService.getPipelineLogsMessages(
|
|
||||||
id,
|
|
||||||
details,
|
|
||||||
);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
async create(@Body() createPipelineDto) {
|
|
||||||
this.logger.info(process.env.DEV_URL + `/pipelines ON CREATE ROUTE`);
|
|
||||||
|
|
||||||
const response = await this.pipelineService.create(createPipelineDto);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
async findAll(@User() user: RequestUser) {
|
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline ON Find All ROUTE`, {
|
|
||||||
user: user.user_id,
|
|
||||||
customer: user.customer_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { customer_id, user_id, customer_name } = user;
|
|
||||||
|
|
||||||
const response = await this.pipelineService.findAll({
|
|
||||||
customer_name,
|
|
||||||
customer_id,
|
|
||||||
user_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('/:id')
|
|
||||||
async findOne(@Body() data, @Param() params) {
|
|
||||||
const { id } = params;
|
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON Find One ROUTE`);
|
|
||||||
|
|
||||||
const response = await this.pipelineService.findOne({ id, ...data });
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put(':id')
|
|
||||||
async update(@Body() updatePipelineDto, @Param() params) {
|
|
||||||
const { id } = params;
|
|
||||||
const { info } = updatePipelineDto;
|
|
||||||
delete updatePipelineDto.info;
|
|
||||||
|
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON UPDATE ROUTE`);
|
|
||||||
|
|
||||||
const response = await this.pipelineService.update(
|
|
||||||
id,
|
|
||||||
updatePipelineDto,
|
|
||||||
info,
|
|
||||||
);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete(':id')
|
|
||||||
async delete(@Body() data, @Param() params) {
|
|
||||||
const { id } = params;
|
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON DELETE ROUTE`);
|
|
||||||
|
|
||||||
const response = await this.pipelineService.remove({ id, ...data });
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
import { DecodeGrpcStruct } from 'protospack';
|
|
||||||
import { Info } from 'protospack/dist/lib/interfaces';
|
|
||||||
import { PipelinesClientService } from './client.service';
|
import { PipelinesClientService } from './client.service';
|
||||||
import { IIdRequest } from './interfaces';
|
import { IIdRequest } from './interfaces';
|
||||||
import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
||||||
@@ -9,91 +7,6 @@ import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
|||||||
export class PipelinesService {
|
export class PipelinesService {
|
||||||
constructor(private pipelineClient: PipelinesClientService) {}
|
constructor(private pipelineClient: PipelinesClientService) {}
|
||||||
|
|
||||||
adjustPayload(payload) {
|
|
||||||
if (payload.input?.input_generic) {
|
|
||||||
payload.input = DecodeGrpcStruct(payload.input?.input_generic);
|
|
||||||
} else {
|
|
||||||
payload.input = payload.input?.input_s3 || payload.input?.input_jdbc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(createPipelineDto) {
|
|
||||||
const createPipelineResponse = await this.pipelineClient.create(
|
|
||||||
createPipelineDto,
|
|
||||||
);
|
|
||||||
|
|
||||||
const pipeline = objectCamelToSnake(createPipelineResponse);
|
|
||||||
this.adjustPayload(pipeline.pipeline);
|
|
||||||
|
|
||||||
return pipeline;
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOne(data: IIdRequest) {
|
|
||||||
try {
|
|
||||||
const findOnePipelineResponse = await this.pipelineClient.findOne(data);
|
|
||||||
|
|
||||||
const pipeline = objectCamelToSnake(findOnePipelineResponse);
|
|
||||||
this.adjustPayload(pipeline.pipeline);
|
|
||||||
|
|
||||||
return pipeline;
|
|
||||||
} catch (err) {
|
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll(data) {
|
|
||||||
try {
|
|
||||||
const { pipelines } = await this.pipelineClient.findAll({
|
|
||||||
info: data,
|
|
||||||
});
|
|
||||||
if (pipelines)
|
|
||||||
pipelines.forEach((pipeline) => {
|
|
||||||
this.adjustPayload(pipeline);
|
|
||||||
});
|
|
||||||
return { pipelines: pipelines || [] };
|
|
||||||
} catch (err) {
|
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(id: string, data, info: Info) {
|
|
||||||
try {
|
|
||||||
const updatePipelineResponse = await this.pipelineClient.update({
|
|
||||||
id,
|
|
||||||
info,
|
|
||||||
...data,
|
|
||||||
});
|
|
||||||
|
|
||||||
const pipeline = objectCamelToSnake(updatePipelineResponse);
|
|
||||||
this.adjustPayload(pipeline);
|
|
||||||
|
|
||||||
return pipeline;
|
|
||||||
} catch (err) {
|
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async remove(data: IIdRequest) {
|
|
||||||
try {
|
|
||||||
const removePipelineResponse = await this.pipelineClient.remove(data);
|
|
||||||
|
|
||||||
return removePipelineResponse;
|
|
||||||
} catch (err) {
|
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPipelineLogsMessages(id: string, details: string) {
|
|
||||||
try {
|
|
||||||
const pipelineLogsResponse =
|
|
||||||
await this.pipelineClient.getPipelineLogsMessages({ id, details });
|
|
||||||
|
|
||||||
return objectCamelToSnake(pipelineLogsResponse);
|
|
||||||
} catch (err) {
|
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPipelineStatus(data: IIdRequest) {
|
async getPipelineStatus(data: IIdRequest) {
|
||||||
try {
|
try {
|
||||||
const pipelineStatusResponse =
|
const pipelineStatusResponse =
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export class PipelinesController {
|
|||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() createPipelineDto: ICreatePipelineV2Req,
|
@Body() createPipelineDto: ICreatePipelineV2Req,
|
||||||
) {
|
) {
|
||||||
this.logger.info(process.env.DEV_URL + `/pipelines ON CREATE ROUTE`);
|
this.logger.info('PipelinesController - create', { user });
|
||||||
if (!language) language = 'en-us';
|
if (!language) language = 'en-us';
|
||||||
const { customer_id, customer_name, username, user_id } = user;
|
const { customer_id, customer_name, username, user_id } = user;
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
@@ -86,10 +86,7 @@ export class PipelinesController {
|
|||||||
@Headers('Dadosfera-Lang') language,
|
@Headers('Dadosfera-Lang') language,
|
||||||
@Query() data,
|
@Query() data,
|
||||||
) {
|
) {
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline ON Find All ROUTE`, {
|
this.logger.info('PipelinesController - findAll', { user });
|
||||||
user: user.user_id,
|
|
||||||
customer: user.customer_name,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!language) language = 'en-us';
|
if (!language) language = 'en-us';
|
||||||
|
|
||||||
@@ -103,24 +100,34 @@ export class PipelinesController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await this.pipelinesClientService.findAll(data, metadata);
|
const response = await this.pipelinesClientService.findAll(data, metadata);
|
||||||
const oldResponse = await this.oldPipelinesService.findAll({
|
|
||||||
customer_name,
|
|
||||||
user_id,
|
|
||||||
customer_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pipelines: [...response.pipelines, ...oldResponse.pipelines],
|
pipelines: [...response.pipelines],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get(':id/config')
|
||||||
|
async getPipelineproperties(
|
||||||
|
@Headers('Dadosfera-Lang') language,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Param('id') id,
|
||||||
|
) {
|
||||||
|
this.logger.info('PipelinesController - getPipelineproperties', { user });
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
...user,
|
||||||
|
language: language || 'pt-br',
|
||||||
|
});
|
||||||
|
return this.pipelinesClientService.findOneProperties(id, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
async findOne(
|
async findOne(
|
||||||
@Headers('Dadosfera-Lang') language,
|
@Headers('Dadosfera-Lang') language,
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Param('id') id,
|
@Param('id') id,
|
||||||
): Promise<Messages.PipelineV2FindOneResponse> {
|
): Promise<Messages.PipelineV2FindOneResponse> {
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON Find One ROUTE`);
|
this.logger.info('PipelinesController - findOne', { user });
|
||||||
|
|
||||||
if (!language) language = 'en-us';
|
if (!language) language = 'en-us';
|
||||||
|
|
||||||
const { customer_id, customer_name, user_id, username } = user;
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
@@ -149,24 +156,20 @@ export class PipelinesController {
|
|||||||
: {},
|
: {},
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
})
|
|
||||||
.catch(async (err) => {
|
|
||||||
this.logger.error(err);
|
|
||||||
return await this.oldPipelinesService.findOne({
|
|
||||||
id,
|
|
||||||
info: { customer_id, customer: customer_name, user_id },
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
async update(@Body() updatePipelineDto, @Param('id') id) {
|
async update(
|
||||||
|
@Body() updatePipelineDto,
|
||||||
|
@Param('id') id,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
) {
|
||||||
|
this.logger.info('PipelinesController - findOne', { user });
|
||||||
const { info } = updatePipelineDto;
|
const { info } = updatePipelineDto;
|
||||||
delete updatePipelineDto.info;
|
delete updatePipelineDto.info;
|
||||||
|
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON UPDATE ROUTE`);
|
|
||||||
|
|
||||||
const response = await this.pipelinesClientService.update({
|
const response = await this.pipelinesClientService.update({
|
||||||
...updatePipelineDto,
|
...updatePipelineDto,
|
||||||
info,
|
info,
|
||||||
@@ -177,11 +180,16 @@ export class PipelinesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
async delete(@Body() data, @Param() params) {
|
async delete(@Body() data, @Param() params, @User() user: RequestUser) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON DELETE ROUTE`);
|
this.logger.info('PipelinesController - findOne', { user });
|
||||||
|
|
||||||
const response = await this.pipelinesClientService.remove({ id, ...data });
|
const metadata = PackTheMetadata({ ...user });
|
||||||
|
|
||||||
|
const response = await this.pipelinesClientService.remove(
|
||||||
|
{ id, ...data },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { PipelinesService } from './pipelines.service';
|
|||||||
import { PipelinesClientConfiguration } from './pipelines-client';
|
import { PipelinesClientConfiguration } from './pipelines-client';
|
||||||
|
|
||||||
import { PipelinesModule as OldPipelineModule } from 'src/modules/pipelines/pipelines.module';
|
import { PipelinesModule as OldPipelineModule } from 'src/modules/pipelines/pipelines.module';
|
||||||
|
import { ConnectorModule } from '../connector/connector.module';
|
||||||
|
|
||||||
const client = new PipelinesClientConfiguration();
|
const client = new PipelinesClientConfiguration();
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ const client = new PipelinesClientConfiguration();
|
|||||||
imports: [
|
imports: [
|
||||||
ClientsModule.register([client.providerOptions]),
|
ClientsModule.register([client.providerOptions]),
|
||||||
OldPipelineModule,
|
OldPipelineModule,
|
||||||
|
ConnectorModule,
|
||||||
],
|
],
|
||||||
controllers: [PipelinesController],
|
controllers: [PipelinesController],
|
||||||
providers: [PipelinesService, DadosferaLogger],
|
providers: [PipelinesService, DadosferaLogger],
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
|
HttpException,
|
||||||
Inject,
|
Inject,
|
||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
OnModuleInit,
|
OnModuleInit,
|
||||||
@@ -17,6 +18,8 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|||||||
import { PipelinesClientConfiguration } from './pipelines-client';
|
import { PipelinesClientConfiguration } from './pipelines-client';
|
||||||
import { ICreatePipelineV2Req } from './interfaces';
|
import { ICreatePipelineV2Req } from './interfaces';
|
||||||
import { PipelineV2CreateRequest } from '@dadosfera/protospack-v2/dist/lib/PipelineV2/interfaces/messages';
|
import { PipelineV2CreateRequest } from '@dadosfera/protospack-v2/dist/lib/PipelineV2/interfaces/messages';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
import { ConnectorClientService } from '../connector/client.service';
|
||||||
|
|
||||||
export class PipelinesService implements OnModuleInit {
|
export class PipelinesService implements OnModuleInit {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
@@ -27,6 +30,7 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
dadosferaLogger: DadosferaLogger,
|
dadosferaLogger: DadosferaLogger,
|
||||||
@Inject(PipelinesClientConfiguration.name)
|
@Inject(PipelinesClientConfiguration.name)
|
||||||
private readonly grpcClient: ClientGrpc,
|
private readonly grpcClient: ClientGrpc,
|
||||||
|
private readonly connectorService: ConnectorClientService,
|
||||||
) {
|
) {
|
||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
}
|
}
|
||||||
@@ -152,11 +156,11 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
return updatePipelineResponse;
|
return updatePipelineResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(data: Messages.PipelineV2RemoveRequest) {
|
async remove(data: Messages.PipelineV2RemoveRequest, metadata: Metadata) {
|
||||||
this.logger.info('PipelinesClientService - Remove');
|
this.logger.info('PipelinesClientService - Remove');
|
||||||
|
|
||||||
const removePipelineResponse = await lastValueFrom(
|
const removePipelineResponse = await lastValueFrom(
|
||||||
this.pipelineWriteService.PipelineV2Remove(data),
|
this.pipelineWriteService.PipelineV2Remove(data, metadata),
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.logger.info('Done');
|
this.logger.info('Done');
|
||||||
@@ -164,9 +168,49 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
this.logger.error(err.message);
|
this.logger.error(err.message);
|
||||||
throw new Error(err);
|
console.log(err);
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.details === 'Erro ao pausar pipeline na plataforma.' ? 409 : 500,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return removePipelineResponse;
|
return removePipelineResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findOneProperties(id: string, metadata: Metadata) {
|
||||||
|
this.logger.info('PipelinesClientService - findOneProperties');
|
||||||
|
const { pipeline } = await this.findOne({ id }, metadata);
|
||||||
|
|
||||||
|
const pipelineProperties = JSON.parse(pipeline.properties);
|
||||||
|
|
||||||
|
const connectorId = `${pipeline.connector_plugin}-${pipeline.connector_version}`;
|
||||||
|
|
||||||
|
const res = await this.connectorService.getConnectorDetails(
|
||||||
|
connectorId,
|
||||||
|
metadata.get('language')[0].toString(),
|
||||||
|
);
|
||||||
|
const connector = JSON.parse(res.connector);
|
||||||
|
const config_controls = connector.config_controls || [];
|
||||||
|
|
||||||
|
for (const key in pipelineProperties) {
|
||||||
|
const i = config_controls
|
||||||
|
.map((cc) => cc.name)
|
||||||
|
.indexOf(`properties.${key}`);
|
||||||
|
if (i > -1) {
|
||||||
|
config_controls[i] = {
|
||||||
|
...config_controls[i],
|
||||||
|
default_value: pipelineProperties[key],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
pipeline: {
|
||||||
|
...pipeline,
|
||||||
|
config_controls,
|
||||||
|
properties: pipelineProperties,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class INote {
|
||||||
|
@ApiProperty()
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
content: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
tags: string[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ProductboardController } from './productboard.controller';
|
||||||
|
|
||||||
|
describe('ProductboardController', () => {
|
||||||
|
let controller: ProductboardController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [ProductboardController],
|
||||||
|
providers: [],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<ProductboardController>(ProductboardController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { Body, Controller, HttpException, Post } from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { User, RequestUser } from 'src/authentication/user.decorator';
|
||||||
|
import { getSecreteFromSecreteManager } from 'src/utils/SecretManager';
|
||||||
|
import { INote } from './dtos';
|
||||||
|
|
||||||
|
@ApiTags('Productboard')
|
||||||
|
@Controller('productboard')
|
||||||
|
export class ProductboardController {
|
||||||
|
@Post('notes')
|
||||||
|
async sendNote(@Body() note: INote, @User() user: RequestUser) {
|
||||||
|
const { title, content, tags } = note;
|
||||||
|
const { username, customer_name } = user;
|
||||||
|
|
||||||
|
const email = username.includes('@')
|
||||||
|
? username
|
||||||
|
: username + `@${customer_name}.default`;
|
||||||
|
|
||||||
|
const path = process.env.PB_TOKEN_PATH;
|
||||||
|
const token = await getSecreteFromSecreteManager(path);
|
||||||
|
|
||||||
|
const response = await axios
|
||||||
|
.post(
|
||||||
|
`https://api.productboard.com/notes`,
|
||||||
|
{
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
tags,
|
||||||
|
user: {
|
||||||
|
email,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: 'Bearer ' + token,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
if (!response) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Your request could not be submitted, please try again in a few moments or contact support.',
|
||||||
|
502,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ProductboardController } from './productboard.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [ProductboardController],
|
||||||
|
providers: [],
|
||||||
|
})
|
||||||
|
export class ProductboardModule {}
|
||||||
@@ -36,9 +36,9 @@ export enum TrueOrFalseEnum {
|
|||||||
}
|
}
|
||||||
export class GetRolesByCustomerReq {
|
export class GetRolesByCustomerReq {
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
permissionId: string[];
|
permissionId?: string[];
|
||||||
@ApiPropertyOptional({ enum: TrueOrFalseEnum })
|
@ApiPropertyOptional({ enum: TrueOrFalseEnum })
|
||||||
getUsers: TrueOrFalseEnum;
|
getUsers?: TrueOrFalseEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetRolesByCustomerRes {
|
export class GetRolesByCustomerRes {
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ import { LanguageEnum } from 'src/utils/languages.enum';
|
|||||||
required: false,
|
required: false,
|
||||||
description: 'Defaults to pt-br',
|
description: 'Defaults to pt-br',
|
||||||
})
|
})
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@Controller('roles')
|
@Controller('roles')
|
||||||
export class RolesController {
|
export class RolesController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
@@ -69,7 +69,6 @@ export class RolesController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
async searchRoles(
|
async searchRoles(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Query() filters: GetRolesByCustomerReq,
|
@Query() filters: GetRolesByCustomerReq,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class RolesService {
|
|||||||
|
|
||||||
async roleSearch(
|
async roleSearch(
|
||||||
filters: GetRolesByCustomerReq,
|
filters: GetRolesByCustomerReq,
|
||||||
{ customer_id, access_token }: RequestUser,
|
{ customer_id, access_token }: any,
|
||||||
) {
|
) {
|
||||||
const meta = new Metadata();
|
const meta = new Metadata();
|
||||||
meta.add('access_token', access_token);
|
meta.add('access_token', access_token);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|||||||
|
|
||||||
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
|
||||||
import { RequestUser, User } from '../../authentication/user.decorator';
|
import { RequestUser, User } from '../../authentication/user.decorator';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@ApiTags('TermsOfUse')
|
@ApiTags('TermsOfUse')
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@@ -33,10 +34,15 @@ export class TermsOfUseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('token')
|
@Get('token')
|
||||||
async getToken(@User({ required: true }) user: RequestUser) {
|
async getToken(
|
||||||
|
@User({ required: true }) user: RequestUser,
|
||||||
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
|
) {
|
||||||
this.logger.info('/terms-of-use - get token');
|
this.logger.info('/terms-of-use - get token');
|
||||||
|
const metadata = new Metadata();
|
||||||
|
metadata.add('language', language || 'pt-br');
|
||||||
|
|
||||||
return this.termsOfUseClient.getToken({ userId: user.user_id });
|
return this.termsOfUseClient.getToken({ userId: user.user_id }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('accept')
|
@Post('accept')
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
TermsOfUseAcceptRequest,
|
TermsOfUseAcceptRequest,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TermsOfUseClientService implements OnModuleInit {
|
export class TermsOfUseClientService implements OnModuleInit {
|
||||||
@@ -31,8 +32,10 @@ export class TermsOfUseClientService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getToken(data: TermsOfUseGetTokenRequest) {
|
async getToken(data: TermsOfUseGetTokenRequest, metadata: Metadata) {
|
||||||
return lastValueFrom(this.termsOfUseService.TermsOfUseGetToken(data));
|
return lastValueFrom(
|
||||||
|
this.termsOfUseService.TermsOfUseGetToken(data, metadata),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async accept(data: TermsOfUseAcceptRequest) {
|
async accept(data: TermsOfUseAcceptRequest) {
|
||||||
|
|||||||
@@ -55,7 +55,10 @@ export class UserNoRoles extends OmitType(User, ['roles']) {}
|
|||||||
export class UserNoRolesAndCustomer extends OmitType(UserNoRoles, [
|
export class UserNoRolesAndCustomer extends OmitType(UserNoRoles, [
|
||||||
'customer',
|
'customer',
|
||||||
]) {}
|
]) {}
|
||||||
export class UserByCustomer extends OmitType(User, ['customer']) {}
|
export class IUserByCustomer extends OmitType(User, ['customer']) {
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
permissions?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export class CreateUserReq {
|
export class CreateUserReq {
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@@ -111,11 +114,11 @@ export class UpdateUserReq {
|
|||||||
|
|
||||||
export class UpdateUserRes {
|
export class UpdateUserRes {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
user: UserByCustomer;
|
user: IUserByCustomer;
|
||||||
}
|
}
|
||||||
export class GetAllUsersByCustomerIdRes {
|
export class GetAllUsersByCustomerIdRes {
|
||||||
@ApiProperty({ type: [UserByCustomer] })
|
@ApiProperty({ type: [IUserByCustomer] })
|
||||||
users: UserByCustomer[];
|
users: IUserByCustomer[];
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
departments: string[];
|
departments: string[];
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@@ -153,7 +156,7 @@ export class SetUserRolesReq {
|
|||||||
|
|
||||||
export class SetUserRolesRes {
|
export class SetUserRolesRes {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
user: UserByCustomer;
|
user: IUserByCustomer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SearchUserRes extends GetAllUsersByCustomerIdRes {}
|
export class SearchUserRes extends GetAllUsersByCustomerIdRes {}
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ import {
|
|||||||
ApiTags,
|
ApiTags,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
@@ -42,10 +45,12 @@ import {
|
|||||||
UnassignRoleToUserReq,
|
UnassignRoleToUserReq,
|
||||||
UpdateUserReq,
|
UpdateUserReq,
|
||||||
UpdateUserRes,
|
UpdateUserRes,
|
||||||
UserByCustomer,
|
IUserByCustomer,
|
||||||
} from './dtos/entities';
|
} from './dtos/entities';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
import ErrorBuilder from 'src/utils/ErrorBuilder';
|
||||||
|
import ErrorCodes from 'src/utils/errorCodes';
|
||||||
|
|
||||||
// TODO GET de hierarquias e do PATCH em usuário
|
// TODO GET de hierarquias e do PATCH em usuário
|
||||||
@ApiTags('Users')
|
@ApiTags('Users')
|
||||||
@@ -56,6 +61,7 @@ import { Metadata } from '@grpc/grpc-js';
|
|||||||
required: false,
|
required: false,
|
||||||
description: 'Defaults to pt-br',
|
description: 'Defaults to pt-br',
|
||||||
})
|
})
|
||||||
|
@Authenticated()
|
||||||
@UseFilters(GrpcToHttpExceptionFilter)
|
@UseFilters(GrpcToHttpExceptionFilter)
|
||||||
export class UsersController {
|
export class UsersController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
@@ -69,7 +75,6 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
type: GetAllUsersByCustomerIdRes,
|
type: GetAllUsersByCustomerIdRes,
|
||||||
description: 'List of users of a customer',
|
description: 'List of users of a customer',
|
||||||
@@ -120,9 +125,8 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
type: UserByCustomer,
|
type: IUserByCustomer,
|
||||||
})
|
})
|
||||||
async findOneById(
|
async findOneById(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -131,6 +135,14 @@ export class UsersController {
|
|||||||
) {
|
) {
|
||||||
this.logger.info('findOneById', { user });
|
this.logger.info('findOneById', { user });
|
||||||
this.userService.setLanguage(language);
|
this.userService.setLanguage(language);
|
||||||
|
if (
|
||||||
|
id !== user.user_id &&
|
||||||
|
!user.permissions.includes(
|
||||||
|
PERMISSIONS_GROUPS.USERS.permissions.ADMIN.seqid,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new ErrorBuilder(ErrorCodes.AUTH.FORBIDDEN);
|
||||||
|
}
|
||||||
return await this.userService.findOneById(id);
|
return await this.userService.findOneById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
BatchCreateUserReq,
|
BatchCreateUserReq,
|
||||||
CreateUserReq,
|
CreateUserReq,
|
||||||
Hierarchy,
|
Hierarchy,
|
||||||
|
IUserByCustomer,
|
||||||
SetUserRolesReq,
|
SetUserRolesReq,
|
||||||
UpdateUserReq,
|
UpdateUserReq,
|
||||||
} from './dtos/entities';
|
} from './dtos/entities';
|
||||||
@@ -77,11 +78,24 @@ export class UsersService implements OnModuleInit {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOneById(id: string) {
|
async findOneById(id: string): Promise<{ user: IUserByCustomer }> {
|
||||||
const { user } = await lastValueFrom(
|
const { user } = await lastValueFrom(
|
||||||
this.usersClientService.UserFindOneById({ id }),
|
this.usersClientService.UserFindOneById({ id }),
|
||||||
);
|
);
|
||||||
return { user: this.adjustUsersPayload([user])[0] };
|
const res: { user: IUserByCustomer } = {
|
||||||
|
user: this.adjustUsersPayload([user])[0],
|
||||||
|
};
|
||||||
|
const { permissions } = await lastValueFrom(
|
||||||
|
this.usersClientService.GetUserPermissions({ id }),
|
||||||
|
).catch((error) => {
|
||||||
|
this.logger.error('UsersService.findOneById - GetUserPermissions', {
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
const permissions: string[] = [];
|
||||||
|
return { permissions };
|
||||||
|
});
|
||||||
|
res.user.permissions = permissions;
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser(req: CreateUserReq, meta?: Metadata) {
|
async createUser(req: CreateUserReq, meta?: Metadata) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ interface IMetadata {
|
|||||||
language?: string;
|
language?: string;
|
||||||
details?: string;
|
details?: string;
|
||||||
roles?: string[];
|
roles?: string[];
|
||||||
|
is_data_manager?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PackTheMetadata(info: IMetadata): Metadata {
|
export function PackTheMetadata(info: IMetadata): Metadata {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import {
|
||||||
|
SecretsManagerClient,
|
||||||
|
GetSecretValueCommand,
|
||||||
|
} from '@aws-sdk/client-secrets-manager';
|
||||||
|
|
||||||
|
export async function getSecreteFromSecreteManager(path: string) {
|
||||||
|
const secretsManagerClient = new SecretsManagerClient({});
|
||||||
|
|
||||||
|
const getSecretComand = new GetSecretValueCommand({
|
||||||
|
SecretId: `${path}`,
|
||||||
|
});
|
||||||
|
const res = await secretsManagerClient
|
||||||
|
.send(getSecretComand)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
return res?.SecretString;
|
||||||
|
}
|
||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user