1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const typeorm_1 = require("typeorm");
|
4 | const typeorm_utils_1 = require("./common/typeorm.utils");
|
5 | function createTypeOrmProviders(entities, connection) {
|
6 | return (entities || []).map(entity => ({
|
7 | provide: typeorm_utils_1.getRepositoryToken(entity, connection),
|
8 | useFactory: (connection) => {
|
9 | if (entity.prototype instanceof typeorm_1.Repository ||
|
10 | entity.prototype instanceof typeorm_1.AbstractRepository) {
|
11 | return connection.getCustomRepository(entity);
|
12 | }
|
13 | return connection.options.type === 'mongodb'
|
14 | ? connection.getMongoRepository(entity)
|
15 | : connection.getRepository(entity);
|
16 | },
|
17 | inject: [typeorm_utils_1.getConnectionToken(connection)],
|
18 | }));
|
19 | }
|
20 | exports.createTypeOrmProviders = createTypeOrmProviders;
|