feat: require brand description in create and update operations, add validation messages
Frontend CI / Frontend (push) Successful in 4m25s
Backend CI / Backend (push) Successful in 15m23s

This commit is contained in:
2026-06-09 14:09:05 +08:00
parent a6d203a300
commit 41f5623791
9 changed files with 148 additions and 25 deletions
@@ -17,7 +17,11 @@ import { useRoute, useRouter } from 'vue-router'
import AiWaitingModal from '@/components/AiWaitingModal.vue'
import { brandsApi } from '@/lib/api'
import { formatError } from '@/lib/errors'
import {
formatError,
getQuestionMaterializeErrorMessage,
isDuplicateQuestionSkipReason,
} from '@/lib/errors'
type CreateMode = 'combination' | 'ai' | 'batch'
@@ -155,6 +159,14 @@ const existingQuestionSet = computed(() => {
})
const selectedCandidates = computed(() => candidateRows.value.filter((item) => item.selected))
const selectedCandidatesAllExistInLibrary = computed(() => {
if (!selectedCandidates.value.length) {
return false
}
return selectedCandidates.value.every((item) =>
existingQuestionSet.value.has(normalizeQuestionKey(item.text)),
)
})
const candidateStats = computed(() => {
const total = candidateRows.value.length
const selected = selectedCandidates.value.length
@@ -321,11 +333,19 @@ const materializeMutation = useMutation({
})
return
}
pageNotice.value = t('brands.questions.errors.noValidQuestions')
pageNotice.value =
result.skipped_questions.length > 0 &&
result.skipped_questions.every((item) => isDuplicateQuestionSkipReason(item.reason))
? t('brands.questions.errors.duplicateExisting')
: t('brands.questions.errors.noValidQuestions')
},
onError: (error) => {
if (error instanceof ApiClientError && error.message === 'no_valid_questions') {
pageNotice.value = t('brands.questions.errors.noValidQuestions')
const materializeMessage = getQuestionMaterializeErrorMessage(error, {
duplicate: t('brands.questions.errors.duplicateExisting'),
noValid: t('brands.questions.errors.noValidQuestions'),
})
if (materializeMessage) {
pageNotice.value = materializeMessage
return
}
pageNotice.value = formatError(error)
@@ -786,6 +806,10 @@ async function saveCandidates(): Promise<void> {
pageNotice.value = t('brands.questions.errors.noSelection')
return
}
if (selectedCandidatesAllExistInLibrary.value) {
pageNotice.value = t('brands.questions.errors.duplicateExisting')
return
}
await materializeMutation.mutateAsync()
}