mirror of
https://github.com/strapi/strapi.git
synced 2025-07-21 07:57:45 +00:00

Use Decimal128 mongo's type instead mongoose-double package. Mongodb will be store decimal values as NumberDecimal, not as string.
52 lines
1.0 KiB
JavaScript
Executable File
52 lines
1.0 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
|
|
module.exports = mongoose => {
|
|
require('mongoose-float').loadType(mongoose);
|
|
|
|
const SchemaTypes = mongoose.Schema.Types;
|
|
|
|
SchemaTypes.Decimal.prototype.cast = function (value) {
|
|
return value.toString();
|
|
};
|
|
|
|
return {
|
|
convertType: mongooseType => {
|
|
switch (mongooseType.toLowerCase()) {
|
|
case 'string':
|
|
case 'password':
|
|
case 'text':
|
|
case 'email':
|
|
return 'String';
|
|
case 'integer':
|
|
case 'biginteger':
|
|
return 'Number';
|
|
case 'float':
|
|
return 'Float';
|
|
case 'decimal':
|
|
return 'Decimal';
|
|
case 'date':
|
|
case 'time':
|
|
case 'datetime':
|
|
case 'timestamp':
|
|
return Date;
|
|
case 'boolean':
|
|
return 'Boolean';
|
|
case 'binary':
|
|
return 'Buffer';
|
|
case 'uuid':
|
|
return 'ObjectId';
|
|
case 'enumeration':
|
|
return 'String';
|
|
case 'json':
|
|
return 'Mixed';
|
|
default:
|
|
|
|
}
|
|
}
|
|
};
|
|
};
|