mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2026-02-08 00:51:41 -05: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();
|
||||
47
src/services/client.service.js
Normal file
47
src/services/client.service.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import storage from 'localforage';
|
||||
|
||||
class ClientService {
|
||||
async getClients() {
|
||||
const clients = await storage.getItem('clients');
|
||||
|
||||
return clients || [];
|
||||
}
|
||||
|
||||
async getClient(clientId) {
|
||||
const clients = await this.getClients();
|
||||
return clients.find(client => client.id === clientId);
|
||||
}
|
||||
|
||||
async createClient(client) {
|
||||
const clients = await this.getClients();
|
||||
|
||||
delete client.$id;
|
||||
delete client.$isNew;
|
||||
delete client.$isDirty;
|
||||
|
||||
clients.push(client);
|
||||
await storage.setItem('clients', clients);
|
||||
return client;
|
||||
}
|
||||
|
||||
async updateClient(client) {
|
||||
const clients = await this.getClients();
|
||||
const index = clients.findIndex(item => item.id === client.id);
|
||||
|
||||
// TODO: Fix this mess
|
||||
if (index === -1) {
|
||||
return false;
|
||||
}
|
||||
clients[index] = client;
|
||||
return storage.setItem('clients', clients);
|
||||
}
|
||||
|
||||
async deleteClient(clientId) {
|
||||
const clients = await this.getClients();
|
||||
const index = clients.findIndex(item => item.id === clientId);
|
||||
clients.splice(index, 1);
|
||||
return storage.setItem('clients', clients);
|
||||
}
|
||||
}
|
||||
|
||||
export default new ClientService();
|
||||
48
src/services/invoice.service.js
Normal file
48
src/services/invoice.service.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import storage from 'localforage';
|
||||
|
||||
class InvoiceService {
|
||||
async getInvoices() {
|
||||
const invoices = await storage.getItem('invoices');
|
||||
return invoices || [];
|
||||
}
|
||||
|
||||
async getInvoice(invoiceId) {
|
||||
const invoices = await this.getInvoices();
|
||||
return invoices.find(invoice => invoice.id === invoiceId);
|
||||
}
|
||||
|
||||
async createInvoice(invoice) {
|
||||
// TODO: add invoice no, issued_at, due_at, late_fee, prefill company info, bank_info, currency, vat_rate
|
||||
const invoices = await this.getInvoices();
|
||||
|
||||
delete invoice.$id;
|
||||
delete invoice.$isNew;
|
||||
delete invoice.$isDirty;
|
||||
|
||||
invoices.push(invoice);
|
||||
await storage.setItem('invoices', invoices);
|
||||
}
|
||||
|
||||
async updateInvoice(invoice) {
|
||||
// TODO: validation
|
||||
const invoices = await this.getInvoices();
|
||||
const index = invoices.findIndex(item => item.id === invoice.id);
|
||||
invoices[index] = invoice;
|
||||
return storage.setItem('invoices', invoices);
|
||||
}
|
||||
|
||||
async deleteInvoice(invoiceId) {
|
||||
const invoices = await this.getInvoices();
|
||||
const index = invoices.findIndex(item => item.id === invoiceId);
|
||||
invoices.splice(index, 1);
|
||||
return storage.setItem('invoices', invoices);
|
||||
}
|
||||
|
||||
bookInvoice(invoice) {
|
||||
// TODO: validation
|
||||
invoice.status = 'booked';
|
||||
return this.updateInvoice(invoice);
|
||||
}
|
||||
}
|
||||
|
||||
export default new InvoiceService();
|
||||
24
src/services/notification.service.js
Normal file
24
src/services/notification.service.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
class NotificationService {
|
||||
success(text) {
|
||||
return Vue.notify({
|
||||
type: 'success',
|
||||
text,
|
||||
});
|
||||
}
|
||||
|
||||
error(text, duration = 5000) {
|
||||
return Vue.notify({
|
||||
type: 'error',
|
||||
text,
|
||||
duration,
|
||||
});
|
||||
}
|
||||
|
||||
stickyError(text, title) {
|
||||
return this.error(text, title, -1);
|
||||
}
|
||||
}
|
||||
|
||||
export default new NotificationService();
|
||||
36
src/services/team.service.js
Normal file
36
src/services/team.service.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import storage from 'localforage';
|
||||
|
||||
class TeamService {
|
||||
async getTeam() {
|
||||
let team = await storage.getItem('team');
|
||||
if (!team) {
|
||||
team = {
|
||||
company_name: null,
|
||||
company_address: null,
|
||||
company_postal_code: null,
|
||||
company_country: null,
|
||||
company_county: null,
|
||||
company_city: null,
|
||||
company_reg_no: null,
|
||||
company_vat_no: null,
|
||||
website: null,
|
||||
contact_email: null,
|
||||
contact_phone: null,
|
||||
vat_rate: null,
|
||||
invoice_late_fee: null,
|
||||
invoice_due_days: null,
|
||||
updated_at: null,
|
||||
created_at: null,
|
||||
logo_url: null,
|
||||
};
|
||||
}
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
async updateTeam(team) {
|
||||
return storage.setItem('team', team);
|
||||
}
|
||||
}
|
||||
|
||||
export default new TeamService();
|
||||
Reference in New Issue
Block a user