feat: implement audit logging system with service, controller, and interceptor to track user actions across core services
This commit is contained in:
@@ -2,6 +2,8 @@ import { Injectable, Logger, BadRequestException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import Stripe from 'stripe';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditService } from '../audit/audit.service';
|
||||
import { AuditAction } from '../audit/audit.constants';
|
||||
|
||||
@Injectable()
|
||||
export class StripeService {
|
||||
@@ -11,6 +13,7 @@ export class StripeService {
|
||||
constructor(
|
||||
private configService: ConfigService,
|
||||
private prisma: PrismaService,
|
||||
private audit: AuditService,
|
||||
) {
|
||||
const secretKey = this.configService.get<string>('stripe.secretKey');
|
||||
if (secretKey) {
|
||||
@@ -180,13 +183,20 @@ export class StripeService {
|
||||
stripeSubscriptionId: string,
|
||||
atPeriodEnd = true,
|
||||
): Promise<Stripe.Subscription> {
|
||||
if (atPeriodEnd) {
|
||||
return this.getStripe().subscriptions.update(stripeSubscriptionId, {
|
||||
cancel_at_period_end: true,
|
||||
});
|
||||
}
|
||||
const result = atPeriodEnd
|
||||
? await this.getStripe().subscriptions.update(stripeSubscriptionId, {
|
||||
cancel_at_period_end: true,
|
||||
})
|
||||
: await this.getStripe().subscriptions.cancel(stripeSubscriptionId);
|
||||
|
||||
return this.getStripe().subscriptions.cancel(stripeSubscriptionId);
|
||||
this.audit.log({
|
||||
action: AuditAction.SUBSCRIPTION_CANCEL,
|
||||
resourceType: 'AgentSubscription',
|
||||
resourceId: stripeSubscriptionId,
|
||||
metadata: { atPeriodEnd, source: 'agent_action' },
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async getSubscription(
|
||||
|
||||
Reference in New Issue
Block a user