mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
fix(InviteUsers): fix invite users bugs.
This commit is contained in:
@@ -570,48 +570,6 @@ export default class ExpensesService implements IExpensesService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given expenses in bulk.
|
||||
* @param {number} tenantId
|
||||
* @param {number[]} expensesIds
|
||||
* @param {ISystemUser} authorizedUser
|
||||
*/
|
||||
public async deleteBulkExpenses(
|
||||
tenantId: number,
|
||||
expensesIds: number[],
|
||||
authorizedUser: ISystemUser
|
||||
) {
|
||||
const {
|
||||
expenseRepository,
|
||||
expenseEntryRepository,
|
||||
} = this.tenancy.repositories(tenantId);
|
||||
|
||||
// Retrieve olds expenses.
|
||||
const oldExpenses = await this.getExpensesOrThrowError(
|
||||
tenantId,
|
||||
expensesIds
|
||||
);
|
||||
|
||||
this.logger.info('[expense] trying to delete the given expenses.', {
|
||||
tenantId,
|
||||
expensesIds,
|
||||
});
|
||||
await expenseEntryRepository.deleteWhereIn('expenseId', expensesIds);
|
||||
await expenseRepository.deleteWhereIdIn(expensesIds);
|
||||
|
||||
this.logger.info('[expense] the given expenses deleted successfully.', {
|
||||
tenantId,
|
||||
expensesIds,
|
||||
});
|
||||
// Triggers `onExpenseBulkDeleted` event.
|
||||
this.eventDispatcher.dispatch(events.expenses.onBulkDeleted, {
|
||||
tenantId,
|
||||
expensesIds,
|
||||
oldExpenses,
|
||||
authorizedUser,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the not published expenses.
|
||||
* @param {IExpense[]} expenses -
|
||||
@@ -629,74 +587,6 @@ export default class ExpensesService implements IExpensesService {
|
||||
return expenses.filter((expense) => expense.publishedAt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given expenses in bulk.
|
||||
* @param {number} tenantId
|
||||
* @param {number[]} expensesIds
|
||||
* @param {ISystemUser} authorizedUser
|
||||
*/
|
||||
public async publishBulkExpenses(
|
||||
tenantId: number,
|
||||
expensesIds: number[],
|
||||
authorizedUser: ISystemUser
|
||||
): Promise<{
|
||||
meta: {
|
||||
alreadyPublished: number;
|
||||
published: number;
|
||||
total: number,
|
||||
},
|
||||
}> {
|
||||
const oldExpenses = await this.getExpensesOrThrowError(
|
||||
tenantId,
|
||||
expensesIds
|
||||
);
|
||||
const { expenseRepository } = this.tenancy.repositories(tenantId);
|
||||
|
||||
// Filters the not published expenses.
|
||||
const notPublishedExpenses = this.getNonePublishedExpenses(oldExpenses);
|
||||
|
||||
// Filters the published expenses.
|
||||
const publishedExpenses = this.getPublishedExpenses(oldExpenses);
|
||||
|
||||
// Mappes the not-published expenses to get id.
|
||||
const notPublishedExpensesIds = map(notPublishedExpenses, 'id');
|
||||
|
||||
if (notPublishedExpensesIds.length > 0) {
|
||||
this.logger.info('[expense] trying to publish the given expenses.', {
|
||||
tenantId,
|
||||
expensesIds,
|
||||
});
|
||||
await expenseRepository.whereIdInPublish(notPublishedExpensesIds);
|
||||
|
||||
this.logger.info(
|
||||
'[expense] the given expenses ids published successfully.',
|
||||
{ tenantId, expensesIds }
|
||||
);
|
||||
}
|
||||
// Retrieve the new expenses after modification.
|
||||
const expenses = await expenseRepository.findWhereIn(
|
||||
'id',
|
||||
expensesIds,
|
||||
'categories'
|
||||
);
|
||||
// Triggers `onExpenseBulkDeleted` event.
|
||||
this.eventDispatcher.dispatch(events.expenses.onBulkPublished, {
|
||||
tenantId,
|
||||
expensesIds,
|
||||
oldExpenses,
|
||||
expenses,
|
||||
authorizedUser,
|
||||
});
|
||||
|
||||
return {
|
||||
meta: {
|
||||
alreadyPublished: publishedExpenses.length,
|
||||
published: notPublishedExpenses.length,
|
||||
total: oldExpenses.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve expenses datatable lsit.
|
||||
* @param {number} tenantId
|
||||
|
||||
Reference in New Issue
Block a user