Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm';

export class CreateConsistencyReportTable1700000000000
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'consistency_reports',
columns: [
{
name: 'id',
type: 'varchar',
length: '36',
isPrimary: true,
generationStrategy: 'uuid',
},
{
name: 'escrowId',
type: 'varchar',
length: '36',
},
{
name: 'severity',
type: 'varchar',
length: '20',
},
{
name: 'discrepancies',
type: 'text',
},
{
name: 'metadata',
type: 'text',
isNullable: true,
},
{
name: 'resolved',
type: 'boolean',
default: false,
},
{
name: 'resolvedByUserId',
type: 'varchar',
length: '36',
isNullable: true,
},
{
name: 'resolvedAt',
type: 'datetime',
isNullable: true,
},
{
name: 'createdAt',
type: 'datetime',
default: 'CURRENT_TIMESTAMP',
},
],
}),
true,
);

await queryRunner.createIndex(
'consistency_reports',
new TableIndex({
name: 'idx_consistency_escrow_id',
columnNames: ['escrowId'],
}),
);

await queryRunner.createIndex(
'consistency_reports',
new TableIndex({
name: 'idx_consistency_severity',
columnNames: ['severity'],
}),
);

await queryRunner.createIndex(
'consistency_reports',
new TableIndex({
name: 'idx_consistency_created_at',
columnNames: ['createdAt'],
}),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('consistency_reports');
}
}
5 changes: 5 additions & 0 deletions apps/backend/src/modules/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ScheduleModule } from '@nestjs/schedule';

import { AdminController } from './admin.controller';
import { AdminService } from './admin.service';
Expand All @@ -12,6 +13,7 @@ import { EscrowModule } from '../escrow/escrow.module';
import { ConsistencyCheckerService } from './services/consistency-checker.service';
import { AdminEscrowConsistencyController } from './controllers/admin-escrow-consistency.controller';
import { AdminAuditLog } from './entities/admin-audit-log.entity';
import { ConsistencyReport } from './entities/consistency-report.entity';
import { AdminAuditLogService } from './services/admin-audit-log.service';
import { AnalyticsService } from './services/analytics.service';
import { AnalyticsController } from './controllers/analytics.controller';
Expand All @@ -20,12 +22,14 @@ import { Dispute } from '../escrow/entities/dispute.entity';
@Module({
imports: [
AuthModule,
ScheduleModule.forRoot(),
TypeOrmModule.forFeature([
User,
Escrow,
Party,
EscrowEvent,
AdminAuditLog,
ConsistencyReport,
Dispute,
]),
EscrowModule,
Expand All @@ -40,6 +44,7 @@ import { Dispute } from '../escrow/entities/dispute.entity';
ConsistencyCheckerService,
AdminAuditLogService,
AnalyticsService,
ConsistencyNotificationService,
],
exports: [AdminService, ConsistencyCheckerService],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Post, Get, Param, Query, UseGuards } from '@nestjs/common';
import { ConsistencyCheckerService } from '../services/consistency-checker.service';
import {
ConsistencyCheckRequest,
ConsistencyCheckResponse,
} from '../dto/consistency-check.dto';
import { AdminGuard } from '../../auth/middleware/admin.guard';
import { ConsistencySeverity } from '../entities/consistency-report.entity';

@Controller('admin/escrows')
@Controller('admin/consistency')
@UseGuards(AdminGuard)
export class AdminEscrowConsistencyController {
constructor(private readonly checker: ConsistencyCheckerService) {}

@Post('consistency-check')
@Post('check')
async checkConsistency(
@Body() body: ConsistencyCheckRequest,
): Promise<ConsistencyCheckResponse> {
return this.checker.checkConsistency(body);
}

@Get('reports')
async getReports(
@Query('severity') severity?: ConsistencySeverity,
@Query('resolved') resolved?: string,
@Query('page') page?: string,
@Query('limit') limit?: string,
) {
return this.checker.getReports({
severity,
resolved: resolved === 'true' ? true : resolved === 'false' ? false : undefined,
page: page ? parseInt(page, 10) : 1,
limit: limit ? parseInt(limit, 10) : 20,
});
}

@Get(':escrowId')
async getDetailedComparison(@Param('escrowId') escrowId: string) {
return this.checker.getDetailedComparison(escrowId);
}

@Post('resolve')
async resolveDiscrepancy(
@Body() body: { escrowId: string; adminUserId: string; syncToOnchain: boolean },
) {
await this.checker.resolveDiscrepancy(
body.escrowId,
body.adminUserId,
body.syncToOnchain,
);
return { success: true, message: 'Discrepancy resolved' };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
Index,
} from 'typeorm';

export enum ConsistencySeverity {
CRITICAL = 'critical',
WARNING = 'warning',
INFO = 'info',
}

@Entity('consistency_reports')
@Index('idx_consistency_escrow_id', ['escrowId'])
@Index('idx_consistency_severity', ['severity'])
@Index('idx_consistency_created_at', ['createdAt'])
export class ConsistencyReport {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
escrowId: string;

@Column({ type: 'varchar' })
severity: ConsistencySeverity;

@Column({ type: 'simple-json' })
discrepancies: Array<{
field: string;
dbValue: unknown;
onchainValue: unknown;
}>;

@Column({ type: 'simple-json', nullable: true })
metadata?: Record<string, unknown>;

@Column({ default: false })
resolved: boolean;

@Column({ nullable: true })
resolvedByUserId?: string;

@Column({ type: 'datetime', nullable: true })
resolvedAt?: Date;

@CreateDateColumn()
createdAt: Date;
}
Loading
Loading