53 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-07-14 11:06:58 +02:00
'use strict';
/**
* Module dependencies
*/
2016-07-14 12:15:42 +02:00
module.exports = mongoose => {
require('mongoose-float').loadType(mongoose);
const SchemaTypes = mongoose.Schema.Types;
2016-07-14 11:06:58 +02:00
// Note: The decimal format isn't well supported by MongoDB.
// It's recommended to use Float or Number type instead.
//
// SchemaTypes.Decimal.prototype.cast = function (value) {
// return value.toString();
// };
2016-07-14 11:06:58 +02:00
return {
2016-07-14 12:15:42 +02:00
convertType: mongooseType => {
2016-07-14 11:06:58 +02:00
switch (mongooseType.toLowerCase()) {
case 'boolean':
2016-09-28 11:42:26 +02:00
return 'Boolean';
2016-07-14 11:06:58 +02:00
case 'binary':
return 'Buffer';
2018-03-17 16:42:28 +00:00
case 'date':
case 'datetime':
case 'time':
case 'timestamp':
return Date;
case 'decimal':
case 'float':
return 'Float';
case 'json':
return 'Mixed';
case 'biginteger':
case 'integer':
return 'Number';
2016-07-14 11:06:58 +02:00
case 'uuid':
return 'ObjectId';
2018-03-17 16:42:28 +00:00
case 'email':
2016-07-14 11:06:58 +02:00
case 'enumeration':
2018-03-17 16:42:28 +00:00
case 'password':
case 'string':
case 'text':
2016-07-14 11:06:58 +02:00
return 'String';
default:
}
}
2016-09-28 11:42:26 +02:00
};
};