Skip to content

Commit ae57ed7

Browse files
author
Brite
committed
fix(backend): stabilize websocket gateway CI integration
1 parent ca14ea1 commit ae57ed7

9 files changed

Lines changed: 21 additions & 33 deletions

File tree

apps/backend/src/gateways/escrow.gateway.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { EventsGateway } from './escrow.gateway';
1+
import { EscrowGateway } from './escrow.gateway';
22

33
describe('EventsGateway', () => {
4-
let gateway: EventsGateway;
4+
let gateway: EscrowGateway;
55
let jwtService: { verify: jest.Mock };
66

77
beforeEach(() => {
88
jwtService = {
99
verify: jest.fn().mockReturnValue({ sub: 'user-1' }),
1010
};
11-
gateway = new EventsGateway(jwtService as any);
11+
gateway = new EscrowGateway(jwtService as any);
1212
});
1313

1414
it('authenticates a socket and emits a connected event', async () => {

apps/backend/src/gateways/escrow.gateway.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ interface ClientAuthPayload {
3131
credentials: true,
3232
},
3333
})
34-
export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
34+
export class EscrowGateway implements OnGatewayConnection, OnGatewayDisconnect {
3535
@WebSocketServer()
3636
server!: Server;
3737

38-
private readonly logger = new Logger(EventsGateway.name);
38+
private readonly logger = new Logger(EscrowGateway.name);
3939
private readonly userSocketMap = new Map<string, Set<string>>();
4040
private readonly socketUserMap = new Map<string, string>();
4141
private readonly socketEscrowMap = new Map<string, Set<string>>();
@@ -44,9 +44,7 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
4444

4545
private extractToken(client: Socket): string | undefined {
4646
const authPayload = client.handshake.auth as ClientAuthPayload | undefined;
47-
const authorizationHeader = client.handshake.headers.authorization as
48-
| string
49-
| undefined;
47+
const authorizationHeader = client.handshake.headers.authorization;
5048

5149
if (authPayload?.token) {
5250
return authPayload.token;
@@ -254,7 +252,4 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
254252
timestamp: new Date().toISOString(),
255253
});
256254
}
257-
isHealthy(): boolean {
258-
return this.server !== undefined;
259-
}
260255
}

apps/backend/src/gateways/events.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Module } from '@nestjs/common';
22
import { ConfigModule, ConfigService } from '@nestjs/config';
33
import { JwtModule } from '@nestjs/jwt';
4-
import { EventsGateway } from './escrow.gateway';
4+
import { EscrowGateway } from './escrow.gateway';
55

66
@Module({
77
imports: [
@@ -17,7 +17,7 @@ import { EventsGateway } from './escrow.gateway';
1717
inject: [ConfigService],
1818
}),
1919
],
20-
providers: [EventsGateway],
21-
exports: [EventsGateway],
20+
providers: [EscrowGateway],
21+
exports: [EscrowGateway],
2222
})
2323
export class EventsModule {}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Module } from '@nestjs/common';
2-
import { JwtModule } from '@nestjs/jwt';
3-
import { EscrowGateway } from './escrow.gateway';
2+
import { EventsModule } from './events.module';
43

54
@Module({
6-
imports: [JwtModule],
7-
providers: [EscrowGateway],
8-
exports: [EscrowGateway],
5+
imports: [EventsModule],
6+
exports: [EventsModule],
97
})
108
export class GatewaysModule {}

apps/backend/src/modules/escrow/services/escrow-evidence.service.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ import {
1616
UploadEvidenceResponseDto,
1717
} from '../dto/upload-evidence.dto';
1818

19-
interface FileWithMetadata extends Express.Multer.File {
20-
buffer: Buffer;
21-
originalname: string;
22-
mimetype: string;
23-
size: number;
24-
}
25-
2619
@Injectable()
2720
export class EscrowEvidenceService {
2821
private readonly logger = new Logger(EscrowEvidenceService.name);
@@ -57,7 +50,7 @@ export class EscrowEvidenceService {
5750
*/
5851
async uploadEvidence(
5952
escrowId: string,
60-
files: FileWithMetadata[],
53+
files: Express.Multer.File[],
6154
userId: string,
6255
): Promise<UploadEvidenceResponseDto> {
6356
this.logger.log(
@@ -230,7 +223,7 @@ export class EscrowEvidenceService {
230223
* - Check MIME type against allowlist
231224
* - Check file size (max 10MB)
232225
*/
233-
private validateFile(file: FileWithMetadata): void {
226+
private validateFile(file: Express.Multer.File): void {
234227
// Validate MIME type
235228
if (!this.ALLOWED_MIME_TYPES.includes(file.mimetype)) {
236229
throw new BadRequestException(

apps/backend/src/modules/escrow/services/escrow.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { IpfsService } from '../../ipfs/ipfs.service';
4545
import { AllowedAsset } from '../../assets/entities/allowed-asset.entity';
4646
import { NotificationService } from '../../../notifications/notifications.service';
4747
import { NotificationEventType } from '../../../notifications/enums/notification-event.enum';
48-
import { EventsGateway } from '../../../gateways/escrow.gateway';
48+
import { EscrowGateway } from '../../../gateways/escrow.gateway';
4949

5050
@Injectable()
5151
export class EscrowService {
@@ -69,7 +69,7 @@ export class EscrowService {
6969
private readonly webhookService: WebhookService,
7070
private readonly ipfsService: IpfsService,
7171
private readonly notificationService: NotificationService,
72-
@Optional() private readonly eventsGateway?: EventsGateway,
72+
@Optional() private readonly eventsGateway?: EscrowGateway,
7373
) {}
7474

7575
async create(

apps/backend/src/modules/health/health.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export class HealthController {
5252
() => this.checkDatabase(),
5353
() => this.checkStellar(),
5454
() => this.checkWebSocket(),
55+
() => this.checkMemory(),
56+
() => this.checkDisk(),
5557
]);
5658
}
5759

apps/backend/src/notifications/notifications.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { WebhookSender } from './senders/webhook.sender';
1212
import { Repository, IsNull } from 'typeorm';
1313
import { EmailSender } from './senders/email.sender';
1414
import { PreferenceService } from './preference.service';
15-
import { EventsGateway } from '../gateways/escrow.gateway';
15+
import { EscrowGateway } from '../gateways/escrow.gateway';
1616

1717
@Injectable()
1818
export class NotificationService {
@@ -25,7 +25,7 @@ export class NotificationService {
2525
private preferenceService: PreferenceService,
2626
emailSender: EmailSender,
2727
webhookSender: WebhookSender,
28-
@Optional() private readonly eventsGateway?: EventsGateway,
28+
@Optional() private readonly eventsGateway?: EscrowGateway,
2929
) {
3030
this.senders = new Map([
3131
[NotificationChannel.EMAIL, emailSender],

apps/backend/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"noImplicitAny": false,
2121
"strictBindCallApply": false,
2222
"noFallthroughCasesInSwitch": false,
23-
"types": ["node"],
23+
"types": ["node", "multer"],
2424
"lib": ["es2021"]
2525
}
2626
}

0 commit comments

Comments
 (0)