From fecfe1d1f02a7f4fedba341b47f3ac284acd4aa0 Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Thu, 5 Jun 2025 13:47:46 +0000 Subject: [PATCH] refactor: reorganize imports and update guards in AI request controllers --- .../ai/user-ai-requests.controller.ts | 20 ++++---- .../entities/ai/user-ai-threads.controller.ts | 46 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/backend/src/entities/ai/user-ai-requests.controller.ts b/backend/src/entities/ai/user-ai-requests.controller.ts index b26f7442f..95b467a85 100644 --- a/backend/src/entities/ai/user-ai-requests.controller.ts +++ b/backend/src/entities/ai/user-ai-requests.controller.ts @@ -1,17 +1,17 @@ -import { UseInterceptors, Controller, Injectable, Inject, UseGuards, Post, Body } from '@nestjs/common'; +import { Body, Controller, Inject, Injectable, Post, UseGuards, UseInterceptors } from '@nestjs/common'; import { ApiBearerAuth, ApiBody, ApiOperation, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { SentryInterceptor } from '../../interceptors/sentry.interceptor.js'; import { UseCaseType } from '../../common/data-injection.tokens.js'; -import { IRequestInfoFromTable } from './ai-use-cases.interface.js'; -import { RequestInfoFromTableBodyDTO } from './application/dto/request-info-from-table-body.dto.js'; -import { SlugUuid } from '../../decorators/slug-uuid.decorator.js'; -import { RequestInfoFromTableDS } from './application/data-structures/request-info-from-table.ds.js'; +import { MasterPassword } from '../../decorators/master-password.decorator.js'; import { QueryTableName } from '../../decorators/query-table-name.decorator.js'; +import { SlugUuid } from '../../decorators/slug-uuid.decorator.js'; +import { UserId } from '../../decorators/user-id.decorator.js'; import { InTransactionEnum } from '../../enums/in-transaction.enum.js'; -import { MasterPassword } from '../../decorators/master-password.decorator.js'; +import { TableReadGuard } from '../../guards/table-read.guard.js'; +import { SentryInterceptor } from '../../interceptors/sentry.interceptor.js'; +import { IRequestInfoFromTable } from './ai-use-cases.interface.js'; +import { RequestInfoFromTableDS } from './application/data-structures/request-info-from-table.ds.js'; import { ResponseInfoDS } from './application/data-structures/response-info.ds.js'; -import { UserId } from '../../decorators/user-id.decorator.js'; -import { ConnectionEditGuard } from '../../guards/connection-edit.guard.js'; +import { RequestInfoFromTableBodyDTO } from './application/dto/request-info-from-table-body.dto.js'; @UseInterceptors(SentryInterceptor) @Controller() @@ -30,7 +30,7 @@ export class UserAIRequestsController { description: 'Returned info.', type: ResponseInfoDS, }) - @UseGuards(ConnectionEditGuard) + @UseGuards(TableReadGuard) @ApiBody({ type: RequestInfoFromTableBodyDTO }) @ApiQuery({ name: 'tableName', required: true, type: String }) @Post('/ai/request/:connectionId') diff --git a/backend/src/entities/ai/user-ai-threads.controller.ts b/backend/src/entities/ai/user-ai-threads.controller.ts index 2594802c8..5b3b0f97e 100644 --- a/backend/src/entities/ai/user-ai-threads.controller.ts +++ b/backend/src/entities/ai/user-ai-threads.controller.ts @@ -1,19 +1,27 @@ import { - UseInterceptors, + Body, Controller, - Injectable, + Delete, + Get, Inject, - UseGuards, + Injectable, Post, - Body, - Res, - Get, - Delete, Query, + Res, + UseGuards, + UseInterceptors, } from '@nestjs/common'; import { ApiBearerAuth, ApiBody, ApiOperation, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger'; -import { SentryInterceptor } from '../../interceptors/sentry.interceptor.js'; +import { Response } from 'express'; import { UseCaseType } from '../../common/data-injection.tokens.js'; +import { MasterPassword } from '../../decorators/master-password.decorator.js'; +import { QueryTableName } from '../../decorators/query-table-name.decorator.js'; +import { SlugUuid } from '../../decorators/slug-uuid.decorator.js'; +import { UserId } from '../../decorators/user-id.decorator.js'; +import { InTransactionEnum } from '../../enums/in-transaction.enum.js'; +import { TableReadGuard } from '../../guards/table-read.guard.js'; +import { SentryInterceptor } from '../../interceptors/sentry.interceptor.js'; +import { SuccessResponse } from '../../microservices/saas-microservice/data-structures/common-responce.ds.js'; import { IAddMessageToThreadWithAIAssistant, ICreateThreadWithAIAssistant, @@ -21,21 +29,13 @@ import { IGetAllThreadMessages, IGetAllUserThreadsWithAIAssistant, } from './ai-use-cases.interface.js'; -import { ConnectionEditGuard } from '../../guards/connection-edit.guard.js'; -import { CreateThreadWithAIAssistantBodyDTO } from './application/dto/create-thread-with-ai-assistant-body.dto.js'; -import { CreateThreadWithAssistantDS } from './application/data-structures/create-thread-with-assistant.ds.js'; -import { SlugUuid } from '../../decorators/slug-uuid.decorator.js'; -import { QueryTableName } from '../../decorators/query-table-name.decorator.js'; -import { MasterPassword } from '../../decorators/master-password.decorator.js'; -import { UserId } from '../../decorators/user-id.decorator.js'; -import { InTransactionEnum } from '../../enums/in-transaction.enum.js'; -import { Response } from 'express'; import { AddMessageToThreadWithAssistantDS } from './application/data-structures/add-message-to-thread-with-assistant.ds.js'; -import { FoundUserThreadsWithAiRO } from './application/dto/found-user-threads-with-ai.ro.js'; -import { FoundUserThreadMessagesRO } from './application/dto/found-user-thread-messages.ro.js'; -import { FindAllThreadMessagesDS } from './application/data-structures/find-all-thread-messages.ds.js'; -import { SuccessResponse } from '../../microservices/saas-microservice/data-structures/common-responce.ds.js'; +import { CreateThreadWithAssistantDS } from './application/data-structures/create-thread-with-assistant.ds.js'; import { DeleteThreadWithAssistantDS } from './application/data-structures/delete-thread-with-assistant.ds.js'; +import { FindAllThreadMessagesDS } from './application/data-structures/find-all-thread-messages.ds.js'; +import { CreateThreadWithAIAssistantBodyDTO } from './application/dto/create-thread-with-ai-assistant-body.dto.js'; +import { FoundUserThreadMessagesRO } from './application/dto/found-user-thread-messages.ro.js'; +import { FoundUserThreadsWithAiRO } from './application/dto/found-user-threads-with-ai.ro.js'; @UseInterceptors(SentryInterceptor) @Controller() @@ -61,7 +61,7 @@ export class UserAIThreadsController { status: 201, description: 'Return ai assistant response text as stream.', }) - @UseGuards(ConnectionEditGuard) + @UseGuards(TableReadGuard) @ApiBody({ type: CreateThreadWithAIAssistantBodyDTO }) @ApiQuery({ name: 'tableName', required: true, type: String }) @Post('/ai/thread/:connectionId') @@ -90,7 +90,7 @@ export class UserAIThreadsController { status: 201, description: 'Return ai assistant response text as stream.', }) - @UseGuards(ConnectionEditGuard) + @UseGuards(TableReadGuard) @ApiBody({ type: CreateThreadWithAIAssistantBodyDTO }) @ApiQuery({ name: 'tableName', required: true, type: String }) @Post('/ai/thread/message/:connectionId/:threadId')