fix: ILIKE operator not supported in sqlite (#393)
* fix: replace ILIKE operator with ILike function where possible * remove: unused import * fix: remove alias from test case as it is not needed * fix: product variant query * add: integration tests + fallback to original query for all queries searching on the display_id field * remove: console.log
This commit is contained in:
1 parent
00ab03f3a2
commit
49a132976d
12 files changed
+793
-448
No files matched your search
@@ -494,9 +494,6 @@ describe("DiscountService", () => {
|
||||
|
||||
expect(discountRepository.findAndCount).toHaveBeenCalledTimes(1)
|
||||
expect(discountRepository.findAndCount).toHaveBeenCalledWith({
|
||||
join: {
|
||||
alias: "discount",
|
||||
},
|
||||
where: expect.anything(),
|
||||
skip: 0,
|
||||
take: 50,
|
||||
|
||||
@@ -3,7 +3,7 @@ import Scrypt from "scrypt-kdf"
|
||||
import _ from "lodash"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { Brackets } from "typeorm"
|
||||
import { Brackets, ILike } from "typeorm"
|
||||
|
||||
/**
|
||||
* Provides layer to manipulate customers.
|
||||
@@ -149,9 +149,9 @@ class CustomerService extends BaseService {
|
||||
|
||||
qb.andWhere(
|
||||
new Brackets(qb => {
|
||||
qb.where(`email ILIKE :q`, { q: `%${q}%` })
|
||||
.orWhere(`first_name ILIKE :q`, { q: `%${q}%` })
|
||||
.orWhere(`last_name ILIKE :q`, { q: `%${q}%` })
|
||||
qb.where({ email: ILike(`%${q}%`) })
|
||||
.orWhere({ first_name: ILike(`%${q}%`) })
|
||||
.orWhere({ last_name: ILike(`%${q}%`) })
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -183,18 +183,14 @@ class CustomerService extends BaseService {
|
||||
delete where.first_name
|
||||
delete where.last_name
|
||||
|
||||
query.join = {
|
||||
alias: "customer",
|
||||
}
|
||||
|
||||
query.where = qb => {
|
||||
qb.where(where)
|
||||
|
||||
qb.andWhere(
|
||||
new Brackets(qb => {
|
||||
qb.where(`customer.first_name ILIKE :q`, { q: `%${q}%` })
|
||||
.orWhere(`customer.last_name ILIKE :q`, { q: `%${q}%` })
|
||||
.orWhere(`customer.email ILIKE :q`, { q: `%${q}%` })
|
||||
qb.where({ email: ILike(`%${q}%`) })
|
||||
.orWhere({ first_name: ILike(`%${q}%`) })
|
||||
.orWhere({ last_name: ILike(`%${q}%`) })
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import _ from "lodash"
|
||||
import randomize from "randomatic"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { Brackets } from "typeorm"
|
||||
import { Brackets, ILike } from "typeorm"
|
||||
|
||||
/**
|
||||
* Provides layer to manipulate discounts.
|
||||
@@ -151,16 +151,12 @@ class DiscountService extends BaseService {
|
||||
|
||||
delete where.code
|
||||
|
||||
query.join = {
|
||||
alias: "discount",
|
||||
}
|
||||
|
||||
query.where = qb => {
|
||||
qb.where(where)
|
||||
|
||||
qb.andWhere(
|
||||
new Brackets(qb => {
|
||||
qb.where(`discount.code ILIKE :q`, { q: `%${q}%` })
|
||||
qb.where({ code: ILike(`%${q}%`) })
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import _ from "lodash"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { Brackets } from "typeorm"
|
||||
import { Brackets, ILike } from "typeorm"
|
||||
|
||||
/**
|
||||
* Handles draft orders
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import _ from "lodash"
|
||||
import randomize from "randomatic"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { Brackets } from "typeorm"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import randomize from "randomatic"
|
||||
import { Brackets } from "typeorm"
|
||||
|
||||
/**
|
||||
* Provides layer to manipulate gift cards.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import _ from "lodash"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { Brackets } from "typeorm"
|
||||
|
||||
@@ -237,7 +236,9 @@ class OrderService extends BaseService {
|
||||
|
||||
qb.andWhere(
|
||||
new Brackets(qb => {
|
||||
qb.where(`shipping_address.first_name ILIKE :q`, { q: `%${q}%` })
|
||||
qb.where(`shipping_address.first_name ILIKE :qfn`, {
|
||||
qfn: `%${q}%`,
|
||||
})
|
||||
.orWhere(`order.email ILIKE :q`, { q: `%${q}%` })
|
||||
.orWhere(`display_id::varchar(255) ILIKE :dId`, { dId: `${q}` })
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import _ from "lodash"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { Brackets, Raw, IsNull } from "typeorm"
|
||||
import { Brackets, Raw, IsNull, ILike } from "typeorm"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
|
||||
/**
|
||||
@@ -558,14 +558,11 @@ class ProductVariantService extends BaseService {
|
||||
}
|
||||
|
||||
query.where = qb => {
|
||||
qb.where(where).andWhere(
|
||||
new Brackets(qb => {
|
||||
qb.where([
|
||||
{ sku: Raw(a => `${a} ILIKE :q`, { q: `%${q}%` }) },
|
||||
{ title: Raw(a => `${a} ILIKE :q`, { q: `%${q}%` }) },
|
||||
]).orWhere(`product.title ILIKE :q`, { q: `%${q}%` })
|
||||
})
|
||||
)
|
||||
qb.where(where).andWhere([
|
||||
{ sku: ILike(`%${q}%`) },
|
||||
{ title: ILike(`%${q}%`) },
|
||||
{ product: { title: ILike(`%${q}%`) } },
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user