Skip to content

Commit 49804ed

Browse files
fix failing tests
1 parent 9537974 commit 49804ed

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

lib/schema/int32.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,56 @@ SchemaInt32.prototype.cast = function(value) {
194194
}
195195
};
196196

197+
/*!
198+
* ignore
199+
*/
200+
201+
SchemaInt32.$conditionalHandlers = {
202+
...SchemaType.prototype.$conditionalHandlers,
203+
$gt: handleSingle,
204+
$gte: handleSingle,
205+
$lt: handleSingle,
206+
$lte: handleSingle
207+
};
208+
209+
/*!
210+
* ignore
211+
*/
212+
213+
function handleSingle(val, context) {
214+
return this.castForQuery(null, val, context);
215+
}
216+
217+
/**
218+
* Casts contents for queries.
219+
*
220+
* @param {String} $conditional
221+
* @param {any} val
222+
* @api private
223+
*/
224+
225+
SchemaInt32.prototype.castForQuery = function($conditional, val, context) {
226+
let handler;
227+
if ($conditional != null) {
228+
handler = SchemaInt32.$conditionalHandlers[$conditional];
229+
230+
if (handler) {
231+
return handler.call(this, val);
232+
}
233+
234+
return this.applySetters(null, val, context);
235+
}
236+
237+
try {
238+
return this.applySetters(val, context);
239+
} catch (err) {
240+
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
241+
err.path = this.$fullPath;
242+
}
243+
throw err;
244+
}
245+
};
246+
197247

198248
/*!
199249
* Module exports.

0 commit comments

Comments
 (0)