/
integrator2
/
dklt
Обзор
Документация
Войти
/
integrator2
/
dklt
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/app/source/source.controller.ts
210 строк
5 KB
sarkazi
first_commit
05 июн 2025, 14:40
05 июн 2025, 14:40
7f52590
Код
Авторство
О чём код?
import { Controller, Post, Body, HttpCode, UseGuards, Req, Head, Get, Headers, Param, Patch, Query, } from "@nestjs/common"; import { SourceService } from "../../core/source/source.service"; import { AuthGuard } from "../account/guards/auth.guard"; import { Request } from "express"; import { AdminGuard } from "../account/guards/admin.guard"; import { CreateChannelDto } from "./dto/create-channel.dto"; import { ChangeActivityDto } from "./dto/change-activity.dto"; import { UpdateChannelDto } from "./dto/update-channel.dto"; import { IGetAppealsStatDto } from "./dto/get-channel-stat.dto"; import { GlobalLoggerService } from "@/infrastructure/logger/logger.service"; import { ISourceWebhook } from "@/infrastructure/source/source-client/types/webhook-receive.types"; import { InjectConnection } from "@nestjs/mongoose"; import { Connection } from "mongoose"; import { HandleError } from "@/core/decorators/handle-error.decorator"; import { IGetStatDto } from "./dto/get-stat.dto"; @Controller("source") export class SourceController { constructor( private readonly sourceService: SourceService, private readonly logger: GlobalLoggerService, @InjectConnection() private readonly mongoConnection: Connection ) {} @HttpCode(200) @Head("/:channel_entity_id/webhook") async offerMessageWebhookConnector() { return "OK"; } @HttpCode(200) @Post("/:channel_entity_id/webhook") async offerMessageWebhookHandler( @Body() dto: ISourceWebhook, @Param("channel_entity_id") channel_entity_id: string ) { this.sourceService.offerMessageWebhookHandlerProcess( channel_entity_id, dto ); } @HttpCode(200) @Get("channels/:channel_entity_id/af-variants") @UseGuards(AuthGuard, AdminGuard) async getAfVariantsHandler( @Param("channel_entity_id") channel_entity_id: string ) { return await this.sourceService.getAfVariantsHandlerProcess( channel_entity_id ); } @HttpCode(200) @Post("channels") @UseGuards(AuthGuard, AdminGuard) @HandleError() async addChannelHandler( @Req() request: Request, @Body() dto: CreateChannelDto, @Headers() headers: Request["headers"] ) { const authAccount = request.account; const session = await this.mongoConnection.startSession(); session.startTransaction(); try { const result = await this.sourceService.addChannelHandlerProcess( authAccount, dto, headers, session ); await session.commitTransaction(); session.endSession(); return result; } catch (error) { await session.abortTransaction(); session.endSession(); throw error; } } @HttpCode(200) @Patch("channels/:channel_entity_id") @UseGuards(AuthGuard, AdminGuard) @HandleError() async updateChannelEntity( @Req() request: Request, @Body() dto: UpdateChannelDto, @Param("channel_entity_id") channelEntityId: string, @Headers() headers: Request["headers"] ) { const authAccount = request.account; const session = await this.mongoConnection.startSession(); session.startTransaction(); try { const result = await this.sourceService.updateChannelHandlerProcess( authAccount, channelEntityId, dto, headers, session ); await session.commitTransaction(); session.endSession(); return result; } catch (error) { await session.abortTransaction(); session.endSession(); throw error; } } @HttpCode(200) @Post("channels/:channel_entity_id/change-activity") @UseGuards(AuthGuard, AdminGuard) @HandleError() async channelChangeActivityHandler( @Req() request: Request, @Body() dto: ChangeActivityDto, @Param() param: { channel_entity_id: string } ) { const authAccount = request.account; return await this.sourceService.channelChangeActivityHandlerProcess( authAccount.account_id, param.channel_entity_id, dto.isActive ); } @HttpCode(200) @Get("channels") @UseGuards(AuthGuard, AdminGuard) @HandleError() async getChannelsHandler(@Req() request: Request) { const authAccount = request.account; return await this.sourceService.getChannelsHandler(authAccount.account_id); } @HttpCode(200) @Get("channels/stat/appeals") @UseGuards(AuthGuard, AdminGuard) @HandleError() async getStatAppealsHandler( @Req() request: Request, @Query() params: IGetAppealsStatDto ) { const authAccount = request.account; return await this.sourceService.getStatAppealsHandlerProcess( authAccount.account_id, params ); } @HttpCode(200) @Get("channels/stat/allocations") @UseGuards(AuthGuard, AdminGuard) async getStatAllocationsHandler( @Req() request: Request, @Query() params: IGetStatDto ) { const authAccount = request.account; return await this.sourceService.getStatAllocationsHandlerProcess( authAccount.account_id, params ); } // @HttpCode(200) // @Get("offers/:amo_chat_id") // @UseGuards(AuthGuard) // @HandleError() // getOffersBymoChatIdHandler( // @Req() request: Request, // @Param() param: { amo_chat_id: string } // ) { // const authAccount = request.account; // return this.sourceService.getOffersByAmoChatIdHandlerProcess( // authAccount.account_id, // param.amo_chat_id // ); // } }