mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 09:14:08 +00:00
Create the complete TypeScript foundation for the Vue 3 migration in a parallel scripts-v2/ directory. 72 files, 5430 lines, zero any types, strict mode. - types/ (21 files): Domain interfaces for all 17 entities derived from actual Laravel models and API resources. Enums for all statuses. Generic API response wrappers. - api/ (29 files): Typed axios client with interceptors, endpoint constants from routes/api.php, 25 typed service classes covering every API endpoint. - composables/ (14 files): Vue 3 composition functions for auth, notifications, dialogs, modals, pagination, filters, currency, dates, theme, sidebar, company context, and permissions. - utils/ (5 files): Pure typed utilities for money formatting, date formatting (date-fns), localStorage, and error handling. - config/ (3 files): Typed ability constants, app constants. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
import { client } from '../client'
|
|
import { API } from '../endpoints'
|
|
import type { User } from '../../types/domain/user'
|
|
import type { CompanyInvitation } from '../../types/domain/company'
|
|
import type { ApiResponse, PaginatedResponse, ListParams } from '../../types/api'
|
|
|
|
export interface MemberListParams extends ListParams {
|
|
display_name?: string
|
|
}
|
|
|
|
export interface MemberListResponse {
|
|
data: User[]
|
|
meta: {
|
|
current_page: number
|
|
last_page: number
|
|
per_page: number
|
|
total: number
|
|
}
|
|
}
|
|
|
|
export interface UpdateMemberPayload {
|
|
name?: string
|
|
email?: string
|
|
phone?: string | null
|
|
role?: string | null
|
|
companies?: Array<{
|
|
id: number
|
|
role?: string
|
|
}>
|
|
}
|
|
|
|
export interface InviteMemberPayload {
|
|
email: string
|
|
role?: string
|
|
}
|
|
|
|
export interface DeleteMembersPayload {
|
|
users: number[]
|
|
}
|
|
|
|
export interface PendingInvitationsResponse {
|
|
invitations: CompanyInvitation[]
|
|
}
|
|
|
|
export const memberService = {
|
|
async list(params?: MemberListParams): Promise<MemberListResponse> {
|
|
const { data } = await client.get(API.MEMBERS, { params })
|
|
return data
|
|
},
|
|
|
|
async get(id: number): Promise<ApiResponse<User>> {
|
|
const { data } = await client.get(`${API.MEMBERS}/${id}`)
|
|
return data
|
|
},
|
|
|
|
async create(payload: UpdateMemberPayload): Promise<ApiResponse<User>> {
|
|
const { data } = await client.post(API.MEMBERS, payload)
|
|
return data
|
|
},
|
|
|
|
async update(id: number, payload: UpdateMemberPayload): Promise<ApiResponse<User>> {
|
|
const { data } = await client.put(`${API.MEMBERS}/${id}`, payload)
|
|
return data
|
|
},
|
|
|
|
async delete(payload: DeleteMembersPayload): Promise<{ success: boolean }> {
|
|
const { data } = await client.post(API.MEMBERS_DELETE, payload)
|
|
return data
|
|
},
|
|
|
|
// Company Invitations (send invitations)
|
|
async fetchPendingInvitations(): Promise<PendingInvitationsResponse> {
|
|
const { data } = await client.get(API.COMPANY_INVITATIONS)
|
|
return data
|
|
},
|
|
|
|
async invite(payload: InviteMemberPayload): Promise<ApiResponse<CompanyInvitation>> {
|
|
const { data } = await client.post(API.COMPANY_INVITATIONS, payload)
|
|
return data
|
|
},
|
|
|
|
async cancelInvitation(id: number): Promise<{ success: boolean }> {
|
|
const { data } = await client.delete(`${API.COMPANY_INVITATIONS}/${id}`)
|
|
return data
|
|
},
|
|
|
|
// User-scoped invitation responses
|
|
async fetchUserPendingInvitations(): Promise<PendingInvitationsResponse> {
|
|
const { data } = await client.get(API.INVITATIONS_PENDING)
|
|
return data
|
|
},
|
|
|
|
async acceptInvitation(token: string): Promise<{ success: boolean }> {
|
|
const { data } = await client.post(`${API.INVITATIONS}/${token}/accept`)
|
|
return data
|
|
},
|
|
|
|
async declineInvitation(token: string): Promise<{ success: boolean }> {
|
|
const { data } = await client.post(`${API.INVITATIONS}/${token}/decline`)
|
|
return data
|
|
},
|
|
}
|