Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
Homework_89_Tsoy_Danil
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
Цой Данил
Homework_89_Tsoy_Danil
Commits
bc729e6b
Commit
bc729e6b
authored
Mar 23, 2023
by
Цой Данил
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6
added all validations to models
parent
0fd51a75
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
20 deletions
+36
-20
Album.ts
src/models/Album.ts
+9
-5
Artist.ts
src/models/Artist.ts
+10
-3
Track.ts
src/models/Track.ts
+8
-4
TrackHistory.ts
src/models/TrackHistory.ts
+2
-2
User.ts
src/models/User.ts
+6
-4
mongooseDB.ts
src/repository/mongooseDB.ts
+1
-2
No files found.
src/models/Album.ts
View file @
bc729e6b
...
...
@@ -7,21 +7,25 @@ const AlbumSchema = new Schema<IAlbum>({
title
:{
type
:
String
,
require
:
true
,
trim
:
true
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Album title should exist'
]
},
artist
:{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Artist'
,
required
:
true
minlength
:
1
,
required
:
[
true
,
'Artists name should exist'
]
},
releaseYear
:{
type
:
Date
,
required
:
true
required
:
[
true
,
'Release year of album should exist'
]
},
coverImage
:{
type
:
String
,
required
:
true
}
required
:
[
true
,
'Cover image should exist'
]
},
},
{
versionKey
:
false
})
export
const
Album
=
mongoose
.
model
<
IAlbum
>
(
'Album'
,
AlbumSchema
)
\ No newline at end of file
src/models/Artist.ts
View file @
bc729e6b
...
...
@@ -7,16 +7,23 @@ const ArtistSchema = new Schema<IArtist>({
name
:{
type
:
String
,
require
:
true
,
trim
:
true
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Artists name should exist'
]
},
photo
:{
type
:
String
,
require
:
true
require
:
true
,
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Artists photo should exist'
]
},
information
:{
type
:
String
,
require
:
true
,
trim
:
true
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Artists info should exist'
]
}
},
{
versionKey
:
false
})
...
...
src/models/Track.ts
View file @
bc729e6b
...
...
@@ -8,17 +8,21 @@ const TrackSchema = new Schema<ITrack>({
title
:{
type
:
String
,
require
:
true
,
trim
:
true
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Track title should exist'
]
},
album
:{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Album'
,
required
:
true
,
trim
:
true
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Album should exist'
]
},
length
:{
type
:
Number
,
required
:
true
minimum
:
10
,
required
:
[
true
,
'Track length should exist'
]
}
},
{
versionKey
:
false
})
...
...
src/models/TrackHistory.ts
View file @
bc729e6b
...
...
@@ -6,12 +6,12 @@ const TrackHistorySchema: Schema = new Schema<ITrackHistory>({
user
:{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'User'
,
required
:
true
required
:
[
true
,
'User should exist'
]
},
track
:{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Track'
,
required
:
true
required
:
[
true
,
'Track should exist'
]
},
datetime
:{
type
:
Date
,
...
...
src/models/User.ts
View file @
bc729e6b
...
...
@@ -7,14 +7,16 @@ import { v4 } from "uuid";
const
UserSchema
:
Schema
=
new
Schema
<
IUser
>
({
username
:
{
type
:
String
,
required
:
true
,
unique
:
true
,
trim
:
true
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Username should exist'
]
},
password
:
{
type
:
String
,
required
:
true
,
trim
:
true
trim
:
true
,
minlength
:
1
,
required
:
[
true
,
'Password should exist'
]
},
token
:
{
type
:
String
,
...
...
src/repository/mongooseDB.ts
View file @
bc729e6b
...
...
@@ -68,7 +68,6 @@ export class MongooseDB {
public
addAlbum
=
async
(
albumDto
:
IAlbumDto
):
Promise
<
IResponse
<
IAlbum
|
null
>>
=>
{
try
{
if
(
albumDto
.
title
.
trim
()
===
''
||
!
albumDto
.
artist
||
!
albumDto
.
releaseYear
||
!
albumDto
.
coverImage
)
throw
new
Error
(
'All fields should exist'
)
const
album
=
new
Album
(
albumDto
)
const
data
=
await
album
.
save
()
const
response
:
IResponse
<
IAlbum
>
=
{
...
...
@@ -159,7 +158,7 @@ export class MongooseDB {
public
addTrack
=
async
(
trackDto
:
ITrackDto
):
Promise
<
IResponse
<
ITrack
|
null
>>
=>
{
try
{
if
(
trackDto
.
title
.
trim
()
===
''
||
!
trackDto
.
album
||
!
trackDto
.
length
||
trackDto
.
length
<=
0
)
throw
new
Error
(
'All fields should exist and have valid value'
)
if
(
trackDto
.
length
<=
0
)
throw
new
Error
(
'All fields should exist and have valid value'
)
const
album
=
new
Track
(
trackDto
)
const
data
=
await
album
.
save
()
const
response
:
IResponse
<
ITrack
>
=
{
...
...
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