Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw87AlenBolatov
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Болатов Ален
hw87AlenBolatov
Commits
ecb79a32
Commit
ecb79a32
authored
Mar 14, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
populated album on get by id request
parent
9da4cf60
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
31 deletions
+67
-31
albums.ts
backend/src/routes/albums.ts
+44
-16
artist.ts
backend/src/routes/artist.ts
+23
-15
4028d8eb740639e19b9f9a7b43c818b5
backend/uploads/albums/4028d8eb740639e19b9f9a7b43c818b5
+0
-0
d182df4782e5b1d074caf1f4dbbfdc93
backend/uploads/albums/d182df4782e5b1d074caf1f4dbbfdc93
+0
-0
1714b1b30c45fa7dcb2470983501bbb9
backend/uploads/artists/1714b1b30c45fa7dcb2470983501bbb9
+0
-0
No files found.
backend/src/routes/albums.ts
View file @
ecb79a32
...
...
@@ -32,28 +32,56 @@ const Album = model<IAlbum>(
);
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
albums
=
await
Album
.
find
().
populate
<
{
artist
:
IArtist
}
>
(
'artist'
);
res
.
send
(
albums
);
if
(
!
req
.
query
.
artist
)
{
try
{
const
albums
=
await
Album
.
find
().
populate
<
{
artist
:
IArtist
}
>
(
'artist'
);
res
.
send
(
albums
);
return
;
}
catch
(
err
:
unknown
)
{
res
.
send
(
'Could not get albums'
);
}
}
try
{
const
artistsAlbums
=
await
Album
.
find
({
artist
:
req
.
query
.
artist
});
res
.
send
(
artistsAlbums
);
}
catch
(
err
:
unknown
)
{
res
.
send
(
`Could not find albums of
${
req
.
query
.
artist
}
`
);
}
});
router
.
get
(
'/:id'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
album
=
await
Album
.
findById
(
req
.
params
.
id
).
populate
<
{
artist
:
IArtist
;
}
>
(
'artist'
);
res
.
send
(
album
);
}
catch
(
err
:
unknown
)
{
res
.
send
(
'No such artist exists'
);
}
});
router
.
post
(
'/'
,
upload
.
single
(
'albumImage'
),
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
album
:
HydratedDocument
<
IAlbum
>
=
new
Album
({
name
:
req
.
body
.
name
,
albumImage
:
{
data
:
fs
.
readFileSync
(
path
.
join
(
'uploads/albums/'
+
req
.
file
?.
filename
)
),
contentType
:
'image'
,
},
year
:
req
.
body
.
year
,
artist
:
req
.
body
.
artist
,
});
await
album
.
save
();
res
.
send
(
'Sucessfully saved'
);
try
{
const
album
:
HydratedDocument
<
IAlbum
>
=
new
Album
({
name
:
req
.
body
.
name
,
albumImage
:
{
data
:
fs
.
readFileSync
(
path
.
join
(
'uploads/albums/'
+
req
.
file
?.
filename
)
),
contentType
:
'image'
,
},
year
:
req
.
body
.
year
,
artist
:
req
.
body
.
artist
,
});
await
album
.
save
();
res
.
send
(
'Sucessfully saved'
);
}
catch
(
err
:
unknown
)
{
res
.
send
(
'Could not post album'
);
}
}
);
...
...
backend/src/routes/artist.ts
View file @
ecb79a32
...
...
@@ -31,27 +31,35 @@ const artistSchema = new Schema<IArtist>({
const
Artist
=
model
<
IArtist
>
(
'Artist'
,
artistSchema
);
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
artists
=
await
Artist
.
find
();
res
.
send
(
artists
);
try
{
const
artists
=
await
Artist
.
find
();
res
.
send
(
artists
);
}
catch
(
err
:
unknown
)
{
res
.
send
(
'could not get artists'
);
}
});
router
.
post
(
'/'
,
upload
.
single
(
'image'
),
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
artist
:
HydratedDocument
<
IArtist
>
=
new
Artist
({
name
:
req
.
body
.
name
,
description
:
req
.
body
.
description
,
image
:
{
data
:
fs
.
readFileSync
(
path
.
join
(
'uploads/artists/'
+
req
.
file
?.
filename
)
),
contentType
:
'image'
,
},
});
await
artist
.
save
();
res
.
send
(
'Sucessfully saved'
);
try
{
const
artist
:
HydratedDocument
<
IArtist
>
=
new
Artist
({
name
:
req
.
body
.
name
,
description
:
req
.
body
.
description
,
image
:
{
data
:
fs
.
readFileSync
(
path
.
join
(
'uploads/artists/'
+
req
.
file
?.
filename
)
),
contentType
:
'image'
,
},
});
await
artist
.
save
();
res
.
send
(
'Sucessfully saved'
);
}
catch
(
err
:
unknown
)
{
res
.
send
(
'Could not post'
);
}
}
);
...
...
backend/uploads/albums/4028d8eb740639e19b9f9a7b43c818b5
0 → 100644
View file @
ecb79a32
File added
backend/uploads/albums/d182df4782e5b1d074caf1f4dbbfdc93
0 → 100644
View file @
ecb79a32
File added
backend/uploads/artists/1714b1b30c45fa7dcb2470983501bbb9
0 → 100644
View file @
ecb79a32
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment