Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
refactor(audit): remove unused query helpers
Yudhi Armyndharis428b9bce28c7
diff --git a/src/modules/audit/audit.service.spec.ts b/src/modules/audit/audit.service.spec.tsindex 7313208d9..4d48bc6f6 100644--- a/src/modules/audit/audit.service.spec.ts+++ b/src/modules/audit/audit.service.spec.ts@@ -1,4 +1,4 @@-import { Repository, Between } from 'typeorm';+import { Repository } from 'typeorm';import { AuditService } from './audit.service';import { AuditLog, AuditAction, AuditSeverity } from './entities/audit-log.entity';@@ -56,12 +56,11 @@ describe('AuditService', () => {);});- it('logInfo/logWarn/logError map to the right severity', async () => {+ it('logInfo/logWarn map to the right severity', async () => {await service.logInfo(AuditAction.API_KEY_USED);await service.logWarn(AuditAction.API_KEY_AUTH_FAILED);- await service.logError(AuditAction.MESSAGE_FAILED);const severities = (repo.create.mock.calls as unknown[][]).map(c => (c[0] as { severity: AuditSeverity }).severity);- expect(severities).toEqual([AuditSeverity.INFO, AuditSeverity.WARN, AuditSeverity.ERROR]);+ expect(severities).toEqual([AuditSeverity.INFO, AuditSeverity.WARN]);});it('findAll applies provided filters with default take/skip', async () => {@@ -94,23 +93,11 @@ describe('AuditService', () => {expect(arg.skip).toBe(0);});- it('findAll uses Between only when BOTH dates are present', async () => {- const start = new Date('2026-01-01T00:00:00Z');- const end = new Date('2026-02-01T00:00:00Z');- await service.findAll({ startDate: start, endDate: end, limit: 10, offset: 5 });- const arg = (repo.findAndCount.mock.calls as unknown[][])[0][0] as {- where: Record<string, unknown>;- take: number;- skip: number;- };- expect(arg.where.createdAt).toEqual(Between(start, end));+ it('findAll passes an in-range limit and offset through to the query', async () => {+ await service.findAll({ limit: 10, offset: 5 });+ const arg = (repo.findAndCount.mock.calls as unknown[][])[0][0] as { take: number; skip: number };expect(arg.take).toBe(10);expect(arg.skip).toBe(5);-- repo.findAndCount.mockClear();- await service.findAll({ startDate: start }); // only one date → no Between- const arg2 = (repo.findAndCount.mock.calls as unknown[][])[0][0] as { where: Record<string, unknown> };- expect(arg2.where.createdAt).toBeUndefined();});it('cleanup deletes rows older than the cutoff and returns the affected count', async () => {diff --git a/src/modules/audit/audit.service.ts b/src/modules/audit/audit.service.tsindex 1e2a3c77d..8b451ba67 100644--- a/src/modules/audit/audit.service.ts+++ b/src/modules/audit/audit.service.ts@@ -1,6 +1,6 @@import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';import { InjectRepository } from '@nestjs/typeorm';-import { Repository, Between, LessThan, In } from 'typeorm';+import { Repository, LessThan, In } from 'typeorm';import { AuditLog, AuditAction, AuditSeverity } from './entities/audit-log.entity';import { ApiKey } from '../auth/entities/api-key.entity';import { createLogger } from '../../common/services/logger.service';@@ -40,8 +40,6 @@ export interface AuditQueryOptions {apiKeyId?: string;sessionId?: string;severity?: AuditSeverity;- startDate?: Date;- endDate?: Date;limit?: number;offset?: number;}@@ -143,10 +141,6 @@ export class AuditService implements OnModuleInit, OnModuleDestroy {return this.log(action, context, AuditSeverity.WARN);}- async logError(action: AuditAction, context: AuditContext = {}): Promise<AuditLog | null> {- return this.log(action, context, AuditSeverity.ERROR);- }-async findAll(options: AuditQueryOptions = {},allowedSessions?: string[] | null,@@ -168,10 +162,6 @@ export class AuditService implements OnModuleInit, OnModuleDestroy {}if (options.severity) where.severity = options.severity;- if (options.startDate && options.endDate) {- where.createdAt = Between(options.startDate, options.endDate);- }-// Clamp the page size so an arbitrarily large `limit` can't load the whole table into one response.const requested = options.limit && options.limit > 0 ? options.limit : 50;const take = Math.min(requested, MAX_AUDIT_PAGE_SIZE);@@ -190,22 +180,6 @@ export class AuditService implements OnModuleInit, OnModuleDestroy {return { data, total };}- async getRecentByApiKey(apiKeyId: string, limit = 10): Promise<AuditLog[]> {- return this.auditRepository.find({- where: { apiKeyId },- order: { createdAt: 'DESC' },- take: limit,- });- }-- async getRecentBySession(sessionId: string, limit = 10): Promise<AuditLog[]> {- return this.auditRepository.find({- where: { sessionId },- order: { createdAt: 'DESC' },- take: limit,- });- }-async cleanup(olderThanDays = 30): Promise<number> {const cutoffDate = new Date();cutoffDate.setDate(cutoffDate.getDate() - olderThanDays);