Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
feat(titres): permet de rechercher des titres à partir d’une liste d’…
Browse files Browse the repository at this point in the history
…identifiants uniques
  • Loading branch information
vmaubert committed Feb 3, 2022
1 parent 53a42b1 commit f8afbc7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/api/graphql/resolvers/titres.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphQLResolveInfo } from 'graphql'

import { IToken, ITitre, ITitreColonneId } from '../../../types'
import { ITitre, ITitreColonneId, IToken } from '../../../types'

import { debug } from '../../../config/index'
import { titreFormat, titresFormat } from '../../_format/titres'
Expand Down Expand Up @@ -53,6 +53,7 @@ const titres = async (
page,
colonne,
ordre,
ids,
perimetre,
typesIds,
domainesIds,
Expand All @@ -70,6 +71,7 @@ const titres = async (
page?: number | null
colonne?: ITitreColonneId | null
ordre?: 'asc' | 'desc' | null
ids: string[]
perimetre?: number[] | null
typesIds: string[]
domainesIds: string[]
Expand Down Expand Up @@ -97,6 +99,7 @@ const titres = async (
page,
colonne,
ordre,
ids,
perimetre,
typesIds,
domainesIds,
Expand All @@ -115,6 +118,7 @@ const titres = async (
),
titresCount(
{
ids,
typesIds,
domainesIds,
statutsIds,
Expand Down
1 change: 1 addition & 0 deletions src/api/graphql/schemas/index.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Query {
page: Int
colonne: String
ordre: String
ids: [ID]
perimetre: [Float!]
typesIds: [ID]
domainesIds: [ID]
Expand Down
8 changes: 7 additions & 1 deletion src/database/queries/_titres-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const fieldFormat = (name: string, field: string) =>
// root: nom de la table de base
const titresFiltersQueryModify = (
{
ids,
perimetre,
domainesIds,
typesIds,
Expand All @@ -33,6 +34,7 @@ const titresFiltersQueryModify = (
references,
territoires
}: {
ids?: string[] | null
perimetre?: number[] | null
domainesIds?: string[] | null
typesIds?: string[] | null
Expand All @@ -52,6 +54,10 @@ const titresFiltersQueryModify = (
name: ITitreTableName = 'titres',
root: ITitreRootName = 'titres'
) => {
if (ids) {
q.whereIn('titres.id', ids)
}

if (perimetre?.length === 4) {
q.leftJoinRelated(jointureFormat(name, 'points'))
q.whereRaw(
Expand Down Expand Up @@ -117,7 +123,7 @@ const titresFiltersQueryModify = (
`${name}.nom`,
nomsArray.map(n => `(?=.*?(${n}))`).join('')
]).orWhereRaw(`?? ~* ?`, [
`${name}.id`,
`${name}.slug`,
nomsArray.map(n => `(?=.*?(${n}))`).join('')
])
})
Expand Down
17 changes: 8 additions & 9 deletions src/database/queries/titres.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Transaction, raw, RawBuilder } from 'objection'
import { raw, RawBuilder, Transaction } from 'objection'

import {
IColonne,
IFields,
Index,
ITitre,
ITitreAdministrationGestionnaire,
ITitreColonneId,
IColonne,
Index,
IFields,
IUtilisateur
} from '../../types'

Expand Down Expand Up @@ -161,16 +161,13 @@ const titresGet = async (
) => {
const q = titresQueryBuild({ fields }, user, demandeEnCours)

if (ids) {
q.whereIn('titres.id', ids)
}

if (slugs) {
q.whereIn('titres.slug', slugs)
}

titresFiltersQueryModify(
{
ids,
perimetre,
domainesIds,
typesIds,
Expand Down Expand Up @@ -243,6 +240,7 @@ const titresGet = async (
*/
const titresCount = async (
{
ids,
domainesIds,
typesIds,
statutsIds,
Expand All @@ -255,6 +253,7 @@ const titresCount = async (
territoires,
demandeEnCours
}: {
ids?: string[] | null
domainesIds?: string[] | null
typesIds?: string[] | null
statutsIds?: string[] | null
Expand All @@ -274,9 +273,9 @@ const titresCount = async (

titresFiltersQueryModify(
{
ids,
domainesIds,
typesIds,

statutsIds,
substancesLegalesIds,
entreprisesIds,
Expand Down

0 comments on commit f8afbc7

Please sign in to comment.