-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
TransactionRepository.ts
27 lines (24 loc) · 1.06 KB
/
TransactionRepository.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {getMetadataArgsStorage} from "../../";
import {TransactionRepositoryMetadataArgs} from "../../metadata-args/TransactionRepositoryMetadataArgs";
import {CannotReflectMethodParameterTypeError} from "../../error/CannotReflectMethodParameterTypeError";
/**
* Injects transaction's repository into the method wrapped with @Transaction decorator.
*/
export function TransactionRepository(entityType?: Function): ParameterDecorator {
return (object: Object, methodName: string, index: number) => {
// get repository type
let repositoryType: Function;
try {
repositoryType = Reflect.getOwnMetadata("design:paramtypes", object, methodName)[index];
} catch (err) {
throw new CannotReflectMethodParameterTypeError(object.constructor, methodName);
}
getMetadataArgsStorage().transactionRepositories.push({
target: object.constructor,
methodName,
index,
repositoryType,
entityType,
} as TransactionRepositoryMetadataArgs);
};
}