type-money-plugin.js 325 B

123456789101112131415
  1. 'use strict';
  2. const { Decimal128 } = require('mongoose').Types;
  3. module.exports = exports = function metaPlugin(schema /* , options*/) {
  4. schema.add({
  5. money: {
  6. type: Decimal128,
  7. set(data) {
  8. return data;
  9. },
  10. get(data) {
  11. if (data) return data.toString() * 1;
  12. },
  13. },
  14. });
  15. };