remove item

This commit is contained in:
2026-02-21 14:51:58 +03:30
parent a636598683
commit 6cf1d3c6d4
3 changed files with 3000 additions and 6 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,17 @@
import { Migration } from '@mikro-orm/migrations';
export class Migration20260221105450 extends Migration {
override async up(): Promise<void> {
this.addSql(`alter table "credit_transactions" drop constraint if exists "credit_transactions_type_check";`);
this.addSql(`alter table "credit_transactions" add constraint "credit_transactions_type_check" check("type" in (''));`);
}
override async down(): Promise<void> {
this.addSql(`alter table "credit_transactions" drop constraint if exists "credit_transactions_type_check";`);
this.addSql(`alter table "credit_transactions" add constraint "credit_transactions_type_check" check("type" in (''));`);
}
}
+21 -6
View File
@@ -150,14 +150,29 @@ export class InvoiceService {
return item;
}
async update(id: string, updateInvoiceDto: UpdateInvoiceDto) {
async update(id: string, dto: UpdateInvoiceDto) {
const invoice = await this.findOneOrFail(id);
if (updateInvoiceDto.enableTax !== undefined) invoice.enableTax = updateInvoiceDto.enableTax;
if (updateInvoiceDto.approvalDeadline !== undefined) {
invoice.approvalDeadline = new Date(updateInvoiceDto.approvalDeadline);
if (dto.enableTax !== undefined) invoice.enableTax = dto.enableTax;
if (dto.approvalDeadline !== undefined) {
invoice.approvalDeadline = new Date(dto.approvalDeadline);
}
if (updateInvoiceDto.items !== undefined && updateInvoiceDto.items.length > 0) {
for (const item of updateInvoiceDto.items) {
if(dto.paymentMethod !== undefined) invoice.paymentMethod = dto.paymentMethod;
if(dto.description !== undefined) invoice.description = dto.description;
// if(updateInvoiceDto.attachments !== undefined) invoice.attachments = updateInvoiceDto.attachments;
if (dto.items !== undefined) {
// Items in dto.items represent the full list: delete any existing items not in the list
const idsToKeep = new Set(
dto.items.filter((i) => i.id).map((i) => i.id),
);
const existingItems = invoice.items.getItems();
for (const existingItem of existingItems) {
if (!idsToKeep.has(existingItem.id)) {
invoice.items.remove(existingItem);
}
}
for (const item of dto.items) {
if (item.id) {
const existingItem = await this.em.findOne(InvoiceItem, {
id: item.id,