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.
		
		
		
		
		
			
		
			
				
					
					
						
							25 lines
						
					
					
						
							775 B
						
					
					
				
			
		
		
	
	
							25 lines
						
					
					
						
							775 B
						
					
					
				| 'use strict';
 | |
| 
 | |
| const getDiscriminatorByValue = require('./getDiscriminatorByValue');
 | |
| 
 | |
| /*!
 | |
|  * Find the correct constructor, taking into account discriminators
 | |
|  */
 | |
| 
 | |
| module.exports = function getConstructor(Constructor, value) {
 | |
|   const discriminatorKey = Constructor.schema.options.discriminatorKey;
 | |
|   if (value != null &&
 | |
|       Constructor.discriminators &&
 | |
|       value[discriminatorKey] != null) {
 | |
|     if (Constructor.discriminators[value[discriminatorKey]]) {
 | |
|       Constructor = Constructor.discriminators[value[discriminatorKey]];
 | |
|     } else {
 | |
|       const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[discriminatorKey]);
 | |
|       if (constructorByValue) {
 | |
|         Constructor = constructorByValue;
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   return Constructor;
 | |
| }; |