feat: made missing errors as internal server error and added depth in scim knex

This commit is contained in:
=
2024-10-11 01:42:38 +05:30
parent 3d58eba78c
commit e042f9b5e2
2 changed files with 14 additions and 6 deletions

View File

@ -11,8 +11,11 @@ const appendParentToGroupingOperator = (parentPath: string, filter: Filter) => {
const processDynamicQuery = (
rootQuery: Knex.QueryBuilder,
scimRootFilterAst: Filter,
getAttributeField: (attr: string) => string | null
getAttributeField: (attr: string) => string | null,
depth = 0
) => {
if (depth > 10) return;
const stack = [
{
scimFilterAst: scimRootFilterAst,
@ -76,7 +79,7 @@ const processDynamicQuery = (
case "and": {
scimFilterAst.filters.forEach((el) => {
void query.andWhere((subQueryBuilder) => {
processDynamicQuery(subQueryBuilder, el, getAttributeField);
processDynamicQuery(subQueryBuilder, el, getAttributeField, depth + 1);
});
});
break;
@ -84,14 +87,14 @@ const processDynamicQuery = (
case "or": {
scimFilterAst.filters.forEach((el) => {
void query.orWhere((subQueryBuilder) => {
processDynamicQuery(subQueryBuilder, el, getAttributeField);
processDynamicQuery(subQueryBuilder, el, getAttributeField, depth + 1);
});
});
break;
}
case "not": {
void query.whereNot((subQueryBuilder) => {
processDynamicQuery(subQueryBuilder, scimFilterAst.filter, getAttributeField);
processDynamicQuery(subQueryBuilder, scimFilterAst.filter, getAttributeField, depth + 1);
});
break;
}
@ -100,7 +103,8 @@ const processDynamicQuery = (
processDynamicQuery(
subQueryBuilder,
appendParentToGroupingOperator(scimFilterAst.attrPath, scimFilterAst.valFilter),
getAttributeField
getAttributeField,
depth + 1
);
});
break;

View File

@ -97,7 +97,11 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
message
});
} else {
void res.send(error);
void res.status(HttpStatusCodes.InternalServerError).send({
statusCode: HttpStatusCodes.InternalServerError,
error: "InternalServerError",
message: "Something went wrong"
});
}
});
});