stuff
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Admin Panel / Deploy Admin Panel (push) Waiting to run
Deploy Admin Panel / Admin Panel Verification (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions

This commit is contained in:
Dmitry 2025-12-17 04:28:42 +03:00
parent 8e77f99c02
commit d869e5c17d
2 changed files with 16 additions and 10 deletions

View file

@ -202,10 +202,15 @@ export default function CardsPage() {
}
// Determine if this is an update or create
const isUpdate = selectedCard !== null && selectedCard.id !== undefined && selectedCard.id !== null && selectedCard.id !== ''
// Check if id exists and is not empty (handle both string and number)
const hasValidId = selectedCard?.id != null &&
selectedCard.id !== '' &&
selectedCard.id !== 0 &&
String(selectedCard.id).trim() !== ''
const isUpdate = selectedCard !== null && hasValidId
const cardData: GameCardDto = {
id: isUpdate ? selectedCard.id : null,
id: isUpdate ? String(selectedCard.id) : null,
packId: formData.packId.trim() || undefined,
original: formData.original.trim(),
translation: formData.translation.trim(),
@ -230,8 +235,12 @@ export default function CardsPage() {
}
const confirmDelete = () => {
if (cardToDelete && cardToDelete.id) {
deleteMutation.mutate(cardToDelete.id)
if (cardToDelete && cardToDelete.id != null && cardToDelete.id !== '') {
// Ensure id is a string
const cardId = String(cardToDelete.id)
deleteMutation.mutate(cardId)
} else {
toast.error('Invalid card ID')
}
}

View file

@ -87,9 +87,8 @@ class AdminCardsApiV2 {
for (final card in paginatedCards) {
final packs = await _db.packDao.getPacksForCard(card.id);
final packId = packs.isNotEmpty ? packs.first.id : null;
final cardId = int.tryParse(card.id) ?? 0;
cardsWithPacks.add({
'id': cardId,
'id': card.id,
'packId': packId,
'original': card.original,
'translation': card.translation,
@ -257,7 +256,6 @@ class AdminCardsApiV2 {
updatedAt: PgDateTime(DateTime.now()),
);
await _db.packDao.updateCard(updated);
final cardIdInt = int.tryParse(updated.id) ?? 0;
// Получить паки для карточки
final packs = await _db.packDao.getPacksForCard(updated.id);
final packId = packs.isNotEmpty ? packs.first.id : null;
@ -266,7 +264,7 @@ class AdminCardsApiV2 {
json.encode({
'success': true,
'card': {
'id': cardIdInt,
'id': updated.id,
'packId': packId,
'original': updated.original,
'translation': updated.translation,
@ -319,12 +317,11 @@ class AdminCardsApiV2 {
final packs = await _db.packDao.getPacksForCard(cardId);
final packId = packs.isNotEmpty ? packs.first.id : null;
final cardIdInt = int.tryParse(created.id) ?? 0;
return Response.ok(
json.encode({
'success': true,
'card': {
'id': cardIdInt,
'id': created.id,
'packId': packId,
'original': created.original,
'translation': created.translation,