feat: half-way bulk upload support.
This commit is contained in:
@@ -1,23 +1,37 @@
|
||||
import { SingleMetadata } from "../contract";
|
||||
import { LogEntry, SingleMetadata } from "../contract";
|
||||
import { HttpError } from "../http-error";
|
||||
import { db } from "./init";
|
||||
import { zip } from "lodash-es";
|
||||
|
||||
declare global {
|
||||
interface BigInt {
|
||||
/** Convert to BigInt to string form in JSON.stringify */
|
||||
toJSON: () => string;
|
||||
}
|
||||
}
|
||||
BigInt.prototype.toJSON = function () {
|
||||
return this.toString();
|
||||
};
|
||||
|
||||
export async function postLog(
|
||||
gameName: string,
|
||||
version: string,
|
||||
saveGuid: string,
|
||||
sessionGuid: string,
|
||||
message: string,
|
||||
category: string | undefined,
|
||||
metadata: SingleMetadata[]
|
||||
entries: LogEntry[]
|
||||
// message: string,
|
||||
// category: string | undefined,
|
||||
// metadata: SingleMetadata[]
|
||||
) {
|
||||
if (
|
||||
gameName === "" ||
|
||||
sessionGuid === "" ||
|
||||
message === "" ||
|
||||
entries.some((entry) => entry.message === "") ||
|
||||
version === ""
|
||||
) {
|
||||
const errorMessage = `One of the necessary fields was missing: gameName=${gameName}, sessionGuid=${sessionGuid}, message=${message}, version=${version}`;
|
||||
const errorMessage = `One of the necessary fields was missing: gameName=${gameName}, sessionGuid=${sessionGuid}, messages=${entries
|
||||
.map((e) => e.message)
|
||||
.join(", ")}, version=${version}`;
|
||||
throw new HttpError(422, errorMessage);
|
||||
} else {
|
||||
await db.transaction().execute(async (trx) => {
|
||||
@@ -35,26 +49,36 @@ export async function postLog(
|
||||
// add the main log line
|
||||
const insertResult = await trx
|
||||
.insertInto("log_entries")
|
||||
.values({
|
||||
session_info_id: sessionGuid,
|
||||
message: message,
|
||||
timestamp: new Date(),
|
||||
category,
|
||||
})
|
||||
.executeTakeFirstOrThrow();
|
||||
// add all the metadata
|
||||
if (metadata.length > 0) {
|
||||
await trx
|
||||
.insertInto("log_metadata")
|
||||
.values(
|
||||
metadata.map(({ key, value }) => ({
|
||||
log_entry_id: Number(insertResult.insertId),
|
||||
key,
|
||||
value,
|
||||
}))
|
||||
)
|
||||
.execute();
|
||||
.values(
|
||||
entries.map((entry) => ({
|
||||
session_info_id: sessionGuid,
|
||||
message: entry.message,
|
||||
timestamp: new Date(),
|
||||
category: entry.category,
|
||||
}))
|
||||
)
|
||||
.returning("id")
|
||||
.execute();
|
||||
console.log("insertResulttt:", JSON.stringify(insertResult, null, 2));
|
||||
for (const r of insertResult) {
|
||||
console.log("insertResult", r.id);
|
||||
}
|
||||
// console.log("insertResult.insertId", (insertResult as any).insertId);
|
||||
// console.log("keys:", Object.keys(insertResult));
|
||||
throw new Error("aaa");
|
||||
// add all the metadata
|
||||
// if (metadata.length > 0) {
|
||||
// await trx
|
||||
// .insertInto("log_metadata")
|
||||
// .values(
|
||||
// metadata.map(({ key, value }) => ({
|
||||
// log_entry_id: Number(insertResult.insertId),
|
||||
// key,
|
||||
// value,
|
||||
// }))
|
||||
// )
|
||||
// .execute();
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user