fix array to object

This commit is contained in:
Bright 2024-11-22 11:03:46 +07:00
parent 736030da39
commit e669971e8a

View file

@ -271,42 +271,40 @@ export class ReportController extends Controller {
output: string; output: string;
sequence: string[]; sequence: string[];
} }
const content = queryData.hits.hits.map((x) => {
const source = x._source as DocumentSource; const x = queryData.hits.hits[0]
return { const source = x._source as DocumentSource;
id: x._id, const content = {
startTimeStamp: source.startTimeStamp, id: x._id,
userName: source.userName, startTimeStamp: source.startTimeStamp,
host: source.host, userName: source.userName,
endpoint: source.endpoint, host: source.host,
method: source.method, endpoint: source.endpoint,
responseCode: source.responseCode, method: source.method,
logType: source.logType, responseCode: source.responseCode,
responseDescription: source.responseDescription, logType: source.logType,
input: source.input, responseDescription: source.responseDescription,
output: JSON.parse(/*JSON.stringify(*/source.output/*, null, 2)*/), input: JSON.parse(source.input),
sequence: source.sequence ? source.sequence : [{ output: JSON.parse(source.output),
action:"-", sequence: source.sequence ? source.sequence : [{
status:"-", action:"-",
description:"-", status:"-",
request:{ description:"-",
method:"-", request:{
url:"-", method:"-",
response:"-", url:"-",
}, response:"-",
}], },
}; }],
}); };
const contentString = JSON.parse(JSON.stringify(content, null, 2)); const contentString = JSON.parse(JSON.stringify(content, null, 2));
downloadFile(200, contentString, { downloadFile(200, contentString, {
"Content-Type": "application/octet-stream", "Content-Type": "application/octet-stream",
"Content-Disposition": `attachment; filename="log_${id}.txt"`, "Content-Disposition": `attachment; filename="log_${id}.txt"`,
"Content-Length": contentString.length.toString(),
}); });
} }
catch (error:any) { catch (error:any) {
console.error("An error occurred:", error);
throw new Error("Failed to process logs: " + error.message); throw new Error("Failed to process logs: " + error.message);
} }
} }