PATCH: Ref/Catalog new functions

This commit is contained in:
Victor Radael
2022-10-18 13:05:05 -03:00
parent f2dd871de2
commit b921393ba1
5 changed files with 78 additions and 19 deletions
+43 -10
View File
@@ -1,6 +1,7 @@
import {
Body,
Controller,
Delete,
Get,
Headers,
HttpException,
@@ -333,16 +334,6 @@ export class CatalogController {
return res;
}
@Post('data-asset/:id/comment')
async makeAComment(
@User() user: RequestUser,
@Headers() headers,
@Param('id') id,
) {
console.log(user, headers);
return { data_asset_id: id, message: 'Under development' };
}
@Put('data-asset/:id/manage-permissions')
async manageDataAssetPermissions(
@Param('id') id: string,
@@ -384,4 +375,46 @@ export class CatalogController {
return { message: response.message };
}
@Post('data-asset/:id/comment')
async commentOnDataAsset(
@Param('id') id: string,
@User() user: RequestUser,
@Body('message') message,
) {
const { customer_id, customer_name, user_id, username } = user;
const metadata = PackTheMetadata({
customer_id,
customer_name,
user_id,
username,
});
const response = await this.catalogService.commentOnDataAsset(
{ data_asset_id: id, username, message },
metadata,
);
return response;
}
@Delete('data-asset/:id/comment')
async deleteComment(
@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,
user_id,
username,
});
const response = await this.catalogService.deleteComment(
{ data_asset_id: id, comment: body.comment },
metadata,
);
return response;
}
}
+26
View File
@@ -84,6 +84,32 @@ class CatalogService implements OnModuleInit {
});
}
async commentOnDataAsset(data: Messages.MakeACommentRequest, metadata) {
this.logger.info('CatalogService - Manage Data assets permissions');
return lastValueFrom(
this.catalogWriteService.MakeAComment(data, metadata),
).catch((err) => {
throw new HttpException(
err.details,
err.code === 6 ? HttpStatus.CONFLICT : 404,
);
});
}
async deleteComment(data: Messages.UpdateACommentRequest, metadata) {
this.logger.info('CatalogService - Manage Data assets permissions');
return lastValueFrom(
this.catalogWriteService.UpdateAComment(data, metadata),
).catch((err) => {
throw new HttpException(
err.details,
err.code === 6 ? HttpStatus.CONFLICT : 404,
);
});
}
async getUserRolesIds(userId: string) {
const result = await this.userService.findOneById(userId).catch(() => null);