Fix recording sequelize unique constraint error (#882)

* display error when create assessment

* setup nil value for recording target as default

* refactor
This commit is contained in:
an-lee
2024-07-24 19:18:24 +08:00
committed by GitHub
parent ab0a173a60
commit d42814eb0c
2 changed files with 35 additions and 24 deletions

View File

@@ -15,6 +15,7 @@ import {
import dayjs from "dayjs";
import { t } from "i18next";
import log from "@main/logger";
import { NIL as NIL_UUID } from "uuid";
const logger = log.scope("db/handlers/recordings-handler");
@@ -120,8 +121,13 @@ class RecordingsHandler {
};
}
) {
const { targetId, targetType, referenceId, referenceText, duration } =
options;
const {
targetId = NIL_UUID,
targetType = "None",
referenceId,
referenceText,
duration,
} = options;
const recording = await Recording.createFromBlob(options.blob, {
targetId,
targetType,

View File

@@ -64,28 +64,32 @@ export const PronunciationAssessmentForm = () => {
}
const { language, referenceText } = data;
const recording = await createRecording(data);
setSubmitting(true);
toast.promise(
createAssessment({
language,
reference: referenceText,
recording,
})
.then(() => {
navigate("/pronunciation_assessments");
try {
setSubmitting(true);
const recording = await createRecording(data);
toast.promise(
createAssessment({
language,
reference: referenceText,
recording,
})
.catch(() => {
EnjoyApp.recordings.destroy(recording.id);
})
.finally(() => setSubmitting(false)),
{
loading: t("assessing"),
success: t("assessedSuccessfully"),
error: (err) => err.message,
}
);
.then(() => {
navigate("/pronunciation_assessments");
})
.catch(() => {
EnjoyApp.recordings.destroy(recording.id);
})
.finally(() => setSubmitting(false)),
{
loading: t("assessing"),
success: t("assessedSuccessfully"),
error: (err) => err.message,
}
);
} catch (err) {
toast.error(err.message);
setSubmitting(false);
}
};
const createRecording = async (
@@ -98,7 +102,8 @@ export const PronunciationAssessmentForm = () => {
} else {
arrayBuffer = await new Blob([file[0]]).arrayBuffer();
}
return await EnjoyApp.recordings.create({
return EnjoyApp.recordings.create({
language,
referenceText,
blob: {