Skip to content

Commit dda34f0

Browse files
fix linting test
now these may work on npm run lint and able to get merge
1 parent d689cbb commit dda34f0

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Diff for: server/models/user.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ userSchema.pre('save', function checkPassword(next) {
118118
userSchema.pre('save', function checkApiKey(next) {
119119
const user = this;
120120
if (!user.isModified('apiKeys')) {
121-
return next();
121+
next();
122+
return;
122123
}
123124

124125
let hasNew = false;
@@ -129,22 +130,28 @@ userSchema.pre('save', function checkApiKey(next) {
129130
if (nextCalled) return;
130131
if (err) {
131132
nextCalled = true;
132-
return next(new Error(err)); // ✅ Pass Error object
133+
next(err);
134+
return;
133135
}
134-
if (--pendingTasks === 0) {
136+
pendingTasks -= 1;
137+
if (pendingTasks === 0) {
135138
nextCalled = true;
136-
return next();
139+
next();
137140
}
138141
};
139142

140143
user.apiKeys.forEach((k) => {
141144
if (k.isNew) {
142145
hasNew = true;
143-
pendingTasks++;
146+
pendingTasks += 1;
144147
bcrypt.genSalt(10, (err, salt) => {
145-
if (err) return done(err);
148+
if (err) {
149+
done(err);
150+
}
146151
bcrypt.hash(k.hashedKey, salt, (innerErr, hash) => {
147-
if (innerErr) return done(innerErr);
152+
if (innerErr) {
153+
done(innerErr);
154+
}
148155
k.hashedKey = hash;
149156
done();
150157
});
@@ -153,7 +160,7 @@ userSchema.pre('save', function checkApiKey(next) {
153160
});
154161

155162
if (!hasNew) {
156-
return next();
163+
next();
157164
}
158165
});
159166

0 commit comments

Comments
 (0)