mirror of
				https://github.com/mokuappio/serverless-invoices.git
				synced 2025-10-31 09:51:08 -04:00 
			
		
		
		
	Init commit
This commit is contained in:
		
							
								
								
									
										35
									
								
								src/services/bank-account.service.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/services/bank-account.service.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| import storage from 'localforage'; | ||||
|  | ||||
| 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) { | ||||
|     const bankAccounts = await this.getBankAccounts(); | ||||
|  | ||||
|     delete bankAccount.$id; | ||||
|     delete bankAccount.$isNew; | ||||
|     delete bankAccount.$isDirty; | ||||
|  | ||||
|     bankAccounts.push(bankAccount); | ||||
|     await storage.setItem('bank_accounts', bankAccounts); | ||||
|     return bankAccount; | ||||
|   } | ||||
|  | ||||
|   async updateBankAccount(bankAccount) { | ||||
|     const bankAccounts = await this.getBankAccounts(); | ||||
|     const index = bankAccounts.findIndex(item => item.id === bankAccount.id); | ||||
|     bankAccounts[index] = bankAccount; | ||||
|     return storage.setItem('bank_accounts', bankAccounts); | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default new BankAccountService(); | ||||
		Reference in New Issue
	
	Block a user