#Weird DB Find Record Problem
10 messages · Page 1 of 1 (latest)
This endpoint is for downloading a file and creating a record of it in the db.
Find User - this is simply to validate the cookie JWT and expiration date. check.
Find Project - the params include a domain, with the below find is being used to locate the project.
// working
console.log('domain: ', data.domain);
// not working
const project = await this.projectRepository.findOne({
where: {
domain: data.domain
}
});
When I log the domain into the console, it prints correctly. But when I use it in the where clause, it returns a "null" value for the project. It doesn't make sense why.
The service file has the correct injectables:
constructor(
@InjectRepository(Account)
private accountRepository: Repository<Account>,
@InjectRepository(File)
private fileRepository: Repository<File>,
@InjectRepository(Project)
private projectRepository: Repository<Project>,
private jwt: JwtService
) {}
The user search works fine:
// use token data to find user account
const user = await this.accountRepository.findOne({
where: {
email: decodedToken.email
},
relations: {
projects: true
}
});
Only when I bring in the project do I get an error. The console logs this out as well.
domain: carbondigital.us
create file for project: null
[Nest] 35410 - 10/11/2022, 1:03:03 AM ERROR [ExceptionsHandler] Cannot read properties of null (reading 'id')
TypeError: Cannot read properties of null (reading 'id')
In order to create the file record in the DB, I need to get the project details as it's a relation field. Also, the file being saved in the DB contain the project's ID.
Any ideas out there? I've never seen this type of problem below. The first findOne works, but not the second one.
Still working to find a resolution on this one. I tried searching the net for anyone else who might have seen this problem. So far, no luck finding it.
Has anyone here had this problem before? Or maybe know what is going on?