- Migration 009: coluna `type` em recurring_expenses + tabela recurring_late - API Go: tipo income/expense em CRUD; endpoints POST /confirm e /late - Dashboard: campo pending_income_recurrings na resposta - Frontend: RecurringView com seções RECEITAS e DESPESAS separadas - HomeView: widget de confirmação (dia 1-5) e badge SALÁRIO PENDENTE (pós dia 5) - Testes unitários: 4 novos casos (income covered, late, confirm, reject expense) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
108 lines
2.8 KiB
TypeScript
108 lines
2.8 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import { api } from '@/services/api'
|
|
|
|
export interface RecurringExpense {
|
|
id: number
|
|
name: string
|
|
expected_amount: number
|
|
day_of_month: number
|
|
category_id: number | null
|
|
type: 'income' | 'expense'
|
|
active: boolean
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface RecurringStatus extends RecurringExpense {
|
|
covered: boolean
|
|
ignored: boolean
|
|
late: boolean
|
|
reason?: string
|
|
}
|
|
|
|
export const useRecurringStore = defineStore('recurring', () => {
|
|
const items = ref<RecurringExpense[]>([])
|
|
const monthlyStatus = ref<RecurringStatus[]>([])
|
|
const loading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
|
|
async function fetchAll() {
|
|
loading.value = true
|
|
error.value = null
|
|
try {
|
|
items.value = await api.get<RecurringExpense[]>('/recurring')
|
|
} catch (e: any) {
|
|
error.value = e.message
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function fetchMonthlyStatus(month: string) {
|
|
try {
|
|
monthlyStatus.value = await api.get<RecurringStatus[]>(`/recurring/status?month=${month}`)
|
|
} catch {
|
|
monthlyStatus.value = []
|
|
}
|
|
}
|
|
|
|
async function create(input: Omit<RecurringExpense, 'id' | 'active' | 'created_at' | 'updated_at'>) {
|
|
const item = await api.post<RecurringExpense>('/recurring', input)
|
|
items.value.push(item)
|
|
return item
|
|
}
|
|
|
|
async function update(id: number, input: Omit<RecurringExpense, 'id' | 'active' | 'created_at' | 'updated_at'>) {
|
|
const item = await api.put<RecurringExpense>(`/recurring/${id}`, input)
|
|
const idx = items.value.findIndex((x) => x.id === id)
|
|
if (idx !== -1) items.value[idx] = item
|
|
return item
|
|
}
|
|
|
|
async function remove(id: number) {
|
|
await api.delete(`/recurring/${id}`)
|
|
items.value = items.value.filter((x) => x.id !== id)
|
|
}
|
|
|
|
async function ignore(id: number, month: string, reason: string) {
|
|
await api.post(`/recurring/${id}/ignore`, { month, reason })
|
|
await fetchMonthlyStatus(month)
|
|
}
|
|
|
|
async function unignore(id: number, month: string) {
|
|
await api.delete(`/recurring/${id}/ignore?month=${month}`)
|
|
await fetchMonthlyStatus(month)
|
|
}
|
|
|
|
async function confirmIncome(id: number, month: string) {
|
|
await api.post(`/recurring/${id}/confirm`, { month })
|
|
await fetchMonthlyStatus(month)
|
|
}
|
|
|
|
async function markLate(id: number, month: string) {
|
|
await api.post(`/recurring/${id}/late`, { month })
|
|
await fetchMonthlyStatus(month)
|
|
}
|
|
|
|
const pendingCount = (month: string) =>
|
|
monthlyStatus.value.filter((s) => !s.covered).length
|
|
|
|
return {
|
|
items,
|
|
monthlyStatus,
|
|
loading,
|
|
error,
|
|
fetchAll,
|
|
fetchMonthlyStatus,
|
|
create,
|
|
update,
|
|
remove,
|
|
ignore,
|
|
unignore,
|
|
confirmIncome,
|
|
markLate,
|
|
pendingCount,
|
|
}
|
|
})
|