agregar endpoint /epicdevelopment/ + store de epicas y HUs por proyecto
This commit is contained in:
+45
-8
@@ -1,7 +1,9 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { kappa } from '@/services/kappa-api'
|
||||
import type { KappaUserStory, KappaLogbookEntry, KappaPlanningEntry } from '@/types/kappa'
|
||||
import { tauriDb } from '@/services/tauri-db'
|
||||
import { stripHtml } from '@/services/clean-html'
|
||||
import type { KappaUserStory, KappaLogbookEntry, KappaPlanningEntry, KappaEpicDevelopment } from '@/types/kappa'
|
||||
|
||||
export const useWorkItemsStore = defineStore('workitems', () => {
|
||||
const creating = ref(false)
|
||||
@@ -9,13 +11,15 @@ export const useWorkItemsStore = defineStore('workitems', () => {
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
const userStories = ref<KappaUserStory[]>([])
|
||||
const epics = ref<KappaEpicDevelopment[]>([])
|
||||
const logbooks = ref<KappaLogbookEntry[]>([])
|
||||
const plannings = ref<KappaPlanningEntry[]>([])
|
||||
|
||||
const totalHUs = computed(() => userStories.value.length)
|
||||
const totalEpics = computed(() => epics.value.length)
|
||||
const inProgressHUs = computed(() =>
|
||||
userStories.value.filter(us =>
|
||||
us.status && ['in_progress', 'doing', 'wip', 'active'].includes(us.status.toLowerCase())
|
||||
userStories.value.filter(hu =>
|
||||
hu.status && ['in_progress', 'doing', 'wip', 'active', 'in progress'].includes(hu.status.toLowerCase())
|
||||
).length
|
||||
)
|
||||
const totalSessions = computed(() => logbooks.value.length)
|
||||
@@ -38,18 +42,34 @@ export const useWorkItemsStore = defineStore('workitems', () => {
|
||||
async function fetchWorkItems(initiativeId?: number) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
const id = initiativeId || Number(localStorage.getItem('kappa_last_project'))
|
||||
if (!id) {
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const [stories, logs, plans] = await Promise.all([
|
||||
kappa.getUserStories(initiativeId),
|
||||
kappa.getLogbooks(initiativeId),
|
||||
kappa.getPlannings(initiativeId),
|
||||
const [stories, logs, plans, epicData] = await Promise.all([
|
||||
kappa.getUserStories(id).catch(() => [] as KappaUserStory[]),
|
||||
kappa.getLogbooks(id).catch(() => [] as KappaLogbookEntry[]),
|
||||
kappa.getPlannings(id).catch(() => [] as KappaPlanningEntry[]),
|
||||
kappa.getAllEpicDevelopment(id).catch(() => [] as KappaEpicDevelopment[]),
|
||||
])
|
||||
|
||||
const storiesData = stories as KappaUserStory[] | { results?: KappaUserStory[] }
|
||||
const logsData = logs as KappaLogbookEntry[] | { results?: KappaLogbookEntry[] }
|
||||
const plansData = plans as KappaPlanningEntry[] | { results?: KappaPlanningEntry[] }
|
||||
userStories.value = Array.isArray(storiesData) ? storiesData : (storiesData.results ?? [])
|
||||
logbooks.value = Array.isArray(logsData) ? logsData : (logsData.results ?? [])
|
||||
plannings.value = Array.isArray(plansData) ? plansData : (plansData.results ?? [])
|
||||
|
||||
epics.value = epicData.map(epic => ({
|
||||
...epic,
|
||||
description: stripHtml(epic.description || ''),
|
||||
}))
|
||||
|
||||
syncHUsToTurso(id, userStories.value)
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
@@ -57,17 +77,34 @@ export const useWorkItemsStore = defineStore('workitems', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function syncHUsToTurso(projectId: number, hus: KappaUserStory[]) {
|
||||
for (const hu of hus) {
|
||||
await tauriDb.saveWorkItem({
|
||||
id: hu.id ?? 0,
|
||||
project_id: projectId,
|
||||
code: hu.code ?? null,
|
||||
title: hu.title,
|
||||
description: stripHtml(hu.description || ''),
|
||||
type: 'hu',
|
||||
status: hu.status || 'backlog',
|
||||
priority: hu.priority || 'medium',
|
||||
}).catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
creating,
|
||||
loading,
|
||||
error,
|
||||
userStories,
|
||||
epics,
|
||||
logbooks,
|
||||
plannings,
|
||||
totalHUs,
|
||||
totalEpics,
|
||||
inProgressHUs,
|
||||
totalSessions,
|
||||
createUserStory,
|
||||
fetchWorkItems,
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user