improvement for the backend api

This commit is contained in:
ivannoskov
2025-11-19 12:56:04 +03:00
parent b0a9934220
commit d4672ea32b
40 changed files with 2383 additions and 3313 deletions

View File

@@ -1,4 +1,4 @@
import { TargetChannel, TargetChannelDetail } from "@/lib/types/api";
import { TargetChannel } from "@/lib/types/api";
// ============================================================================
// Mock Target Channels Data
@@ -6,74 +6,24 @@ import { TargetChannel, TargetChannelDetail } from "@/lib/types/api";
export const mockTargetChannels: TargetChannel[] = [
{
id: "tc1",
id: "550e8400-e29b-41d4-a716-446655440010",
telegram_id: -1001234567890,
title: "Мой Главный Канал",
username: "my_main_channel",
description: "Основной канал для продвижения продукта",
is_active: true,
created_at: "2024-01-10T10:00:00.000Z",
updated_at: "2024-01-10T10:00:00.000Z",
total_purchases: 15,
total_subscriptions: 1250,
avg_cpf: 45.5,
},
{
id: "tc2",
id: "550e8400-e29b-41d4-a716-446655440011",
telegram_id: -1009876543210,
title: "Тестовый Канал",
username: "test_channel_promo",
description: "Канал для тестирования рекламных креативов",
is_active: true,
created_at: "2024-02-15T12:00:00.000Z",
updated_at: "2024-02-15T12:00:00.000Z",
total_purchases: 8,
total_subscriptions: 450,
avg_cpf: 52.3,
},
{
id: "tc3",
id: "550e8400-e29b-41d4-a716-446655440012",
telegram_id: -1005555555555,
title: "Новости и Обновления",
username: null,
description: "Приватный канал для новостей",
is_active: false,
created_at: "2024-03-01T08:00:00.000Z",
updated_at: "2024-03-20T14:30:00.000Z",
total_purchases: 3,
total_subscriptions: 120,
avg_cpf: 67.8,
},
];
export const getMockTargetChannelDetail = (
id: string
): TargetChannelDetail | null => {
const channel = mockTargetChannels.find((c) => c.id === id);
if (!channel) return null;
return {
...channel,
recent_purchases: [], // Will be populated from purchases mock
stats_by_period: [
{
period: "day",
subscriptions: 25,
cost: 1200,
cpf: 48.0,
},
{
period: "week",
subscriptions: 180,
cost: 8500,
cpf: 47.2,
},
{
period: "month",
subscriptions: 750,
cost: 35000,
cpf: 46.7,
},
],
};
};

View File

@@ -1,4 +1,4 @@
import { Creative, CreativeDetail } from "@/lib/types/api";
import { Creative } from "@/lib/types/api";
import { mockTargetChannels } from "./channels";
// ============================================================================
@@ -11,61 +11,39 @@ export const mockCreatives: Creative[] = [
name: 'Креатив "Присоединяйся"',
text: "🔥 Присоединяйся к нашему сообществу!\n\nУзнавай первым о новых возможностях и фишках.\n\n👉 {link}",
target_channel_id: "tc1",
is_archived: false,
target_channel_title: mockTargetChannels[0].title,
created_at: "2024-01-15T10:00:00.000Z",
updated_at: "2024-01-15T10:00:00.000Z",
target_channel: mockTargetChannels[0],
total_purchases: 10,
total_subscriptions: 850,
avg_cpf: 42.3,
status: "active",
placements_count: 10,
},
{
id: "cr2",
name: 'Креатив "Эксклюзив"',
text: "⭐ Эксклюзивный контент только для подписчиков!\n\nНе упусти возможность быть в курсе всех трендов.\n\nПереходи: {link}",
target_channel_id: "tc1",
is_archived: false,
target_channel_title: mockTargetChannels[0].title,
created_at: "2024-01-20T12:00:00.000Z",
updated_at: "2024-01-20T12:00:00.000Z",
target_channel: mockTargetChannels[0],
total_purchases: 5,
total_subscriptions: 400,
avg_cpf: 48.5,
status: "active",
placements_count: 5,
},
{
id: "cr3",
name: 'Креатив "Обучение"',
text: "📚 Хочешь научиться зарабатывать больше?\n\nПодписывайся на канал с проверенными методиками!\n\n{link}",
target_channel_id: "tc2",
is_archived: false,
target_channel_title: mockTargetChannels[1].title,
created_at: "2024-02-05T09:00:00.000Z",
updated_at: "2024-02-05T09:00:00.000Z",
target_channel: mockTargetChannels[1],
total_purchases: 8,
total_subscriptions: 450,
avg_cpf: 52.3,
status: "active",
placements_count: 8,
},
{
id: "cr4",
name: "Старый креатив (архив)",
text: "Устаревший текст с предложением. {link}",
target_channel_id: "tc1",
is_archived: true,
target_channel_title: mockTargetChannels[0].title,
created_at: "2023-12-01T10:00:00.000Z",
updated_at: "2024-01-10T15:00:00.000Z",
target_channel: mockTargetChannels[0],
total_purchases: 2,
total_subscriptions: 80,
avg_cpf: 75.0,
status: "archived",
placements_count: 2,
},
];
export const getMockCreativeDetail = (id: string): CreativeDetail | null => {
const creative = mockCreatives.find((c) => c.id === id);
if (!creative) return null;
return {
...creative,
purchases: [], // Will be populated from purchases mock
};
};

View File

@@ -1,4 +1,4 @@
import { ExternalChannel, ExternalChannelDetail } from "@/lib/types/api";
import { ExternalChannel } from "@/lib/types/api";
// ============================================================================
// Mock External Channels Data
@@ -6,90 +6,43 @@ import { ExternalChannel, ExternalChannelDetail } from "@/lib/types/api";
export const mockExternalChannels: ExternalChannel[] = [
{
id: "ec1",
id: "550e8400-e29b-41d4-a716-446655440020",
telegram_id: -1001111111111,
title: "Канал о Маркетинге",
username: "marketing_pro",
link: "https://t.me/marketing_pro",
subscribers_count: 50000,
description: "Лучшие практики маркетинга",
created_at: "2024-01-05T10:00:00.000Z",
updated_at: "2024-01-05T10:00:00.000Z",
target_channels: ["tc1", "tc2"],
total_purchases: 5,
avg_cpf: 42.5,
avg_cpm: 850.0,
},
{
id: "ec2",
id: "550e8400-e29b-41d4-a716-446655440021",
telegram_id: -1002222222222,
title: "Бизнес и Стартапы",
username: "business_startups",
link: "https://t.me/business_startups",
subscribers_count: 120000,
description: "Новости мира бизнеса",
created_at: "2024-01-08T11:00:00.000Z",
updated_at: "2024-01-08T11:00:00.000Z",
target_channels: ["tc1"],
total_purchases: 8,
avg_cpf: 55.8,
avg_cpm: 1200.0,
},
{
id: "ec3",
id: "550e8400-e29b-41d4-a716-446655440022",
telegram_id: -1003333333333,
title: "IT и Технологии",
username: "it_tech_news",
link: "https://t.me/it_tech_news",
subscribers_count: 85000,
description: "Все о новых технологиях",
created_at: "2024-01-12T09:00:00.000Z",
updated_at: "2024-01-12T09:00:00.000Z",
target_channels: ["tc1", "tc2"],
total_purchases: 3,
avg_cpf: 38.2,
avg_cpm: 750.0,
},
{
id: "ec4",
telegram_id: null,
id: "550e8400-e29b-41d4-a716-446655440023",
telegram_id: -1004444444444,
title: "Крипто Инвестиции",
username: "crypto_invest",
link: "https://t.me/crypto_invest",
subscribers_count: 200000,
description: null,
created_at: "2024-02-01T10:00:00.000Z",
updated_at: "2024-02-01T10:00:00.000Z",
target_channels: ["tc2"],
total_purchases: 2,
avg_cpf: 68.5,
avg_cpm: 1500.0,
},
{
id: "ec5",
id: "550e8400-e29b-41d4-a716-446655440024",
telegram_id: -1005555555555,
title: "Продажи и Переговоры",
username: "sales_expert",
link: "https://t.me/sales_expert",
subscribers_count: 35000,
description: "Экспертиза в продажах",
created_at: "2024-02-10T14:00:00.000Z",
updated_at: "2024-02-10T14:00:00.000Z",
target_channels: ["tc1"],
total_purchases: 4,
avg_cpf: 45.0,
avg_cpm: 900.0,
},
];
export const getMockExternalChannelDetail = (
id: string
): ExternalChannelDetail | null => {
const channel = mockExternalChannels.find((c) => c.id === id);
if (!channel) return null;
return {
...channel,
purchases: [], // Will be populated from purchases mock
};
};

View File

@@ -0,0 +1,213 @@
import { Placement, Subscription, ViewsSnapshot } from "@/lib/types/api";
import { mockTargetChannels } from "./channels";
import { mockExternalChannels } from "./external-channels";
import { mockCreatives } from "./creatives";
// ============================================================================
// Mock Placements Data
// ============================================================================
export const mockPlacements: Placement[] = [
{
id: "p1",
target_channel_id: "tc1",
target_channel_title: mockTargetChannels[0].title,
external_channel_id: "ec1",
external_channel_title: mockExternalChannels[0].title,
creative_id: "cr1",
creative_name: mockCreatives[0].name,
placement_date: "2024-03-15T10:00:00.000Z",
cost: 5000,
comment: "Тестовая закупка на утро",
ad_post_url: "https://t.me/marketing_pro/1234",
invite_link_type: "approval",
invite_link: "https://t.me/+AbCdEfGhIjKlMnOp",
status: "active",
subscriptions_count: 125,
views_count: 12500,
views_availability: "available",
last_views_fetch_at: "2024-03-16T10:00:00.000Z",
created_at: "2024-03-14T15:00:00.000Z",
},
{
id: "p2",
target_channel_id: "tc1",
target_channel_title: mockTargetChannels[0].title,
external_channel_id: "ec2",
external_channel_title: mockExternalChannels[1].title,
creative_id: "cr2",
creative_name: mockCreatives[1].name,
placement_date: "2024-03-18T14:00:00.000Z",
cost: 12000,
comment: "Большой канал, ожидаем хороших результатов",
ad_post_url: "https://t.me/business_startups/5678",
invite_link_type: "approval",
invite_link: "https://t.me/+QrStUvWxYzAbCdEf",
status: "active",
subscriptions_count: 210,
views_count: 28000,
views_availability: "available",
last_views_fetch_at: "2024-03-19T10:00:00.000Z",
created_at: "2024-03-17T10:00:00.000Z",
},
{
id: "p3",
target_channel_id: "tc2",
target_channel_title: mockTargetChannels[1].title,
external_channel_id: "ec3",
external_channel_title: mockExternalChannels[2].title,
creative_id: "cr3",
creative_name: mockCreatives[2].name,
placement_date: "2024-03-20T16:00:00.000Z",
cost: 3500,
comment: null,
ad_post_url: "https://t.me/it_tech_news/9101",
invite_link_type: "public",
invite_link: "https://t.me/+GhIjKlMnOpQrStUv",
status: "active",
subscriptions_count: 75,
views_count: 8500,
views_availability: "available",
last_views_fetch_at: "2024-03-21T10:00:00.000Z",
created_at: "2024-03-19T12:00:00.000Z",
},
{
id: "p4",
target_channel_id: "tc1",
target_channel_title: mockTargetChannels[0].title,
external_channel_id: "ec1",
external_channel_title: mockExternalChannels[0].title,
creative_id: "cr1",
creative_name: mockCreatives[0].name,
placement_date: "2024-03-22T08:00:00.000Z",
cost: 4500,
comment: "Повтор в этом же канале",
ad_post_url: "https://t.me/marketing_pro/1290",
invite_link_type: "approval",
invite_link: "https://t.me/+XyZaBcDeFgHiJkLm",
status: "active",
subscriptions_count: 95,
views_count: null,
views_availability: "unavailable",
last_views_fetch_at: "2024-03-23T09:00:00.000Z",
created_at: "2024-03-21T14:00:00.000Z",
},
{
id: "p5",
target_channel_id: "tc1",
target_channel_title: mockTargetChannels[0].title,
external_channel_id: "ec2",
external_channel_title: mockExternalChannels[1].title,
creative_id: "cr1",
creative_name: mockCreatives[0].name,
placement_date: "2024-02-10T10:00:00.000Z",
cost: 10000,
comment: "Старая закупка (архив)",
ad_post_url: "https://t.me/business_startups/4567",
invite_link_type: "public",
invite_link: "https://t.me/+OldLinkArch12345",
status: "archived",
subscriptions_count: 150,
views_count: 20000,
views_availability: "available",
last_views_fetch_at: "2024-02-12T10:00:00.000Z",
created_at: "2024-02-09T10:00:00.000Z",
},
];
// Keep old name for backward compatibility
export const mockPurchases = mockPlacements;
// ============================================================================
// Mock Subscriptions
// ============================================================================
export const mockSubscriptions: Subscription[] = [
{
id: "s1",
purchase_id: "p1",
telegram_user_id: 123456789,
user_first_name: "Иван",
user_last_name: "Иванов",
user_username: "ivan_ivanov",
subscribed_at: "2024-03-15T11:35:00.000Z",
is_active: true,
event_type: "join_request",
},
{
id: "s2",
purchase_id: "p1",
telegram_user_id: 987654321,
user_first_name: "Мария",
user_last_name: null,
user_username: "maria123",
subscribed_at: "2024-03-15T12:05:00.000Z",
is_active: true,
event_type: "join_request",
},
{
id: "s3",
purchase_id: "p1",
telegram_user_id: 456789123,
user_first_name: "Алексей",
user_last_name: "Петров",
user_username: null,
subscribed_at: "2024-03-15T13:20:00.000Z",
is_active: false,
event_type: "join_request",
},
{
id: "s4",
purchase_id: "p2",
telegram_user_id: 789123456,
user_first_name: "Елена",
user_last_name: "Сидорова",
user_username: "elena_s",
subscribed_at: "2024-03-18T14:30:00.000Z",
is_active: true,
event_type: "chat_member",
},
];
// ============================================================================
// Mock Views History
// ============================================================================
export const mockViewsHistory: ViewsSnapshot[] = [
{
id: "v1",
purchase_id: "p1",
views: 10000,
fetched_at: "2024-03-15T12:00:00.000Z",
},
{
id: "v2",
purchase_id: "p1",
views: 11500,
fetched_at: "2024-03-15T18:00:00.000Z",
},
{
id: "v3",
purchase_id: "p1",
views: 12500,
fetched_at: "2024-03-16T10:00:00.000Z",
},
{
id: "v4",
purchase_id: "p2",
views: 25000,
fetched_at: "2024-03-18T15:00:00.000Z",
},
{
id: "v5",
purchase_id: "p2",
views: 27000,
fetched_at: "2024-03-18T20:00:00.000Z",
},
{
id: "v6",
purchase_id: "p2",
views: 28000,
fetched_at: "2024-03-19T10:00:00.000Z",
},
];

View File

@@ -1,264 +0,0 @@
import {
Purchase,
PurchaseDetail,
Subscription,
ViewsSnapshot,
} from "@/lib/types/api";
import { mockTargetChannels } from "./channels";
import { mockExternalChannels } from "./external-channels";
import { mockCreatives } from "./creatives";
// ============================================================================
// Mock Purchases Data
// ============================================================================
export const mockPurchases: Purchase[] = [
{
id: "p1",
target_channel_id: "tc1",
external_channel_id: "ec1",
creative_id: "cr1",
scheduled_date: "2024-03-15T10:00:00.000Z",
actual_date: "2024-03-15T11:30:00.000Z",
cost: 5000,
comment: "Тестовая закупка на утро",
post_link: "https://t.me/marketing_pro/1234",
invite_link: "https://t.me/+AbCdEfGhIjKlMnOp",
invite_link_type: "public",
is_archived: false,
created_at: "2024-03-14T15:00:00.000Z",
updated_at: "2024-03-15T11:30:00.000Z",
target_channel: mockTargetChannels[0],
external_channel: mockExternalChannels[0],
creative: mockCreatives[0],
subscriptions_count: 125,
views_count: 12500,
cpf: 40.0,
cpm: 400.0,
conversion_rate: 1.0,
},
{
id: "p2",
target_channel_id: "tc1",
external_channel_id: "ec2",
creative_id: "cr2",
scheduled_date: "2024-03-18T14:00:00.000Z",
actual_date: "2024-03-18T14:15:00.000Z",
cost: 12000,
comment: "Большой канал, ожидаем хороших результатов",
post_link: "https://t.me/business_startups/5678",
invite_link: "https://t.me/+QrStUvWxYzAbCdEf",
invite_link_type: "public",
is_archived: false,
created_at: "2024-03-17T10:00:00.000Z",
updated_at: "2024-03-18T14:15:00.000Z",
target_channel: mockTargetChannels[0],
external_channel: mockExternalChannels[1],
creative: mockCreatives[1],
subscriptions_count: 210,
views_count: 28000,
cpf: 57.1,
cpm: 428.6,
conversion_rate: 0.75,
},
{
id: "p3",
target_channel_id: "tc2",
external_channel_id: "ec3",
creative_id: "cr3",
scheduled_date: "2024-03-20T16:00:00.000Z",
actual_date: null,
cost: 3500,
comment: null,
post_link: "https://t.me/it_tech_news/9101",
invite_link: "https://t.me/+GhIjKlMnOpQrStUv",
invite_link_type: "private",
is_archived: false,
created_at: "2024-03-19T12:00:00.000Z",
updated_at: "2024-03-19T12:00:00.000Z",
target_channel: mockTargetChannels[1],
external_channel: mockExternalChannels[2],
creative: mockCreatives[2],
subscriptions_count: 85,
views_count: 8500,
cpf: 41.2,
cpm: 411.8,
conversion_rate: 1.0,
},
{
id: "p4",
target_channel_id: "tc1",
external_channel_id: "ec5",
creative_id: "cr1",
scheduled_date: "2024-03-22T12:00:00.000Z",
actual_date: null,
cost: 4500,
comment: "Повторная закупка в том же канале",
post_link: null,
invite_link: "https://t.me/+WxYzAbCdEfGhIjKl",
invite_link_type: "public",
is_archived: false,
created_at: "2024-03-21T09:00:00.000Z",
updated_at: "2024-03-21T09:00:00.000Z",
target_channel: mockTargetChannels[0],
external_channel: mockExternalChannels[4],
creative: mockCreatives[0],
subscriptions_count: 95,
views_count: null,
cpf: 47.4,
cpm: null,
conversion_rate: null,
},
{
id: "p5",
target_channel_id: "tc1",
external_channel_id: "ec1",
creative_id: "cr1",
scheduled_date: "2024-02-10T10:00:00.000Z",
actual_date: "2024-02-10T10:30:00.000Z",
cost: 5500,
comment: "Старая закупка для истории",
post_link: "https://t.me/marketing_pro/1100",
invite_link: "https://t.me/+OldInviteLink123",
invite_link_type: "public",
is_archived: true,
created_at: "2024-02-09T15:00:00.000Z",
updated_at: "2024-02-20T10:00:00.000Z",
target_channel: mockTargetChannels[0],
external_channel: mockExternalChannels[0],
creative: mockCreatives[0],
subscriptions_count: 140,
views_count: 15000,
cpf: 39.3,
cpm: 366.7,
conversion_rate: 0.93,
},
];
// Mock Subscriptions
export const mockSubscriptions: Subscription[] = [
{
id: "s1",
purchase_id: "p1",
telegram_user_id: 111111111,
user_first_name: "Иван",
user_last_name: "Петров",
user_username: "user1",
subscribed_at: "2024-03-15T11:35:00.000Z",
is_active: true,
event_type: "chat_member",
},
{
id: "s2",
purchase_id: "p1",
telegram_user_id: 222222222,
user_first_name: "Мария",
user_last_name: "Сидорова",
user_username: "user2",
subscribed_at: "2024-03-15T11:40:00.000Z",
is_active: true,
event_type: "chat_member",
},
{
id: "s3",
purchase_id: "p1",
telegram_user_id: 333333333,
user_first_name: "Алексей",
user_last_name: null,
user_username: null,
subscribed_at: "2024-03-15T12:00:00.000Z",
is_active: false,
event_type: "join_request",
},
{
id: "s4",
purchase_id: "p2",
telegram_user_id: 444444444,
user_first_name: "Елена",
user_last_name: "Кузнецова",
user_username: "user4",
subscribed_at: "2024-03-18T14:20:00.000Z",
is_active: true,
event_type: "chat_member",
},
{
id: "s5",
purchase_id: "p2",
telegram_user_id: 555555555,
user_first_name: "Дмитрий",
user_last_name: "Смирнов",
user_username: "user5",
subscribed_at: "2024-03-18T14:25:00.000Z",
is_active: true,
event_type: "chat_member",
},
];
// Mock Views Snapshots
export const mockViewsSnapshots: ViewsSnapshot[] = [
{
id: "v1",
purchase_id: "p1",
views: 5000,
fetched_at: "2024-03-15T12:00:00.000Z",
},
{
id: "v2",
purchase_id: "p1",
views: 8500,
fetched_at: "2024-03-15T18:00:00.000Z",
},
{
id: "v3",
purchase_id: "p1",
views: 10200,
fetched_at: "2024-03-16T09:00:00.000Z",
},
{
id: "v4",
purchase_id: "p1",
views: 11800,
fetched_at: "2024-03-16T18:00:00.000Z",
},
{
id: "v5",
purchase_id: "p1",
views: 12500,
fetched_at: "2024-03-17T12:00:00.000Z",
},
{
id: "v6",
purchase_id: "p2",
views: 15000,
fetched_at: "2024-03-18T15:00:00.000Z",
},
{
id: "v7",
purchase_id: "p2",
views: 22000,
fetched_at: "2024-03-18T20:00:00.000Z",
},
{
id: "v8",
purchase_id: "p2",
views: 26500,
fetched_at: "2024-03-19T09:00:00.000Z",
},
{
id: "v9",
purchase_id: "p2",
views: 28000,
fetched_at: "2024-03-19T18:00:00.000Z",
},
];
export const getMockPurchaseDetail = (id: string): PurchaseDetail | null => {
const purchase = mockPurchases.find((p) => p.id === id);
if (!purchase) return null;
return {
...purchase,
subscriptions: mockSubscriptions.filter((s) => s.purchase_id === id),
views_history: mockViewsSnapshots.filter((v) => v.purchase_id === id),
};
};

View File

@@ -6,20 +6,14 @@ import { User } from "@/lib/types/api";
export const mockUsers: User[] = [
{
id: "1",
id: "550e8400-e29b-41d4-a716-446655440001",
telegram_id: 123456789,
username: "ivan_test",
first_name: "Иван",
last_name: "Иванов",
created_at: "2024-01-15T10:00:00.000Z",
},
{
id: "2",
id: "550e8400-e29b-41d4-a716-446655440002",
telegram_id: 987654321,
username: "maria_test",
first_name: "Мария",
last_name: "Петрова",
created_at: "2024-02-01T10:00:00.000Z",
},
];