Closed argupta23 closed 1 year ago
I think a possible way to get around the issue is to do the following
constructor(
@inject("DeviceRepository")
private deviceRepository: Repository????
) {}
or
private deviceRepository = container.resolve(Repository ????);
what would the syntax for Repository be?
Thanks
Repository in Redis OM is just a class. It's not doing anything that terribly interesting, at least not interesting in the sense that it would affect the scope of this
. I don't believe this error has anything to do with Redis OM, primarily because the error you are receiving is complaining that the value of this
is undefined. Redis OM hasn't had a chance to do anything yet.
My guess—and I've never heard of tsyringe beyond a quick google 2 minutes ago—is that you need to inject an instantiated Repository into your Controller. But I have no expertise here. I don't know how it works. I've just used DI frameworks in the last 20 years. ;)
Regardless, do you think this is an error with Redis OM or are you just looking for some help with a third-party library? If the former, I think I need more proof. If the latter, it might be better asked elsewhere.
I will say that the library looks interesting and I may well check it out when I get some time.
I think there are issues with tsyring in typescript 5 because of some decorators changes in version 5, check issues in tsyring.
thanks for the responses. @alan-pg
I am still using typescript 4 in my case.
@guyroyse
I am in the process of removing "tsyringe", but have a question for you.
In the current implementation I have the schema defined in a *.model.ts and then within my controller I use the following lines
save
let redisW = await new Repository(DeviceSchemaR, redisClient).save(tplateJson.id, tplateJson);
get
let redisO = new Repository(DeviceSchemaR, redisClient);
await redisO.createIndex(); <-- is this the right place for this call?
let redisOResp = await redisO.search().where('tntid').equals(tntid).and('userId').equals(uid).return.all();
While this works, can you please let me know if this is the right way or should I be doing this differently?
More specifically the "createIndex()"?
Appreciate the guidance.
What I typically do it define a Schema and Repository in a separate module. In that module I export the Repository and call .createIndex()
.
Like this:
import { redisClient } from './client'.
const deviceSchema = new Schema(...stuff goes here...)
export const deviceRepository = new Repository(deviceSchema, redisClient)
await deviceRepository.createIndex()
I also use a separate module to create and export the Node Redis client which you see in the first line of my code.
Then, I can just import the redisClient or the deviceRepository as needed.
I am using Tsyringe in my controller along with Express4
My controller code looks something like this
When we hit the last line it results in the below error and is true for both the cases
breakpoint within the code indicates that "this" is undefined.
Additionally my tsconfig.json contains
Any guidance on how to solve this is greatly appreciated
Thanks