Im using TypeORM to connect to postgresql database in nodeJS. Im getting this weird issue where:
public static async organizationRelations(name){
let connection = getConnection();
const org = await connection.getRepository(Organization).find({
where:[{name: name}]
});
return org;
}
works but this:
public static async importOrganizations(body){
let connection = getConnection();
let objs = {};
let o = await connection.getRepository(Organization).save(this.createObjects(body, objs));
}
doesent.
For the method with save i keep getting error RepositoryNotFoundError: No repository for "Organization" was found. Looks like this entity is not registered in current "default" connection?
Why is it working in one function but not in another?
I got it working by doing this in mu App.ts
private async databaseConnection(){
await createConnection(options).then(connection =>{
this.express.emit("app_started");
});
}
The issue was that i was using chai tests and the test started before app was fully initialized.