# [TIL] Nest.js Repository Layer Setup Troubleshooting

## 📌 Issues encountered

### Issue #1

I encountered an error message stating that the functions defined in the repository were not found, even though I injected the repository as a dependency in Nest.js.

![](https://velog.velcdn.com/images/c1madang/post/f6d1f9e7-5d97-4460-ac42-a15c0a957ecb/image.png align="left")

## 📌 What I tried

### Issue #1

"EntityRepository is deprecated": This error occurred because the `@EntityRepository()` decorator I was using is deprecated in TypeORM 0.3.x.

#### Solution 1: Create a custom decorator to replace the deprecated EntityRepository decorator

* Reference: [Stack Overflow - How to work around this TypeORM error - EntityRepository is deprecated, use Repo](https://stackoverflow.com/questions/71557301/how-to-workraound-this-typeorm-error-entityrepository-is-deprecated-use-repo)
    

1. The reference suggests running `npm install @nestjs/typeorm@next`, but it resulted in the following error and was not necessary.
    
    ![](https://velog.velcdn.com/images/c1madang/post/5bc2f975-5332-4b6c-8467-a8146e1b9cb5/image.png align="left")
    
2. I followed the steps mentioned in the link, which involved creating a custom decorator.
    

#### Solution 2: Implement a Custom Repository by Inheriting the Repository Provided by TypeORM

This method is simpler and does not require additional files to be created.

* Reference: [TypeORM Custom Repository Solution](https://hou27.tistory.com/entry/TypeORM-Custom-Repository-%EA%B0%9C%EC%84%A0%EC%95%88) & [Stack Overflow - How to do custom repository using TypeORM (MongoDB) in Nest.js](https://stackoverflow.com/questions/72549668/how-to-do-custom-repository-using-typeorm-mongodb-in-nestjs)
    

According to the [official documentation](https://docs.nestjs.com/recipes/sql-typeorm#:~:text=Now%20we%20can%20inject%20the%20Repository%3CPhoto%3E%20to%20the%20PhotoService%20using%20the%20%40Inject()%20decorator%3A), we can define a Repository provider and inject it into the service using `@Inject()`. However, I believe it would be more effective to separate the repository file since it seems that the service would end up using database-related queries. Therefore, it would be better to proceed with the second solution in my project.
