Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

map.js 890B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. /*!
  3. * ignore
  4. */
  5. const MongooseMap = require('../types/map');
  6. const SchemaType = require('../schematype');
  7. /*!
  8. * ignore
  9. */
  10. class Map extends SchemaType {
  11. constructor(key, options) {
  12. super(key, options, 'Map');
  13. this.$isSchemaMap = true;
  14. }
  15. cast(val, doc, init) {
  16. if (val instanceof MongooseMap) {
  17. return val;
  18. }
  19. if (init) {
  20. const map = new MongooseMap({}, this.path, doc, this.$__schemaType);
  21. if (val instanceof global.Map) {
  22. for (const key of val.keys()) {
  23. map.$init(key, map.$__schemaType.cast(val.get(key), doc, true));
  24. }
  25. } else {
  26. for (const key of Object.keys(val)) {
  27. map.$init(key, map.$__schemaType.cast(val[key], doc, true));
  28. }
  29. }
  30. return map;
  31. }
  32. return new MongooseMap(val, this.path, doc, this.$__schemaType);
  33. }
  34. }
  35. module.exports = Map;