git clone [email protected]: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
,Tracks
andFavorites
REST endpoints with separate router paths
-
Users
(/user
route)GET /user
- get all users- Server answer with
status code
200 and all users records
- Server answer with
GET /user/:id
- get single user by id- Server answer with
status code
200 and record withid === userId
if it exists - Server answer with
status code
400 and corresponding message ifuserId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === userId
doesn't exist
- Server answer with
POST /user
- create userCreateUserDto
interface CreateUserDto { login: string; password: string; }
- Server answer with
status code
201 and newly created record if request is valid - Server answer with
status code
400 and corresponding message if requestbody
does 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 code
200 and updated record if request is valid - Server answer with
status code
400 and corresponding message ifuserId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === userId
doesn't exist - Server answer with
status code
403 and corresponding message ifoldPassword
is wrong
- Server answer with
DELETE /user/:id
- delete user- Server answer with
status code
204 if the record is found and deleted - Server answer with
status code
400 and corresponding message ifuserId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === userId
doesn't exist
- Server answer with
-
Tracks
(/track
route)GET /track
- get all tracks- Server answer with
status code
200 and all tracks records
- Server answer with
GET /track/:id
- get single track by id- Server answer with
status code
200 and record withid === trackId
if it exists - Server answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === trackId
doesn't exist
- Server answer with
POST /track
- create new track- Server answer with
status code
201 and newly created record if request is valid - Server answer with
status code
400 and corresponding message if requestbody
does not contain required fields
- Server answer with
PUT /track/:id
- update track info- Server answer with
status code
200 and updated record if request is valid - Server answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === trackId
doesn't exist
- Server answer with
DELETE /track/:id
- delete track- Server answer with
status code
204 if the record is found and deleted - Server answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === trackId
doesn't exist
- Server answer with
-
Artists
(/artist
route)GET /artist
- get all artists- Server answer with
status code
200 and all artists records
- Server answer with
GET /artist/:id
- get single artist by id- Server answer with
status code
200 and record withid === artistId
if it exists - Server answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === artistId
doesn't exist
- Server answer with
POST /artist
- create new artist- Server answer with
status code
201 and newly created record if request is valid - Server answer with
status code
400 and corresponding message if requestbody
does not contain required fields
- Server answer with
PUT /artist/:id
- update artist info- Server answer with
status code
200 and updated record if request is valid - Server answer with
status code
400 and corresponding message ifartist
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === artistId
doesn't exist
- Server answer with
DELETE /artist/:id
- delete album- Server answer with
status code
204 if the record is found and deleted - Server answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === artistId
doesn't exist
- Server answer with
-
Albums
(/album
route)GET /album
- get all albums- Server answer with
status code
200 and all albums records
- Server answer with
GET /album/:id
- get single album by id- Server answer with
status code
200 and record withid === albumId
if it exists - Server answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === albumId
doesn't exist
- Server answer with
POST /album
- create new album- Server answer with
status code
201 and newly created record if request is valid - Server answer with
status code
400 and corresponding message if requestbody
does not contain required fields
- Server answer with
PUT /album/:id
- update album info- Server answer with
status code
200 and updated record if request is valid - Server answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === albumId
doesn't exist
- Server answer with
DELETE /album/:id
- delete album- Server answer with
status code
204 if the record is found and deleted - Server answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if record withid === albumId
doesn't exist
- Server answer with
-
Favorites
GET /favs
- get all favorites- Server answer with
status code
200 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 code
201 and corresponding message if track withid === trackId
exists - Server answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server answer with
status code
422 and corresponding message if track withid === trackId
doesn't exist
- Server answer with
DELETE /favs/track/:id
- delete track from favorites- Server answer with
status code
204 if the track was in favorites and now it's deleted id is found and deleted - Server answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server answer with
status code
404 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 code
201 and corresponding message if album withid === albumId
exists - Server answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server answer with
status code
422 and corresponding message if album withid === albumId
doesn't exist
- Server answer with
DELETE /favs/album/:id
- delete album from favorites- Server answer with
status code
204 if the album was in favorites and now it's deleted id is found and deleted - Server answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server answer with
status code
404 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 code
201 and corresponding message if artist withid === artistId
exists - Server answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server answer with
status code
422 and corresponding message if artist withid === artistId
doesn't exist
- Server answer with
DELETE /favs/artist/:id
- delete artist from favorites- Server answer with
status code
204 if the artist was in favorites and now it's deleted id is found and deleted - Server answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server answer with
status code
404 and corresponding message if corresponding artist is not favorite
- Server answer with
-
Signup
(auth/signup
route)POST auth/signup
- sendlogin
andpassword
to create a newuser
- Server answer with
status code
201 and corresponding message if dto is valid - Server answer with
status code
400 and corresponding message if dto is invalid (nologin
orpassword
, or they are not astrings
)
- Server answer with
-
Login
(auth/login
route)POST auth/login
- sendlogin
andpassword
to get Access token and Refresh token (optionally)- Server answer with
status code
200 and tokens if dto is valid - Server answer with
status code
400 and corresponding message if dto is invalid (nologin
orpassword
, or they are not astrings
) - Server answer with
status code
403 and corresponding message if authentication failed (no user with suchlogin
,password
doesn't match actual one, etc.)
- Server answer with
-
Refresh
(auth/refresh
route)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 code
200 and tokens in body if dto is valid - Server answer with
status code
401 and corresponding message if dto is invalid (norefreshToken
in body) - Server answer with
status code
403 and corresponding message if authentication failed (Refresh token is invalid or expired)
- Server answer with