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
11 changes: 11 additions & 0 deletions backend/src/opsce/audit/audit.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuditLog } from './entities/audit-log.entity';
import { AuditService } from './audit.service';

@Module({
imports: [TypeOrmModule.forFeature([AuditLog])],
providers: [AuditService],
exports: [AuditService, TypeOrmModule],
})
export class AuditModule {}
42 changes: 42 additions & 0 deletions backend/src/opsce/audit/audit.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AuditLog } from './entities/audit-log.entity';

export interface LogDto {
userId?: string;
action: string;
resourceType: string;
resourceId: string;
oldValue?: Record<string, unknown>;
newValue?: Record<string, unknown>;
ipAddress?: string;
userAgent?: string;
}

@Injectable()
export class AuditService {
constructor(
@InjectRepository(AuditLog)
private readonly repo: Repository<AuditLog>,
) {}

async log(dto: LogDto): Promise<AuditLog> {
const entry = this.repo.create(dto);
return this.repo.save(entry);
}

async findByResource(resourceType: string, resourceId: string): Promise<AuditLog[]> {
return this.repo.find({
where: { resourceType, resourceId },
order: { createdAt: 'DESC' },
});
}

async findByUser(userId: string): Promise<AuditLog[]> {
return this.repo.find({
where: { userId },
order: { createdAt: 'DESC' },
});
}
}
44 changes: 44 additions & 0 deletions backend/src/opsce/audit/entities/audit-log.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
Index,
} from 'typeorm';

@Entity('audit_logs')
export class AuditLog {
@PrimaryGeneratedColumn('uuid')
id: string;

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

@Column()
action: string;

@Index()
@Column()
resourceType: string;

@Index()
@Column()
resourceId: string;

@Column({ type: 'jsonb', nullable: true })
oldValue?: Record<string, unknown>;

@Column({ type: 'jsonb', nullable: true })
newValue?: Record<string, unknown>;

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

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

@Index()
@CreateDateColumn()
createdAt: Date;
}
8 changes: 8 additions & 0 deletions backend/src/opsce/opsce.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { AuditModule } from './audit/audit.module';

@Module({
imports: [AuditModule],
exports: [AuditModule],
})
export class OpsceModule {}
74 changes: 74 additions & 0 deletions frontend/opsce/components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use client';

import React from 'react';

interface State {
hasError: boolean;
error?: Error;
}

export class ErrorBoundary extends React.Component<
{ children: React.ReactNode },
State
> {
constructor(props: { children: React.ReactNode }) {
super(props);
this.state = { hasError: false };
}

static getDerivedStateFromError(error: Error): State {
return { hasError: true, error };
}

componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error('[ErrorBoundary]', error, errorInfo);
}

render() {
if (this.state.hasError) {
return (
<div className="min-h-screen bg-gray-50 flex items-center justify-center p-6">
<div className="bg-white rounded-2xl border border-gray-200 shadow-sm p-10 max-w-md w-full text-center">
<div className="w-14 h-14 rounded-full bg-red-50 flex items-center justify-center mx-auto mb-5">
<svg
className="w-7 h-7 text-red-500"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
</div>
<h1 className="text-xl font-semibold text-gray-900 mb-2">
Something went wrong
</h1>
<p className="text-sm text-gray-500 mb-8">
An unexpected error occurred. Please try reloading the page.
</p>
<div className="flex gap-3 justify-center">
<button
onClick={() => window.location.reload()}
className="px-5 py-2.5 text-sm font-medium bg-gray-900 text-white rounded-lg hover:bg-gray-700 transition-colors"
>
Try reloading
</button>
<a
href="/dashboard"
className="px-5 py-2.5 text-sm font-medium border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors"
>
Go to Dashboard
</a>
</div>
</div>
</div>
);
}

return this.props.children;
}
}
1 change: 1 addition & 0 deletions frontend/opsce/components/ErrorBoundary/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ErrorBoundary } from './ErrorBoundary';
Loading
Loading