A basic, not data-persistence repository that aims to serve as a starting point for further development of nestjs-based REST API projects
Use this repo as your starting point for your next NestJS REST API project. For example you can use it and add database persistence by connecting and using your favorite Database e.g. MongoDB, MySQL/MariaDB, PostgreSQL, MS SQL Server, Oracle, etc.
The repo’s key points are summarized as follows:
-
The repo (as in the NestJS Documentation) already includes both the AuthModule and the UsersModule respectively, as well as their Controller and Service classes.
-
Instead of using the UsersService for the basic CRUD operations, the repo uses a separate solo @injectable class, the DbRepo. It serves both the AuthService and the UsersService. [You can read how to use a solo @injectable class as a singleton Provider at my post here and/or here]
-
The DbRepo provides the necessary methods for the CRUD operations. It gets the users’ data from the UsersDB. UsersDB is not persisted. It just contains a couple of users in an array who have been pre-set in the UsersDB class.
-
class-validator and class-transformer packages are installed. DTOs and entities are defined in the src/dataObjects folder, and they are decorated accordingly. [See more here and/or here]
-
The repo uses externally defined variables, so the @nestjs/config package is already installed, and it is declared globally in AppModule. The external variables are defined in the src/config/.env.dev file. [See more here and/or here]
-
Also, the repo uses the Joi schema validation tool (which is also is being used in NestJS Documentation for object schema validation). Moreover, a JSON object schema validator has been defined and decorated (using the appropriate Joi property decorators) in the src/config/config.schema.ts file. It is being used for the externally defined variables in the src/config/.env.dev file.
-
The repo has defined and uses (via AuthController and UsersController) the following endpoints:
- /auth/signup
- /auth/signin
- /users/
- /users?
- /users/:id/
-
Also, note that the /tickets Global Prefix is being used, so for accessing users, you have to use: http://localhost:3000/tickets/users
-
Finally, it uses the Passport package, uses JSON Web Tokens – JWT, and implements the Passport’s JWT strategy (as it is described in the post mentioned before)
You can clone this repo by:
git clone https://github.com/zzpzaf/NestJS-Rest-API-basic1.git