mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
FIX: Ref Catalogo new functions models
This commit is contained in:
@@ -25,7 +25,9 @@ import {
|
||||
ICatalogAllResponse,
|
||||
IColumnsMetadataResponse,
|
||||
IDocsResponse,
|
||||
IOneDataAsset,
|
||||
IPreviewResponse,
|
||||
IUpdateDataRequest,
|
||||
} from './dtos';
|
||||
|
||||
@ApiTags('Catalog')
|
||||
@@ -279,11 +281,30 @@ export class CatalogController {
|
||||
@Put('data-asset/:id')
|
||||
async updateDataAsset(
|
||||
@User() user: RequestUser,
|
||||
@Headers() headers,
|
||||
@Headers('Dadosfera-Lang') language,
|
||||
@Param('id') id,
|
||||
) {
|
||||
console.log(user, headers);
|
||||
return { data_asset_id: id, message: 'Under development' };
|
||||
@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')
|
||||
|
||||
@@ -225,6 +225,53 @@ class CatalogService implements OnModuleInit {
|
||||
return { data_asset: opensearchTable };
|
||||
}
|
||||
|
||||
async updateOneDataAsset({ data_asset_id, customer_id, body, metadata }) {
|
||||
const { data_asset } = await lastValueFrom(
|
||||
this.catalogWriteService.UpdateDataAsset(
|
||||
{ id: data_asset_id, ...body },
|
||||
metadata,
|
||||
),
|
||||
);
|
||||
|
||||
const opensearchTable = JSON.parse(data_asset);
|
||||
|
||||
const result = opensearchTable.owner
|
||||
? await this.userService
|
||||
.findOneById(opensearchTable.owner)
|
||||
.catch(() => null)
|
||||
: null;
|
||||
|
||||
const owner = result !== null ? result.user.username : null;
|
||||
|
||||
const [customer_users, customer_roles] =
|
||||
await this.getUsernamesAndRolesByCustomerId(customer_id);
|
||||
|
||||
const users = [];
|
||||
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(data_asset_id: string, metadata: Metadata) {
|
||||
const [data_asset_type, id] = data_asset_id.split('-');
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ export class IDataAsset {
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export class IOneDataAsset {
|
||||
data_asset: IDataAsset;
|
||||
}
|
||||
|
||||
export class ICatalogAllResponse {
|
||||
@ApiProperty({ type: [IDataAsset] })
|
||||
data_assets: IDataAsset[];
|
||||
@@ -89,6 +93,15 @@ export class IData {
|
||||
day_opening: number;
|
||||
}
|
||||
|
||||
export class IUpdateDataRequest {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
@ApiProperty()
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
export class IPreview {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user