TypeScript-Node-Starter icon indicating copy to clipboard operation
TypeScript-Node-Starter copied to clipboard

RepositoryNotFoundError w/ Express

Open chimon2000 opened this issue 6 years ago • 0 comments

I have a modified version of the express example that uses the latest version. When referencing the entity class

photos = await getEntityManager().getRepository(Photo).find()

I receive an error, however when using the entity string "Photo"

photos = await getEntityManager().getRepository("Photo").find()

everything works fine. This only occurs inside of the controller class. If I move the same code into the createConnection callback, everything works fine:

createConnection({
    ...configuration
})
    .then(connection => {
        const repo = getEntityManager().getRepository(Photo).find().then(console.log)

        // const app = express()
        // app.use(bodyParser.json())
        // routes.forEach(route => {
        //     app[route.method](route.path, (request: Request, response: Response, next: Function) => {
        //         route.action(request, response).then(() => next).catch(err => next(err))
        //     })
        // })
        // app.listen(3000)
    })

chimon2000 avatar Aug 19 '17 16:08 chimon2000