I am trying to create a method in my credentials service file that needs to access the method from another class called CredentialsDao
like so:
disableOneTimeCredentials() {
const emailAndOneTimeToken = CredentialsDao.findOneTimeTokenCredentialsByEmail()
}
This is whats generating that error:
The credentials dao file looks like so:
export class CredentialsDao {
constructor() {
this.findOneTimeTokenCredentialsByEmail = this.findOneTimeTokenCredentialsByEmail.bind(this)
}
async findOneTimeTokenCredentialsByEmail(email: string): Promise<ICredential> {
return this.Model.findOne({
email: email,
credentialType: CredentialType.oneTimeToken,
$or: [
{
disabledOn: null
},
// {
// disabledOn: {
// $exists: false // hangs or return nothing... why?
// }
// },
{
disabledOn: {
$exists: true,
$ne: null,
$gt: new Date()
}
}
]
})
}
}
And yes I did import the file.
CodePudding user response:
You are trying to access the static members.
CredentialsDao.findOneTimeTokenCredentialsByEmail();
but the method is not marked as static
async findOneTimeTokenCredentialsByEmail(email: string): Promise<ICredential>
// static modifier
static async findOneTimeTokenCredentialsByEmail(email: string): Promise<ICredential>
Don't think you will be able to use this
and reference non-static properties within the static
method.
Perhaps an oversight, but will work if you create a new instance:
const service = new CredentialsDao();
service.findOneTimeTokenCredentialsByEmail('[email protected]');