mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: listing vendors and customers.
feat: items service events.
This commit is contained in:
@@ -10,9 +10,6 @@ import {
|
||||
} from 'decorators/eventDispatcher';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import events from 'subscribers/events';
|
||||
import JournalPoster from 'services/Accounting/JournalPoster';
|
||||
import { Account } from 'models';
|
||||
import AccountRepository from 'repositories/AccountRepository';
|
||||
|
||||
@Service()
|
||||
export default class AccountsService {
|
||||
|
||||
@@ -144,15 +144,18 @@ export default class CustomersService {
|
||||
*/
|
||||
public async getCustomersList(
|
||||
tenantId: number,
|
||||
filter: ICustomersFilter
|
||||
customersFilter: ICustomersFilter
|
||||
): Promise<{ customers: ICustomer[], pagination: IPaginationMeta, filterMeta: IFilterMeta }> {
|
||||
const { Contact } = this.tenancy.models(tenantId);
|
||||
const dynamicList = await this.dynamicListService.dynamicList(tenantId, Contact, filter);
|
||||
const dynamicList = await this.dynamicListService.dynamicList(tenantId, Contact, customersFilter);
|
||||
|
||||
const { results, pagination } = await Contact.query().onBuild((query) => {
|
||||
query.modify('customer');
|
||||
dynamicList.buildQuery()(query);
|
||||
});
|
||||
}).pagination(
|
||||
customersFilter.page - 1,
|
||||
customersFilter.pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
customers: results,
|
||||
|
||||
@@ -11,7 +11,9 @@ import {
|
||||
IVendorNewDTO,
|
||||
IVendorEditDTO,
|
||||
IVendor,
|
||||
IVendorsFilter
|
||||
IVendorsFilter,
|
||||
IPaginationMeta,
|
||||
IFilterMeta
|
||||
} from 'interfaces';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
@@ -226,14 +228,25 @@ export default class VendorsService {
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {IVendorsFilter} vendorsFilter - Vendors filter.
|
||||
*/
|
||||
public async getVendorsList(tenantId: number, vendorsFilter: IVendorsFilter) {
|
||||
const { Vendor } = this.tenancy.models(tenantId);
|
||||
public async getVendorsList(
|
||||
tenantId: number,
|
||||
vendorsFilter: IVendorsFilter
|
||||
): Promise<{ vendors: IVendor[], pagination: IPaginationMeta, filterMeta: IFilterMeta }> {
|
||||
const { Contact } = this.tenancy.models(tenantId);
|
||||
const dynamicFilter = await this.dynamicListService.dynamicList(tenantId, Contact, vendorsFilter);
|
||||
|
||||
const dynamicFilter = await this.dynamicListService.dynamicList(tenantId, Vendor, vendorsFilter);
|
||||
|
||||
const vendors = await Vendor.query().onBuild((builder) => {
|
||||
const { results, pagination } = await Contact.query().onBuild((builder) => {
|
||||
builder.modify('vendor');
|
||||
dynamicFilter.buildQuery()(builder);
|
||||
});
|
||||
return vendors;
|
||||
}).pagination(
|
||||
vendorsFilter.page - 1,
|
||||
vendorsFilter.pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
vendors: results,
|
||||
pagination,
|
||||
filterMeta: dynamicFilter.getResponseMeta(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { Inject } from 'typedi';
|
||||
import { difference } from 'lodash';
|
||||
import {
|
||||
EventDispatcher,
|
||||
EventDispatcherInterface,
|
||||
} from 'decorators/eventDispatcher';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import {
|
||||
IItemCategory,
|
||||
@@ -10,6 +14,7 @@ import {
|
||||
} from "interfaces";
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import events from 'subscribers/events';
|
||||
|
||||
const ERRORS = {
|
||||
ITEM_CATEGORIES_NOT_FOUND: 'ITEM_CATEGORIES_NOT_FOUND',
|
||||
@@ -33,6 +38,9 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
|
||||
@EventDispatcher()
|
||||
eventDispatcher: EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* Retrieve item category or throw not found error.
|
||||
* @param {number} tenantId
|
||||
@@ -92,6 +100,8 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
|
||||
const itemCategoryObj = this.transformOTDToObject(itemCategoryOTD, authorizedUser);
|
||||
const itemCategory = await ItemCategory.query().insert({ ...itemCategoryObj });
|
||||
|
||||
await this.eventDispatcher.dispatch(events.items.onCreated);
|
||||
this.logger.info('[item_category] item category inserted successfully.', { tenantId, itemCategoryOTD });
|
||||
|
||||
return itemCategory;
|
||||
@@ -188,6 +198,8 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
|
||||
const itemCategoryObj = this.transformOTDToObject(itemCategoryOTD, authorizedUser);
|
||||
const itemCategory = await ItemCategory.query().patchAndFetchById(itemCategoryId, { ...itemCategoryObj });
|
||||
|
||||
await this.eventDispatcher.dispatch(events.items.onEdited);
|
||||
this.logger.info('[item_category] edited successfully.', { tenantId, itemCategoryId, itemCategoryOTD });
|
||||
|
||||
return itemCategory;
|
||||
@@ -207,6 +219,8 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
const { ItemCategory } = this.tenancy.models(tenantId);
|
||||
await ItemCategory.query().findById(itemCategoryId).delete();
|
||||
this.logger.info('[item_category] deleted successfully.', { tenantId, itemCategoryId });
|
||||
|
||||
await this.eventDispatcher.dispatch(events.items.onDeleted);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,6 +281,8 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
await this.unassociateItemsWithCategories(tenantId, itemCategoriesIds);
|
||||
|
||||
await ItemCategory.query().whereIn('id', itemCategoriesIds).delete();
|
||||
|
||||
await this.eventDispatcher.dispatch(events.items.onBulkDeleted);
|
||||
this.logger.info('[item_category] item categories deleted successfully.', { tenantId, itemCategoriesIds });
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import moment from 'moment';
|
||||
import { ServiceError } from "exceptions";
|
||||
import {
|
||||
IManualJournalDTO,
|
||||
IManuaLJournalsService,
|
||||
IManualJournalsService,
|
||||
IManualJournalsFilter,
|
||||
ISystemUser,
|
||||
IManualJournal,
|
||||
@@ -33,7 +33,7 @@ const ERRORS = {
|
||||
};
|
||||
|
||||
@Service()
|
||||
export default class ManualJournalsService implements IManuaLJournalsService {
|
||||
export default class ManualJournalsService implements IManualJournalsService {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user