Spaces:
Sleeping

File size: 1,063 Bytes
4e83772
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
export interface ResponseJSON<T> {
	data: T[];
	total?: number;
	[key: string]: any;
}
export interface LogResult {
	event_id: string;
	deployment_id: string;
	log: string;
	metedata: null;
	project_id: string;
	report_time: string;
	info: "INFO" | "SUCCESS" | "WARN" | "ERROR";
}
export interface toLogResponseDTO {
	log: {
		event_id: string;
		level: "INFO" | "SUCCESS" | "WARN" | "ERROR";
		deployment_id: string;
		project_id: string;
		message: string;
		timestamp: Date | string;
	};
}
interface toLogsResponseDTO {
	logs: toLogResponseDTO["log"][];
	total: number;
}
export class LogMapper {
	static toLogResponse(log: LogResult): toLogResponseDTO {
		return {
			log: {
				deployment_id: log.deployment_id,
				project_id: log.project_id,
				event_id: log.event_id,
				level: log.info,
				message: log.log,
				timestamp: log.report_time,
			},
		};
	}
	static toLogsResponse(logs: ResponseJSON<unknown>["data"], total: number): toLogsResponseDTO {
		return {
			logs: logs.map((log) => this.toLogResponse(log as LogResult).log),
			total,
		};
	}
}