git clone git@github.com:bitbybit/nodejs2024Q3-service.git
cp .env.example .env
LOG_LEVEL=debug
Possible values: log, error, warn, debug, verbose
docker-compose up -d
docker-compose exec app npm run migration:run
After starting the app on port (4000 as default) you can open
in your browser OpenAPI documentation by typing http://localhost:4000/doc/.
For more information about OpenAPI/Swagger please visit https://swagger.io/.
docker-compose exec app npm audit
After application running open new terminal and enter:
To run all tests without authorization
docker-compose exec app npm run test
To run only one of all test suites
docker-compose exec app npm run test -- <path to suite>
To run all test with authorization
docker-compose exec app npm run test:auth
To run only specific test suite with authorization
docker-compose exec app npm run test:auth -- <path to suite>
docker-compose exec app npm run lint
docker-compose exec app npm run format
Users can create, read, update, delete data about Artists, Tracks and Albums, add them to Favorites.
-
User:interface User { id: string; // uuid v4 login: string; password: string; version: number; // integer number, increments on update createdAt: number; // timestamp of creation updatedAt: number; // timestamp of last update }
-
Artist:interface Artist { id: string; // uuid v4 name: string; grammy: boolean; }
-
Track:interface Track { id: string; // uuid v4 name: string; artistId: string | null; // refers to Artist albumId: string | null; // refers to Album duration: number; // integer number }
-
Album:interface Album { id: string; // uuid v4 name: string; year: number; artistId: string | null; // refers to Artist }
-
Favorites:interface Favorites { artists: string[]; // favorite artists ids albums: string[]; // favorite albums ids tracks: string[]; // favorite tracks ids }
Details:
- For
Users,Artists,Albums,TracksandFavoritesREST endpoints with separate router paths
-
Users(/userroute)GET /user- get all users- Server answer with
status code200 and all users records
- Server answer with
GET /user/:id- get single user by id- Server answer with
status code200 and record withid === userIdif it exists - Server answer with
status code400 and corresponding message ifuserIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === userIddoesn't exist
- Server answer with
POST /user- create userCreateUserDtointerface CreateUserDto { login: string; password: string; }
- Server answer with
status code201 and newly created record if request is valid - Server answer with
status code400 and corresponding message if requestbodydoes not contain required fields
- Server answer with
PUT /user/:id- update user's passwordUpdatePasswordDto:interface UpdatePasswordDto { oldPassword: string; // previous password newPassword: string; // new password }
- Server answer with
status code200 and updated record if request is valid - Server answer with
status code400 and corresponding message ifuserIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === userIddoesn't exist - Server answer with
status code403 and corresponding message ifoldPasswordis wrong
- Server answer with
DELETE /user/:id- delete user- Server answer with
status code204 if the record is found and deleted - Server answer with
status code400 and corresponding message ifuserIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === userIddoesn't exist
- Server answer with
-
Tracks(/trackroute)GET /track- get all tracks- Server answer with
status code200 and all tracks records
- Server answer with
GET /track/:id- get single track by id- Server answer with
status code200 and record withid === trackIdif it exists - Server answer with
status code400 and corresponding message iftrackIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === trackIddoesn't exist
- Server answer with
POST /track- create new track- Server answer with
status code201 and newly created record if request is valid - Server answer with
status code400 and corresponding message if requestbodydoes not contain required fields
- Server answer with
PUT /track/:id- update track info- Server answer with
status code200 and updated record if request is valid - Server answer with
status code400 and corresponding message iftrackIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === trackIddoesn't exist
- Server answer with
DELETE /track/:id- delete track- Server answer with
status code204 if the record is found and deleted - Server answer with
status code400 and corresponding message iftrackIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === trackIddoesn't exist
- Server answer with
-
Artists(/artistroute)GET /artist- get all artists- Server answer with
status code200 and all artists records
- Server answer with
GET /artist/:id- get single artist by id- Server answer with
status code200 and record withid === artistIdif it exists - Server answer with
status code400 and corresponding message ifartistIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === artistIddoesn't exist
- Server answer with
POST /artist- create new artist- Server answer with
status code201 and newly created record if request is valid - Server answer with
status code400 and corresponding message if requestbodydoes not contain required fields
- Server answer with
PUT /artist/:id- update artist info- Server answer with
status code200 and updated record if request is valid - Server answer with
status code400 and corresponding message ifartistis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === artistIddoesn't exist
- Server answer with
DELETE /artist/:id- delete album- Server answer with
status code204 if the record is found and deleted - Server answer with
status code400 and corresponding message ifartistIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === artistIddoesn't exist
- Server answer with
-
Albums(/albumroute)GET /album- get all albums- Server answer with
status code200 and all albums records
- Server answer with
GET /album/:id- get single album by id- Server answer with
status code200 and record withid === albumIdif it exists - Server answer with
status code400 and corresponding message ifalbumIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === albumIddoesn't exist
- Server answer with
POST /album- create new album- Server answer with
status code201 and newly created record if request is valid - Server answer with
status code400 and corresponding message if requestbodydoes not contain required fields
- Server answer with
PUT /album/:id- update album info- Server answer with
status code200 and updated record if request is valid - Server answer with
status code400 and corresponding message ifalbumIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === albumIddoesn't exist
- Server answer with
DELETE /album/:id- delete album- Server answer with
status code204 if the record is found and deleted - Server answer with
status code400 and corresponding message ifalbumIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if record withid === albumIddoesn't exist
- Server answer with
-
FavoritesGET /favs- get all favorites- Server answer with
status code200 and all favorite records (not their ids), split by entity type:
interface FavoritesResponse{ artists: Artist[]; albums: Album[]; tracks: Track[]; }
- Server answer with
POST /favs/track/:id- add track to the favorites- Server answer with
status code201 and corresponding message if track withid === trackIdexists - Server answer with
status code400 and corresponding message iftrackIdis invalid (notuuid) - Server answer with
status code422 and corresponding message if track withid === trackIddoesn't exist
- Server answer with
DELETE /favs/track/:id- delete track from favorites- Server answer with
status code204 if the track was in favorites and now it's deleted id is found and deleted - Server answer with
status code400 and corresponding message iftrackIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if corresponding track is not favorite
- Server answer with
POST /favs/album/:id- add album to the favorites- Server answer with
status code201 and corresponding message if album withid === albumIdexists - Server answer with
status code400 and corresponding message ifalbumIdis invalid (notuuid) - Server answer with
status code422 and corresponding message if album withid === albumIddoesn't exist
- Server answer with
DELETE /favs/album/:id- delete album from favorites- Server answer with
status code204 if the album was in favorites and now it's deleted id is found and deleted - Server answer with
status code400 and corresponding message ifalbumIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if corresponding album is not favorite
- Server answer with
POST /favs/artist/:id- add artist to the favorites- Server answer with
status code201 and corresponding message if artist withid === artistIdexists - Server answer with
status code400 and corresponding message ifartistIdis invalid (notuuid) - Server answer with
status code422 and corresponding message if artist withid === artistIddoesn't exist
- Server answer with
DELETE /favs/artist/:id- delete artist from favorites- Server answer with
status code204 if the artist was in favorites and now it's deleted id is found and deleted - Server answer with
status code400 and corresponding message ifartistIdis invalid (notuuid) - Server answer with
status code404 and corresponding message if corresponding artist is not favorite
- Server answer with
-
Signup(auth/signuproute)POST auth/signup- sendloginandpasswordto create a newuser- Server answer with
status code201 and corresponding message if dto is valid - Server answer with
status code400 and corresponding message if dto is invalid (nologinorpassword, or they are not astrings)
- Server answer with
-
Login(auth/loginroute)POST auth/login- sendloginandpasswordto get Access token and Refresh token (optionally)- Server answer with
status code200 and tokens if dto is valid - Server answer with
status code400 and corresponding message if dto is invalid (nologinorpassword, or they are not astrings) - Server answer with
status code403 and corresponding message if authentication failed (no user with suchlogin,passworddoesn't match actual one, etc.)
- Server answer with
-
Refresh(auth/refreshroute)POST auth/refresh- send refresh token in body as{ refreshToken }to get a new pair of Access token and Refresh token- Server answer with
status code200 and tokens in body if dto is valid - Server answer with
status code401 and corresponding message if dto is invalid (norefreshTokenin body) - Server answer with
status code403 and corresponding message if authentication failed (Refresh token is invalid or expired)
- Server answer with