type-money-plugin.js 404 B

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