feat: добавил каталог достижений и автоначисление
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 10s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m53s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 28s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 7s

Реализовал автосоздание и обновление каталога достижений на бэке и синхронизацию на фронте.
This commit is contained in:
2026-05-12 23:21:39 +03:00
parent dbba2be277
commit feff77b232
12 changed files with 446 additions and 12 deletions
+18 -2
View File
@@ -1,6 +1,6 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { usersApi } from '@/api'
import { achievementsApi, usersApi } from '@/api'
import { mapApiAchievement, mapApiCoinTransaction } from '@/api/mappers'
import type { Achievement, CoinTransaction, Notification } from '@/types'
import { useAuthStore } from './auth'
@@ -25,6 +25,7 @@ export const useUserStore = defineStore('user', () => {
usersApi.achievements(id),
usersApi.transactions(id),
])
const achievementCatalog = await achievementsApi.list()
if (auth.user) {
auth.setUser({
@@ -37,7 +38,22 @@ export const useUserStore = defineStore('user', () => {
achievements: Array.from({ length: stats.achievementsCount }, (_, index) => String(index + 1)),
})
}
achievements.value = achievementPayload.map(mapApiAchievement)
const unlocked = new Map(achievementPayload.map(item => {
const achievement = mapApiAchievement(item)
return [achievement.id, achievement]
}))
const catalogIds = new Set(achievementCatalog.map(item => String(item.id)))
const lockedAndUnlocked = achievementCatalog.map(item => {
const achievement = mapApiAchievement(item)
return unlocked.get(achievement.id) ?? achievement
})
const unlockedOutsideCatalog = achievementPayload
.map(mapApiAchievement)
.filter(item => !catalogIds.has(item.id))
achievements.value = [...lockedAndUnlocked, ...unlockedOutsideCatalog].sort(
(a, b) => Number(a.id) - Number(b.id),
)
coinHistory.value = transactions.map(mapApiCoinTransaction)
} catch (err) {
error.value = err instanceof Error ? err.message : 'Не удалось загрузить данные профиля.'