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
🚀 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:
@@ -78,6 +78,13 @@ export const usersApi = {
|
||||
apiRequest<void>(`/users/${id}/active`, { method: 'PATCH', body: JSON.stringify(isActive) }),
|
||||
}
|
||||
|
||||
export const achievementsApi = {
|
||||
async list() {
|
||||
const payload = await apiRequest<PagedResult<AchievementDto> | AchievementDto[]>('/achievements')
|
||||
return extractItems(payload)
|
||||
},
|
||||
}
|
||||
|
||||
export const reviewsApi = {
|
||||
create: (lectureId: string | number, rating: 'Like' | 'Neutral' | 'Dislike', text: string) =>
|
||||
apiRequest<ReviewDto>('/reviews', {
|
||||
|
||||
@@ -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 : 'Не удалось загрузить данные профиля.'
|
||||
|
||||
Reference in New Issue
Block a user