bug
This commit is contained in:
@@ -19,6 +19,7 @@ import { Cart, CartItem } from '../interfaces/cart.interface';
|
|||||||
import { CouponService } from 'src/modules/coupons/providers/coupon.service';
|
import { CouponService } from 'src/modules/coupons/providers/coupon.service';
|
||||||
import { OrderCouponDetail } from 'src/modules/orders/interface/order-status';
|
import { OrderCouponDetail } from 'src/modules/orders/interface/order-status';
|
||||||
import { CouponType } from 'src/modules/coupons/interface/coupon';
|
import { CouponType } from 'src/modules/coupons/interface/coupon';
|
||||||
|
import { Order } from '../../orders/entities/order.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CartService {
|
export class CartService {
|
||||||
@@ -399,17 +400,19 @@ export class CartService {
|
|||||||
|
|
||||||
// Check maxUsesPerUser limit by counting how many orders this user has with this coupon
|
// Check maxUsesPerUser limit by counting how many orders this user has with this coupon
|
||||||
if (coupon.maxUsesPerUser) {
|
if (coupon.maxUsesPerUser) {
|
||||||
const result = await this.em.getConnection().execute<{ count: string }>(
|
// Use native query for JSONB field access with proper parameter binding
|
||||||
`SELECT COUNT(*) as count
|
const knex = this.em.getKnex();
|
||||||
|
const result = await knex.raw(
|
||||||
|
`SELECT COUNT(*)::int as count
|
||||||
FROM orders
|
FROM orders
|
||||||
WHERE user_id = $1
|
WHERE user_id = ?
|
||||||
AND coupon_detail IS NOT NULL
|
AND coupon_detail IS NOT NULL
|
||||||
AND coupon_detail->>'couponId' = $2
|
AND coupon_detail->>'couponId' = ?
|
||||||
AND deleted_at IS NULL`,
|
AND deleted_at IS NULL`,
|
||||||
[userId, coupon.id],
|
[userId, coupon.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
const userCouponUsageCount = parseInt((result[0] as { count: string })?.count || '0', 10);
|
const userCouponUsageCount = result.rows?.[0]?.count ?? result[0]?.count ?? 0;
|
||||||
|
|
||||||
if (userCouponUsageCount >= coupon.maxUsesPerUser) {
|
if (userCouponUsageCount >= coupon.maxUsesPerUser) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
@@ -594,11 +597,7 @@ export class CartService {
|
|||||||
/**
|
/**
|
||||||
* Set description for cart
|
* Set description for cart
|
||||||
*/
|
*/
|
||||||
async setDescription(
|
async setDescription(userId: string, restaurantId: string, setDescriptionDto: SetDescriptionDto): Promise<Cart> {
|
||||||
userId: string,
|
|
||||||
restaurantId: string,
|
|
||||||
setDescriptionDto: SetDescriptionDto,
|
|
||||||
): Promise<Cart> {
|
|
||||||
const cart = await this.findOneOrFail(userId, restaurantId);
|
const cart = await this.findOneOrFail(userId, restaurantId);
|
||||||
|
|
||||||
cart.description = setDescriptionDto.description;
|
cart.description = setDescriptionDto.description;
|
||||||
|
|||||||
Reference in New Issue
Block a user