Skip to content

Commit

Permalink
Fix cart util call
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikearaya committed Nov 28, 2024
1 parent 02e5e1d commit a21706d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/resolvers/mutations/users/removeUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function removeUser(
log(`mutation removeUser ${normalizedUserId}`, { userId });

if (!(await modules.users.userExists({ userId: normalizedUserId })))
throw UserNotFoundError({ id: normalizedUserId });
throw new UserNotFoundError({ id: normalizedUserId });

return modules.users.delete({ userId: normalizedUserId, removeUserReviews }, unchainedApi);
}
11 changes: 9 additions & 2 deletions packages/core/src/services/deleteUserCartService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { UnchainedCore } from '../core-index.js';

const deleteUserCartService = async (userId: string, unchainedAPI: UnchainedCore) => {
const deleteUserCartService = async (
userId: string,
unchainedAPI: UnchainedCore & { countryContext?: string },
) => {
try {
const userCart = await unchainedAPI.modules.orders.cart({ userId });
const user = await unchainedAPI.modules.users.findUserById(userId);
const userCart = await unchainedAPI.modules.orders.cart({
userId,
countryContext: unchainedAPI?.countryContext || user?.lastLogin?.countryCode,
});
await unchainedAPI.modules.orders.delete(userCart?._id);
await unchainedAPI.modules.orders.payments.deleteOrderPayment(userCart?._id);
await unchainedAPI.modules.orders.deliveries.deleteOrderDelivery(userCart?._id);
Expand Down

0 comments on commit a21706d

Please sign in to comment.