mirror of
https://github.com/aditama-labs/nest-autocrud.git
synced 2024-11-24 04:46:21 +00:00
fix: entities not found
This commit is contained in:
parent
3450fd026a
commit
7424b38798
@ -9,5 +9,5 @@ export interface TypeORMModuleOptions<T extends ObjectLiteral> {
|
||||
processRead?;
|
||||
processUpdate?;
|
||||
synchronize?: boolean;
|
||||
entities?: string[];
|
||||
entities?: any[];
|
||||
}
|
||||
|
@ -1,8 +1,3 @@
|
||||
import { DynamicModule, Module } from '@nestjs/common';
|
||||
import { DataSource, ObjectLiteral } from 'typeorm';
|
||||
import { TYPEORM_DATASOURCE, TYPEORM_REPOSITORY } from './constants';
|
||||
import { TypeORMModuleOptions } from './interfaces';
|
||||
import { TypeORMService } from './typeorm.service';
|
||||
import {
|
||||
CREATE_PROCESS,
|
||||
DELETE_PROCESS,
|
||||
@ -11,6 +6,10 @@ import {
|
||||
READ_PROCESS,
|
||||
UPDATE_PROCESS,
|
||||
} from '@aditama-labs/nest-autocrud/skeleton';
|
||||
import { DynamicModule, Module } from '@nestjs/common';
|
||||
import { DataSource, ObjectLiteral } from 'typeorm';
|
||||
import { TYPEORM_DATASOURCE, TYPEORM_REPOSITORY } from './constants';
|
||||
import { TypeORMModuleOptions } from './interfaces';
|
||||
import {
|
||||
TypeORMCreateProcess,
|
||||
TypeORMDeleteProcess,
|
||||
@ -19,7 +18,7 @@ import {
|
||||
TypeORMReadProcess,
|
||||
TypeORMUpdateProcess,
|
||||
} from './processes';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { TypeORMService } from './typeorm.service';
|
||||
|
||||
const getDatabaseCredential = (
|
||||
synchronize?: boolean,
|
||||
@ -27,11 +26,6 @@ const getDatabaseCredential = (
|
||||
): any => {
|
||||
const url = new URL(process.env.DATABASE_URL);
|
||||
|
||||
let entityList = [__dirname + '/../**/*.entity{.ts,.js}'];
|
||||
if (entities) {
|
||||
entityList = entities;
|
||||
}
|
||||
|
||||
const defaultProtocol = url.protocol.substring(0, url.protocol.length - 1);
|
||||
let protocol = defaultProtocol;
|
||||
switch (defaultProtocol) {
|
||||
@ -56,7 +50,7 @@ const getDatabaseCredential = (
|
||||
username: username,
|
||||
password: password,
|
||||
database: databaseName,
|
||||
entities: entityList,
|
||||
entities,
|
||||
synchronize: synchronize ?? false,
|
||||
};
|
||||
};
|
||||
@ -93,7 +87,10 @@ export class TypeORMModule {
|
||||
provide: TYPEORM_DATASOURCE,
|
||||
useFactory: async () => {
|
||||
const dataSource = new DataSource(
|
||||
getDatabaseCredential(options.synchronize, options.entities),
|
||||
getDatabaseCredential(options.synchronize, [
|
||||
options.entity,
|
||||
...(options.entities ?? []),
|
||||
]),
|
||||
);
|
||||
return dataSource.initialize();
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('account')
|
||||
export class UserEntity {
|
||||
|
Loading…
Reference in New Issue
Block a user