fix: review comments and added graphql operator

This commit is contained in:
meherchandan 2022-07-12 16:19:51 +04:00
parent 41fb55b899
commit a7131ca000
6 changed files with 26 additions and 5 deletions

View File

@ -13,7 +13,7 @@ const OPERATORS = [
'$in',
'$notIn',
'$eq',
'$eqsi',
'$eqi',
'$ne',
'$gt',
'$gte',
@ -223,7 +223,7 @@ const applyOperator = (qb, column, operator, value) => {
break;
}
case '$eqsi': {
case '$eqi': {
if (value === null) {
qb.whereNull(column);
break;

View File

@ -168,14 +168,14 @@ describe('Filtering API', () => {
});
});
describe('Filter equals with case insensitive', () => {
test('Should be usable with eqsi suffix', async () => {
test('Should be usable with eqi suffix', async () => {
const res = await rq({
method: 'GET',
url: '/products',
qs: {
filters: {
name: {
$eqsi: 'PRODuct 1',
$eqi: 'PRODuct 1',
},
},
},
@ -192,7 +192,7 @@ describe('Filtering API', () => {
qs: {
filters: {
name: {
$eqsi: 'Product non existant',
$eqi: 'Product non existant',
},
},
},

View File

@ -0,0 +1,13 @@
'use strict';
const EQI_FIELD_NAME = 'eqi';
module.exports = () => ({
fieldName: EQI_FIELD_NAME,
strapiOperator: '$eqi',
add(t, type) {
t.field(EQI_FIELD_NAME, { type });
},
});

View File

@ -8,6 +8,7 @@ const operators = {
not: require('./not'),
eq: require('./eq'),
eqi: require('./eqi'),
ne: require('./ne'),
startsWith: require('./starts-with'),

View File

@ -85,6 +85,7 @@ const allOperators = [
'not',
'eq',
'eqi',
'ne',
'startsWith',

View File

@ -292,6 +292,12 @@ describe('Test Graphql API End to End', () => {
},
[postsPayload[1]],
],
[
{
category: { eqi: 'Blog' },
},
[postsPayload[0]],
],
[
{
name: { contains: 'post' },