Skip to content

Commit

Permalink
properly handle user prehooks for role updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Baalmart committed Dec 2, 2024
1 parent ae4579e commit f093cd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/auth-service/models/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ NetworkSchema.pre(
const query = this.getQuery ? this.getQuery() : { _id: this._id };

// Get the correct tenant-specific model
const tenant = this.tenant || constants.DEFAULT_TENANT;
const tenant = this.tenant || constants.DEFAULT_TENANT || "airqo";
const Network = getModelByTenant(tenant, "network", NetworkSchema);

const existingDoc = await Network.findOne(query);
Expand Down
6 changes: 5 additions & 1 deletion src/auth-service/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ UserSchema.pre(
// Helper function to handle role updates
const handleRoleUpdates = async (fieldName, idField) => {
const query = this.getQuery ? this.getQuery() : { _id: this._id };
const doc = await this.model.findOne(query);

// Get the correct tenant-specific model
const tenant = this.tenant || constants.DEFAULT_TENANT || "airqo";
const User = getModelByTenant(tenant, "user", UserSchema);
const doc = await User.findOne(query);

Check warning on line 264 in src/auth-service/models/User.js

View check run for this annotation

Codecov / codecov/patch

src/auth-service/models/User.js#L263-L264

Added lines #L263 - L264 were not covered by tests
if (!doc) return;

let newRoles = [];
Expand Down

0 comments on commit f093cd6

Please sign in to comment.