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
+9 -5
View File
@@ -11,8 +11,11 @@ const appendParentToGroupingOperator = (parentPath: string, filter: Filter) => {
const processDynamicQuery = ( const processDynamicQuery = (
rootQuery: Knex.QueryBuilder, rootQuery: Knex.QueryBuilder,
scimRootFilterAst: Filter, scimRootFilterAst: Filter,
getAttributeField: (attr: string) => string | null getAttributeField: (attr: string) => string | null,
depth = 0
) => { ) => {
if (depth > 10) return;
const stack = [ const stack = [
{ {
scimFilterAst: scimRootFilterAst, scimFilterAst: scimRootFilterAst,
@@ -76,7 +79,7 @@ const processDynamicQuery = (
case "and": { case "and": {
scimFilterAst.filters.forEach((el) => { scimFilterAst.filters.forEach((el) => {
void query.andWhere((subQueryBuilder) => { void query.andWhere((subQueryBuilder) => {
processDynamicQuery(subQueryBuilder, el, getAttributeField); processDynamicQuery(subQueryBuilder, el, getAttributeField, depth + 1);
}); });
}); });
break; break;
@@ -84,14 +87,14 @@ const processDynamicQuery = (
case "or": { case "or": {
scimFilterAst.filters.forEach((el) => { scimFilterAst.filters.forEach((el) => {
void query.orWhere((subQueryBuilder) => { void query.orWhere((subQueryBuilder) => {
processDynamicQuery(subQueryBuilder, el, getAttributeField); processDynamicQuery(subQueryBuilder, el, getAttributeField, depth + 1);
}); });
}); });
break; break;
} }
case "not": { case "not": {
void query.whereNot((subQueryBuilder) => { void query.whereNot((subQueryBuilder) => {
processDynamicQuery(subQueryBuilder, scimFilterAst.filter, getAttributeField); processDynamicQuery(subQueryBuilder, scimFilterAst.filter, getAttributeField, depth + 1);
}); });
break; break;
} }
@@ -100,7 +103,8 @@ const processDynamicQuery = (
processDynamicQuery( processDynamicQuery(
subQueryBuilder, subQueryBuilder,
appendParentToGroupingOperator(scimFilterAst.attrPath, scimFilterAst.valFilter), appendParentToGroupingOperator(scimFilterAst.attrPath, scimFilterAst.valFilter),
getAttributeField getAttributeField,
depth + 1
); );
}); });
break; break;
+5 -1
View File
@@ -97,7 +97,11 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
message message
}); });
} else { } else {
void res.send(error); void res.status(HttpStatusCodes.InternalServerError).send({
statusCode: HttpStatusCodes.InternalServerError,
error: "InternalServerError",
message: "Something went wrong"
});
} }
}); });
}); });