mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-28 00:11:08 -04:00
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import storage from 'localforage';
|
|
import { removeVuexORMFlags } from '@/utils/helpers';
|
|
|
|
class BankAccountService {
|
|
async getBankAccounts() {
|
|
const bankAccounts = await storage.getItem('bank_accounts');
|
|
|
|
return bankAccounts || [];
|
|
}
|
|
|
|
async getBankAccount(bankAccountId) {
|
|
const bankAccounts = await this.getBankAccounts();
|
|
return bankAccounts.find(bank_account => bank_account.id === bankAccountId);
|
|
}
|
|
|
|
async createBankAccount(bankAccount) {
|
|
return this.saveBankAccount(bankAccount);
|
|
}
|
|
|
|
async updateBankAccount(bankAccount) {
|
|
return this.saveBankAccount(bankAccount);
|
|
}
|
|
|
|
async saveBankAccount(bankAccount) {
|
|
const bankAccounts = await this.getBankAccounts();
|
|
const index = bankAccounts.findIndex(item => item.id === bankAccount.id);
|
|
removeVuexORMFlags(bankAccount);
|
|
if (index === -1) {
|
|
bankAccounts.push(bankAccount);
|
|
} else {
|
|
bankAccounts[index] = bankAccount;
|
|
}
|
|
return storage.setItem('bank_accounts', bankAccounts);
|
|
}
|
|
}
|
|
|
|
export default new BankAccountService();
|