7
0
forked from yvv/decision
Files
Yvv 3b339b643c
ci/woodpecker/push/woodpecker Pipeline failed
Mandats : refonte wizard nomination-first + types statutory/functional
- Réordonnancement étapes : nomination → infos → résumé (au lieu de infos → nomination → toolbox → résumé)
- Cas nomination renommé : 'election' → 'collective' ; auto-désignation scindée en mode période/réunion
- Types mandat ajoutés : statutory, functional (labels + filtres index)
- Légères corrections texte modalities (ortho, reformulation)
- Fix TS : assertions non-null sur statusGroupMap et paramValues

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 20:33:16 +02:00

110 lines
2.6 KiB
TypeScript

export interface GroupMember {
id: string
display_name: string
identity_id: string | null
added_at: string
}
export interface Group {
id: string
name: string
description: string | null
organization_id: string | null
created_at: string
members: GroupMember[]
}
export interface GroupSummary {
id: string
name: string
description: string | null
organization_id: string | null
member_count: number
}
export interface GroupCreate {
name: string
description?: string | null
}
export interface GroupMemberCreate {
display_name: string
identity_id?: string | null
}
export const useGroupsStore = defineStore('groups', () => {
const { $api } = useApi()
const list = ref<GroupSummary[]>([])
const loading = ref(false)
const error = ref<string | null>(null)
async function fetchAll() {
loading.value = true
error.value = null
try {
list.value = await $api<GroupSummary[]>('/groups/')
} catch (e: any) {
error.value = e?.message ?? 'Erreur chargement groupes'
} finally {
loading.value = false
}
}
async function getGroup(id: string): Promise<Group | null> {
try {
return await $api<Group>(`/groups/${id}`)
} catch {
return null
}
}
async function create(payload: GroupCreate): Promise<Group | null> {
try {
const group = await $api<Group>('/groups/', { method: 'POST', body: payload })
await fetchAll()
return group
} catch (e: any) {
error.value = e?.message ?? 'Erreur création groupe'
return null
}
}
async function remove(id: string): Promise<boolean> {
try {
await $api(`/groups/${id}`, { method: 'DELETE' })
list.value = list.value.filter(g => g.id !== id)
return true
} catch {
return false
}
}
async function addMember(groupId: string, payload: GroupMemberCreate): Promise<GroupMember | null> {
try {
const member = await $api<GroupMember>(`/groups/${groupId}/members`, {
method: 'POST',
body: payload,
})
const g = list.value.find(g => g.id === groupId)
if (g) g.member_count++
return member
} catch {
return null
}
}
async function removeMember(groupId: string, memberId: string): Promise<boolean> {
try {
await $api(`/groups/${groupId}/members/${memberId}`, { method: 'DELETE' })
const g = list.value.find(g => g.id === groupId)
if (g) g.member_count--
return true
} catch {
return false
}
}
return { list, loading, error, fetchAll, getGroup, create, remove, addMember, removeMember }
})