46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import { Controller, Post, Body, Headers } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
|
import { MetaAdsService } from '../services/meta-ads.service';
|
|
import { FetchMetaInsightsDto } from '../dto/fetch-insights.dto';
|
|
import { ConnectAccountDto } from '../dto/connect-account.dto';
|
|
import { ConnectedAccount } from '../entities/connected-account.entity';
|
|
import { NormalizedCampaignInsight } from '../interfaces/campaign-insight.interface';
|
|
|
|
/**
|
|
* Meta Ads Controller
|
|
* متحكم إعلانات ميتا
|
|
*
|
|
* Exposes endpoints for Meta Ads data retrieval.
|
|
* يوفر نقاط نهاية لاسترجاع بيانات إعلانات ميتا.
|
|
*/
|
|
@ApiTags('meta-ads')
|
|
@Controller('meta')
|
|
export class MetaAdsController {
|
|
constructor(private readonly metaAdsService: MetaAdsService) {}
|
|
|
|
@Post('connect')
|
|
@ApiOperation({ summary: 'Connect an Ad Account | ربط حساب إعلاني' })
|
|
@ApiResponse({ status: 201, type: ConnectedAccount })
|
|
async connectAccount(@Body() dto: ConnectAccountDto): Promise<ConnectedAccount> {
|
|
return this.metaAdsService.connectAccount(dto);
|
|
}
|
|
|
|
@Post('insights')
|
|
@ApiOperation({ summary: 'Get normalized insights directly from Meta API | الحصول على رؤى موحدة مباشرة من ميتا' })
|
|
@ApiResponse({ status: 200, description: 'Return list of normalized campaign insights' })
|
|
async getInsights(
|
|
@Body() dto: FetchMetaInsightsDto,
|
|
@Headers('x-user-id') userId?: string,
|
|
): Promise<NormalizedCampaignInsight[]> {
|
|
if (userId) dto.userId = userId;
|
|
return this.metaAdsService.fetchInsights(dto);
|
|
}
|
|
|
|
@Post('accounts')
|
|
@ApiOperation({ summary: 'Get connected accounts for a user | جلب الحسابات المرتبطة للمستخدم' })
|
|
@ApiResponse({ status: 200, type: [ConnectedAccount] })
|
|
async getConnectedAccounts(@Body('userId') userId: string): Promise<ConnectedAccount[]> {
|
|
return this.metaAdsService.getConnectedAccounts(userId);
|
|
}
|
|
}
|