Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deleting products or containers causing queries to fail (#461) #462

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/service/invoice-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ export default class InvoiceService extends WithManager {

const transactions = await this.manager.find(Transaction, { where: { id: In(tIds),
subTransactions: { subTransactionRows: { invoice: false } } },
relations });
relations,
withDeleted: true });

const response: Promise<TransactionResponse>[] = [];
transactions.forEach((t) => response.push(transactionService.asTransactionResponse(t)));
Expand Down
32 changes: 12 additions & 20 deletions src/service/transaction-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
} from '../helpers/transaction-mapper';
import ProductCategoryService from './product-category-service';
import WithManager from '../database/with-manager';
import ProductService from './product-service';

export interface TransactionFilterParameters {
transactionId?: number | number[],
Expand Down Expand Up @@ -137,12 +138,9 @@ export default class TransactionService extends WithManager {
public async getTotalCost(rows: SubTransactionRowRequest[]): Promise<Dinero.Dinero> {
// get costs of individual rows
const rowCosts = await Promise.all(rows.map(async (row) => {
const rowCost = await this.manager.findOne(ProductRevision, {
where: {
revision: row.product.revision,
product: { id: row.product.id },
},
}).then((product) => product.priceInclVat.multiply(row.amount));
const options = await ProductService.getOptions({ productRevision: row.product.revision, productId: row.product.id });
const rowCost = await this.manager.findOne(ProductRevision, options)
.then((product) => product.priceInclVat.multiply(row.amount));

return rowCost;
}));
Expand Down Expand Up @@ -205,13 +203,9 @@ export default class TransactionService extends WithManager {
}

// check if product exists
const product = await this.manager.findOne(ProductRevision, {
where: {
revision: req.product.revision,
product: { id: req.product.id, deletedAt: IsNull() },
},
relations: ['product'],
});
const options = await ProductService.getOptions({ productRevision: req.product.revision, productId: req.product.id });
options.withDeleted = false;
const product = await this.manager.findOne(ProductRevision, options);
if (!product) {
return false;
}
Expand Down Expand Up @@ -443,6 +437,8 @@ export default class TransactionService extends WithManager {
revision: req.container.revision,
container: { id: req.container.id },
},
withDeleted: true,
relations: ['container'],
});

// sub transaction rows
Expand Down Expand Up @@ -504,13 +500,9 @@ export default class TransactionService extends WithManager {
if (!req) {
return undefined;
}
const product = await this.manager.findOne(ProductRevision, {
where: {
revision: req.product.revision,
product: { id: req.product.id },
},
relations: ['vat'],
});

const options = await ProductService.getOptions({ productRevision: req.product.revision, productId: req.product.id });
const product = await this.manager.findOne(ProductRevision, options);
return { product, amount: req.amount, subTransaction } as SubTransactionRow;
}

Expand Down
Loading