You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I understand correctly the problem is that your logic is asynchronous, but the most external layer expects it to be synchronous. The db.getConnection() function in users.ts returns a Promise, so your whole lambda handler will return a Promise, but the ApiHandler type cannot handle it.
At the time I created this project AWS Lambda did not support promises directly, but thankfully now it does, if you use the Node 8.10+ runtime. Basically you have two options:
Go with the callbacks. This is what you see in this project. In this case you have to wrap your underlying asynchronous logic to callbacks.
Change the handler syntax to this:
exports.myHandler=asyncfunction(event,context){// Do something, then return information to the caller. }
Unfortunately at the moment there is no example for this in the codebase.
I'm integrating TypeORM and I have encountered some problems, for example:
I created an entity(User)
and create user folder with this content:
users.zip
main problem is in users.ts, if I do getCustomRepository(UserRepository) I get
that is related to getConnection() or createConnection() before that getCustomRepository(UserRepository) for this I create a shared class:
function getConnection() here is async so it returns a promise and dont know how manage this on users.ts for export getUser endpoint.
const db: Database = new Database();
export const getUser: ApiHandler = db.getConnection().then((connection: Connection): ApiHandler => {
const repo: UserRepository = connection.getCustomRepository(UserRepository);
const service: UsersService = new UsersService(repo);
const controller: UsersController = new UsersController(service);
return controller.getUser;
});
So I get
The text was updated successfully, but these errors were encountered: