Clear only the submitted company from multi-company carts and label all companies.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-15 08:30:58 +02:00
co-authored by Cursor
parent 183476708d
commit e801557e62
2 changed files with 12 additions and 3 deletions
+4 -2
View File
@@ -198,12 +198,14 @@ export class CartsService {
companyName: string;
}>;
}) {
const companyName = cart.items[0]?.companyName;
const companyNames = [
...new Set(cart.items.map((item) => item.companyName).filter(Boolean)),
];
return {
id: cart.id,
userId: cart.userId,
companyId: cart.companyId ?? cart.items[0]?.companyId,
companyName: companyName ?? '',
companyName: companyNames.join('، '),
notes: cart.notes ?? undefined,
items: cart.items.map((item) => ({
id: item.id,
+8 -1
View File
@@ -254,7 +254,14 @@ export class OrdersService {
const cart = await tx.cart.findFirst({ where: { userId } });
if (cart) {
await tx.cartItem.deleteMany({
where: { cartId: cart.id, companyId: company.id },
where: { cartId: cart.id, companyId: orderCompany.id },
});
const remaining = await tx.cartItem.findFirst({
where: { cartId: cart.id },
});
await tx.cart.update({
where: { id: cart.id },
data: { companyId: remaining?.companyId ?? null },
});
}