Skip to content

Commit

Permalink
Merge pull request #461 from CyberT33N/main
Browse files Browse the repository at this point in the history
Added option updateDeep
  • Loading branch information
florianholzapfel authored Apr 22, 2024
2 parents 86e5447 + 579de66 commit 23ac918
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/express-restify-mongoose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const defaultOptions: Omit<Options, "contextFilter" | "outputFn" | "onError"> =
preRead: [],
preUpdate: [],
preDelete: [],
updateDeep: true,
};

const filter = new Filter();
Expand Down
7 changes: 6 additions & 1 deletion src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function operations(
| "runValidators"
| "totalCountHeader"
| "upsert"
| "updateDeep"
>,
filter: Filter
) {
Expand Down Expand Up @@ -324,7 +325,11 @@ export function operations(
return dst;
}

const cleanBody = moredots(depopulate(req.body));
let cleanBody = depopulate(req.body);

if (options.updateDeep) {
cleanBody = moredots(cleanBody);
}

if (options.findOneAndUpdate) {
options.contextFilter(contextModel, req, (filteredContext) => {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type Options = {
preRead: RequestHandler | RequestHandler[];
preUpdate: RequestHandler | RequestHandler[];
preDelete: RequestHandler | RequestHandler[];
updateDeep: boolean;
access?: (req: Request) => Access | Promise<Access>;
contextFilter: (
model: mongoose.Model<unknown>,
Expand Down

0 comments on commit 23ac918

Please sign in to comment.