Server runs on http://localhost:3001
Users Module():
@Controller('users')
@Post() // creates a user instance
@Get() // returns all the available users
@Get(':id') // return a user with id
@Patch(':id') // edit a user with id
@Delete(':id') // delete a user with idAuth Module():
@Controller('auth')
@Post('login) //if the user exists, generates a token using Jwt using passportjs
// Jwt is included in the Bearer of the AuthHeader
@Get() // uses Jwt guards which checks for an existing tokenCategories Module():
@Controller('categories')
@Post() // creates a category instance
@Get() // returns all the available categories with the corresponding products to each category
@Get(':id') // return a category with id with the corresponding products
@Patch(':id') // edit a category with id
@Delete(':id') // delete a category with idProducts Module():
@Controller('products')
//each request includes @UseGuards(JwtAuthGuard) to verify the existing token, otherwise return error 401
@Post() // creates a product instance
@Get() // returns all the available products to the current user as well as the id of the category
@Get(':id') // return an existing product but only if it belongs to the user
@Patch(':id') // edit a product if it belongs to the logged user
@Delete(':id') // delete a product if it belongs to the logged user
@Get('byCategory/:category_id) // returns all the products that fall into a certain category belonging to the logged user
//Note : the id of each category must be handled on the FrontEnd using mapper @Post() does not take any parameters @Get(':id'), @Patch(':id'), @Delete(':id') - they take @Param('id') to handle the unique route for each separate instance
@Post('login') takes @Req() req:Request which returns the access token @Get() takes @Req() req:Request which returns information about the user
@Post() does not take any parameters @Get(':id'), @Patch(':id'), @Delete(':id') - they take @Param('id') to handle the unique route for each separate instance
Every CRUD request has @Req() req: Request which includes the decoded information about the user (id, email, exp,iat)
@Post() does not take any parameters
@Get(':id'),
@Patch(':id'),
@Delete(':id') - they take @Param('id') to handle the unique route for each separate instance
@Get('byCategory/:category_id') - it take @Param('category_id) - to handle each unique category route
mainly for hadnling errors, but also to handle asynschronously response more efficiently using the fact that observable executes when it is subscribed to and not immediately when it is handled in the body of the function(unlike a Promise)
- if a value is needed, we use map
- if an Observable needs to be returned,we use mergeMap( e.g for UpdateResult from typeorm)
- if more a value is returned, then we use of() for the return
- if an array or other iterable type is returned, we use from()
and only if the email exist then
If both the credentials are verified properly an access token is signed
Includes the information about the postgreSql db
Both are being executed beforehand so that given that the database is reached before the timeout of 30s , the docker-compose could start ensuring no errors ocuurring