mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-09-04 09:13:24 +00:00
Includes the required banking configuration, SQL migration, and English locale entries.
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
|
|
import type { BankingAction, BankingOverview } from '@/types/banking'
|
|
import { nuiCall, type NuiResponse } from '@/utils/nui'
|
|
|
|
export const useBankingStore = defineStore('banking', {
|
|
state: () => ({
|
|
error: '',
|
|
isLoading: false,
|
|
overview: null as BankingOverview | null,
|
|
}),
|
|
actions: {
|
|
async load(): Promise<boolean> {
|
|
this.isLoading = true
|
|
const response = await nuiCall<BankingOverview>('banking:overview')
|
|
this.isLoading = false
|
|
if (response.success && response.data) {
|
|
this.overview = response.data
|
|
this.error = ''
|
|
return true
|
|
}
|
|
this.error = response.error ?? 'request_failed'
|
|
return false
|
|
},
|
|
async perform(
|
|
action: BankingAction,
|
|
amount: number,
|
|
target?: number,
|
|
): Promise<NuiResponse<BankingOverview>> {
|
|
this.isLoading = true
|
|
const response = await nuiCall<BankingOverview>(`banking:${action}`, {
|
|
amount,
|
|
...(target === undefined ? {} : { target }),
|
|
})
|
|
this.isLoading = false
|
|
if (response.success && response.data) {
|
|
this.overview = response.data
|
|
this.error = ''
|
|
} else {
|
|
this.error = response.error ?? 'request_failed'
|
|
}
|
|
return response
|
|
},
|
|
},
|
|
})
|