File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 11export * from './prop.decorator' ;
22export * from './schema.decorator' ;
3+ export * from './virtual.decorator' ;
Original file line number Diff line number Diff line change 1+ import { VirtualTypeOptions } from 'mongoose' ;
2+ import { TypeMetadataStorage } from '../storages/type-metadata.storage' ;
3+
4+ /**
5+ * Interface defining property options that can be passed to `@Virtual()` decorator.
6+ */
7+ export interface VirtualOptions {
8+ options ?: VirtualTypeOptions ;
9+ subPath ?: string ;
10+ get ?: ( ...args : any [ ] ) => any ;
11+ set ?: ( ...args : any [ ] ) => any ;
12+ }
13+
14+ /**
15+ * @Virtual decorator is used to mark a specific class property as a Mongoose virtual.
16+ */
17+ export function Virtual ( options ?: VirtualOptions ) : PropertyDecorator {
18+ return ( target : object , propertyKey : string | symbol ) => {
19+ TypeMetadataStorage . addVirtualMetadata ( {
20+ target : target . constructor ,
21+ options : options ?. options ,
22+ name :
23+ propertyKey . toString ( ) +
24+ ( options ?. subPath ? `.${ options . subPath } ` : '' ) ,
25+ setter : options ?. set ,
26+ getter : options ?. get ,
27+ } ) ;
28+ } ;
29+ }
You can’t perform that action at this time.
0 commit comments