-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathingest.controller.ts
More file actions
40 lines (32 loc) · 977 Bytes
/
ingest.controller.ts
File metadata and controls
40 lines (32 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Controller, Post, Body, Get } from '@nestjs/common';
import { IngestService } from './ingest.service';
export interface IngestResponse {
id: string;
t_ms: number;
}
export interface HealthResponse {
status: string;
timestamp: string;
}
@Controller()
export class IngestController {
constructor(private readonly ingestService: IngestService) {}
@Post('ingest')
async ingest(@Body() payload: Record<string, any>): Promise<IngestResponse> {
const startTime = process.hrtime.bigint();
const id = await this.ingestService.process(payload);
const endTime = process.hrtime.bigint();
const elapsedMs = Number(endTime - startTime) / 1000000; // Convert nanoseconds to milliseconds
return {
id,
t_ms: Math.round(elapsedMs * 100) / 100 // Round to 2 decimal places
};
}
@Get('health')
getHealth(): HealthResponse {
return {
status: 'ok',
timestamp: new Date().toISOString()
};
}
}