mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-11 16:58:25 +03:00
split function calls in score-importing.ts
This commit is contained in:
@@ -20,7 +20,11 @@ import { CreateScoreID } from "./score-id";
|
||||
import db from "../../../../external/mongo/db";
|
||||
import { AppendLogCtx, KtLogger } from "../../../logger/logger";
|
||||
|
||||
import { ConverterFunctionReturns, ConverterFunction } from "../../import-types/common/types";
|
||||
import {
|
||||
ConverterFnReturnOrFailure,
|
||||
ConverterFunction,
|
||||
ConverterFnSuccessReturn,
|
||||
} from "../../import-types/common/types";
|
||||
import { DryScore } from "../common/types";
|
||||
import { OrphanScore } from "../orphans/orphans";
|
||||
|
||||
@@ -95,7 +99,7 @@ export async function ImportIterableDatapoint<D, C>(
|
||||
logger: KtLogger
|
||||
): Promise<ImportProcessingInfo | null> {
|
||||
// Converter Function Return
|
||||
let cfnReturn: ConverterFunctionReturns;
|
||||
let cfnReturn: ConverterFnReturnOrFailure;
|
||||
|
||||
try {
|
||||
cfnReturn = await ConverterFunction(data, context, importType, logger);
|
||||
@@ -103,11 +107,6 @@ export async function ImportIterableDatapoint<D, C>(
|
||||
cfnReturn = err;
|
||||
}
|
||||
|
||||
// null => processing didnt result in a score document, but not an error, no processing needed!
|
||||
if (cfnReturn === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// if this conversion failed, return it in the proper format
|
||||
if (cfnReturn instanceof ConverterFailure) {
|
||||
if (cfnReturn instanceof KTDataNotFoundFailure) {
|
||||
@@ -181,6 +180,14 @@ export async function ImportIterableDatapoint<D, C>(
|
||||
};
|
||||
}
|
||||
|
||||
return ProcessSuccessfulConverterReturn(userID, cfnReturn as ConverterFnSuccessReturn, logger);
|
||||
}
|
||||
|
||||
export async function ProcessSuccessfulConverterReturn(
|
||||
userID: integer,
|
||||
cfnReturn: ConverterFnSuccessReturn,
|
||||
logger: KtLogger
|
||||
): Promise<ImportProcessingInfo | null> {
|
||||
const result = await HydrateAndInsertScore(
|
||||
userID,
|
||||
cfnReturn.dryScore,
|
||||
|
||||
Reference in New Issue
Block a user