Skip to content

Commit fc742a9

Browse files
committed
feat: enhance identity search filtering logic
- Updated the identity search filter to exclude identities marked as "do not sync" by default, unless a specific state filter is provided by the client. - Introduced a new variable `effectiveSearchFilterSchema` to manage the search filter schema, ensuring compatibility with MongoDB operators while maintaining type safety.
1 parent f38d7a4 commit fc742a9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

apps/api/src/management/identities/identities-crud.controller.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,24 @@ export class IdentitiesCrudController extends AbstractController {
173173
validations?: MixedValue;
174174
}>> {
175175
const searchFilter = {}
176+
// Par défaut, on cache les identités "ne pas synchroniser" dans la recherche.
177+
// Si le client fournit déjà un filtre `state`, on ne l'écrase pas.
178+
// Le type `FilterSchema` est récursif (valeurs attendues), alors que pour Mongo on injecte parfois
179+
// des opérateurs comme `{ $ne: ... }`. On garde un cast `any` ici côté controller.
180+
const effectiveSearchFilterSchema: any = { ...searchFilterSchema }
181+
if (!Object.prototype.hasOwnProperty.call(effectiveSearchFilterSchema, 'state')) {
182+
effectiveSearchFilterSchema.state = { $ne: IdentityState.DONT_SYNC }
183+
}
176184

177185
if (search && search.trim().length > 0) {
178186
const searchRequest = {}
179187
searchRequest['$or'] = Object.keys(IdentitiesCrudController.searchFields).map((key) => {
180188
return { [key]: { $regex: `^${search}`, $options: 'i' } }
181189
}).filter(item => item !== undefined)
182190
searchFilter['$and'] = [searchRequest]
183-
searchFilter['$and'].push(searchFilterSchema)
191+
searchFilter['$and'].push(effectiveSearchFilterSchema)
184192
} else {
185-
Object.assign(searchFilter, searchFilterSchema)
193+
Object.assign(searchFilter, effectiveSearchFilterSchema)
186194
}
187195

188196
const [data, total] = await this._service.findAndCount(

0 commit comments

Comments
 (0)