Nuxt : query with muliples Predicates

Hi,
In my slice, I want to retrieve all the "clubs" (customtype : clubcustomtype) which the field "niveaulabellisation" is equal to 1

If I don't filter on the "niveaulabellisation", everything works fine :

async fetch() {
try {
let localeForPrismic = 'fr-fr'
if (this.$i18n.locale === 'en') {
localeForPrismic = 'en-us'
}

  const clubs = await this.$prismic.api.query(
    [
      this.$prismic.predicates.at('document.type', 'clubcustomtype'),
    ],
    {
      lang: localeForPrismic,
      orderings: '[my.clubcustomtype.datelabellisation desc]',
      pageSize: 2,
      page: this.pageNumber,
    }
  )

  this.clubs = clubs
} catch (e) {
  console.error(e)
}

},

But When I add the filter :

async fetch() {
try {
let localeForPrismic = 'fr-fr'
if (this.$i18n.locale === 'en') {
localeForPrismic = 'en-us'
}

  const clubs = await this.$prismic.api.query(
    [
      this.$prismic.predicates.at('document.type', 'clubcustomtype'),

      this.$prismic.predicates.at(
        'my.clubcustomtype.niveaulabellisation',
        1
      ),
    ],
    {
      lang: localeForPrismic,
      orderings: '[my.clubcustomtype.datelabellisation desc]',
      pageSize: 2,
      page: this.pageNumber,
    }
  )

  // my.club.niveaulabellisation

  this.clubs = clubs
} catch (e) {
  console.error(e)
}

},

Primic API returns an error :
https://fairplayforplanet.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=2&lang=fr-fr&orderings=[my.clubcustomtype.datelabellisation%20desc]&ref=ZBB2OhAAACoAzSpg&q=[[at(document.type%2C%20"clubcustomtype")][at(my.clubcustomtype.niveaulabellisation%2C%201)]]

Her is my customtype

{
"id": "clubcustomtype",
"label": "Club",
"repeatable": true,
"status": true,
"json": {
"Main": {
"logo": {
"type": "Image",
"config": {
"label": "logo",
"constraint": {
"width": 300
},
"thumbnails":
}
},
"nom": {
"type": "Text",
"config": {
"label": "nom",
"placeholder": ""
}
},
"scoretotal": {
"type": "Text",
"config": {
"label": "scoreTotal",
"placeholder": ""
}
},
"scorepreservationenvironnement": {
"type": "Text",
"config": {
"label": "scorePreservationEnvironnement",
"placeholder": ""
}
},
"scoreecoperformer": {
"type": "Text",
"config": {
"label": "scoreEcoperformer",
"placeholder": ""
}
},
"scorerolesocietal": {
"type": "Text",
"config": {
"label": "scoreRoleSocietal",
"placeholder": ""
}
},
"datelabellisation": {
"type": "Date",
"config": {
"label": "dateLabellisation",
"placeholder": ""
}
},
"niveaulabellisation": {
"type": "Select",
"config": {
"label": "niveauLabellisation",
"placeholder": "",
"options": [
"1",
"2",
"3"
]
}
},
"sport": {
"type": "Text",
"config": {
"label": "sport",
"placeholder": ""
}
}
}
}
}

1 Like

Can anyone help me? I am stuck :frowning:

1 Like

Hello @ricou,

My apologies for just responding.

After debugging the issue and looking at your Customtype, I can see that the niveauLabellisation options are strings, and you are filtering with 1 as a number and not as a string "1".

Let me know if it works for you.

Thanks,
Racheal.

1 Like

Hello @racheal.orukele ,

well seen !
It works perfectly now.
Thanks again!
Prismic Team at the top!

2 Likes

@ricou I'm glad to hear that. Let us know if you have any other questions.

1 Like