feat: licenses administration basic authentication.

feat: accounts slug.
feat: duplicate accounts_balance table and merge balance with accounts table.
feat: refactoring customers and vendors.
feat: system user soft deleting.
feat: preventing build tenant database without any subscription.
feat: remove 'password' property from 'req.user' object.
feat: refactoring JournalPoster class.
feat: delete duplicated directories and files.
This commit is contained in:
Ahmed Bouhuolia
2020-09-09 21:30:19 +02:00
parent 98bba3d3a0
commit ad00f140d1
77 changed files with 2431 additions and 1848 deletions

View File

@@ -0,0 +1,55 @@
import TenantRepository from '@/repositories/TenantRepository';
export default class AccountRepository extends TenantRepository {
models: any;
repositories: any;
cache: any;
/**
* Constructor method.
* @param {number} tenantId - The given tenant id.
*/
constructor(
tenantId: number,
) {
super(tenantId);
this.models = this.tenancy.models(tenantId);
this.cache = this.tenancy.cache(tenantId);
}
/**
* Retrieve accounts dependency graph.
* @returns {}
*/
async getDependencyGraph() {
const { Account } = this.models;
const accounts = await this.allAccounts();
return this.cache.get('accounts.depGraph', async () => {
return Account.toDependencyGraph(accounts);
});
}
/**
* Retrieve all accounts on the storage.
* @return {}
*/
async allAccounts() {
const { Account } = this.models;
return this.cache.get('accounts', async () => {
return Account.query();
});
}
/**
* Retrieve account of the given account slug.
* @param {string} slug
*/
async getBySlug(slug: string) {
const { Account } = this.models;
return this.cache.get(`accounts.slug.${slug}`, () => {
return Account.query().findOne('slug', slug);
});
}
}

View File

@@ -0,0 +1,30 @@
import TenantRepository from '@/repositories/TenantRepository';
export default class AccountTypeRepository extends TenantRepository {
cache: any;
models: any;
/**
* Constructor method.
* @param {number} tenantId - The given tenant id.
*/
constructor(
tenantId: number,
) {
super(tenantId);
this.models = this.tenancy.models(tenantId);
this.cache = this.tenancy.cache(tenantId);
}
/**
* Retrieve account type meta.
* @param {number} accountTypeId
*/
getTypeMeta(accountTypeId: number) {
const { AccountType } = this.models;
return this.cache.get(`accountType.${accountTypeId}`, () => {
return AccountType.query().findById(accountTypeId);
});
}
}

View File

@@ -0,0 +1,71 @@
import TenantRepository from "./TenantRepository";
export default class CustomerRepository extends TenantRepository {
models: any;
cache: any;
/**
* Constructor method.
* @param {number} tenantId
*/
constructor(tenantId: number) {
super(tenantId);
this.models = this.tenancy.models(tenantId);
this.cache = this.tenancy.cache(tenantId);
}
/**
* Retrieve customer details of the given id.
* @param {number} customerId -
*/
getById(customerId: number) {
const { Contact } = this.models;
return this.cache.get(`customers.id.${customerId}`, () => {
return Contact.query().modifier('customer').findById(customerId);
});
}
/**
* Detarmines the given customer exists.
* @param {number} customerId
* @returns {boolean}
*/
isExists(customerId: number) {
return !!this.getById(customerId);
}
/**
* Retrieve the sales invoices that assocaited to the given customer.
* @param {number} customerId
*/
getSalesInvoices(customerId: number) {
const { SaleInvoice } = this.models;
return this.cache.get(`customers.invoices.${customerId}`, () => {
return SaleInvoice.query().where('customer_id', customerId);
});
}
/**
* Retrieve customers details of the given ids.
* @param {number[]} customersIds - Customers ids.
* @return {IContact[]}
*/
customers(customersIds: number[]) {
const { Contact } = this.models;
return Contact.query().modifier('customer').whereIn('id', customersIds);
}
/**
* Retrieve customers of the given ids with associated sales invoices.
* @param {number[]} customersIds - Customers ids.
*/
customersWithSalesInvoices(customersIds: number[]) {
const { Contact } = this.models;
return Contact.query().modify('customer')
.whereIn('id', customersIds)
.withGraphFetched('salesInvoices');
}
}

View File

@@ -0,0 +1,16 @@
import { Container } from 'typedi';
import TenancyService from '@/services/Tenancy/TenancyService';
export default class TenantRepository {
tenantId: number;
tenancy: TenancyService;
/**
* Constructor method.
* @param {number} tenantId
*/
constructor(tenantId: number) {
this.tenantId = tenantId;
this.tenancy = Container.get(TenancyService);
}
}

View File

@@ -0,0 +1,50 @@
import TenantRepository from "./TenantRepository";
export default class VendorRepository extends TenantRepository {
models: any;
cache: any;
/**
* Constructor method.
* @param {number} tenantId
*/
constructor(tenantId: number) {
super(tenantId);
this.models = this.tenancy.models(tenantId);
this.cache = this.tenancy.cache(tenantId);
}
/**
* Retrieve the bill that associated to the given vendor id.
* @param {number} vendorId
*/
getBills(vendorId: number) {
const { Bill } = this.models;
return this.cache.get(`vendors.bills.${vendorId}`, () => {
return Bill.query().where('vendor_id', vendorId);
});
}
/**
*
* @param {numner[]} vendorsIds
*/
vendors(vendorsIds: number[]) {
const { Contact } = this.models;
return Contact.query().modifier('vendor').whereIn('id', vendorsIds);
}
/**
*
* @param {number[]} vendorIds
*/
vendorsWithBills(vendorIds: number[]) {
const { Contact } = this.models;
return Contact.query().modify('vendor')
.whereIn('id', vendorIds)
.withGraphFetched('bills');
}
}