mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix: item categories bulk delete.
This commit is contained in:
@@ -215,7 +215,9 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
* @param {number[]} itemCategoriesIds
|
||||
*/
|
||||
private async getItemCategoriesOrThrowError(tenantId: number, itemCategoriesIds: number[]) {
|
||||
const itemCategories = await ItemCategory.query().whereIn('id', ids);
|
||||
const { ItemCategory } = this.tenancy.models(tenantId);
|
||||
const itemCategories = await ItemCategory.query().whereIn('id', itemCategoriesIds);
|
||||
|
||||
const storedItemCategoriesIds = itemCategories.map((category: IItemCategory) => category.id);
|
||||
const notFoundCategories = difference(itemCategoriesIds, storedItemCategoriesIds);
|
||||
|
||||
@@ -239,7 +241,13 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
return { itemCategories, filterMeta: dynamicList.getResponseMeta() };
|
||||
}
|
||||
|
||||
private async unassociateItemsWithCategories(tenantId: number, itemCategoryId: number|number[]) {
|
||||
/**
|
||||
* Unlink items relations with item categories.
|
||||
* @param {number} tenantId
|
||||
* @param {number|number[]} itemCategoryId -
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
private async unassociateItemsWithCategories(tenantId: number, itemCategoryId: number|number[]): Promise<void> {
|
||||
const { Item } = this.tenancy.models(tenantId);
|
||||
const ids = Array.isArray(itemCategoryId) ? itemCategoryId : [itemCategoryId];
|
||||
|
||||
@@ -253,6 +261,8 @@ export default class ItemCategoriesService implements IItemCategoriesService {
|
||||
*/
|
||||
public async deleteItemCategories(tenantId: number, itemCategoriesIds: number[], authorizedUser: ISystemUser) {
|
||||
this.logger.info('[item_category] trying to delete item categories.', { tenantId, itemCategoriesIds });
|
||||
const { ItemCategory } = this.tenancy.models(tenantId);
|
||||
|
||||
await this.getItemCategoriesOrThrowError(tenantId, itemCategoriesIds);
|
||||
await this.unassociateItemsWithCategories(tenantId, itemCategoriesIds);
|
||||
|
||||
|
||||
@@ -429,7 +429,8 @@ export default class ManualJournalsService implements IManuaLJournalsService {
|
||||
this.logger.info('[manual_journals] trying to get specific manual journal.', { tenantId, manualJournalId });
|
||||
const manualJournal = await ManualJournal.query()
|
||||
.findById(manualJournalId)
|
||||
.withGraphFetched('entries');
|
||||
.withGraphFetched('entries')
|
||||
.withGraphFetched('media');
|
||||
|
||||
return manualJournal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user