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
256ed262
Commit
256ed262
authored
Mar 23, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6
89 реализовал истории прослушивания треков
parent
a412de03
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
102 additions
and
1 deletion
+102
-1
track.history.ts
backend/src/controllers/track.history.ts
+39
-0
index.ts
backend/src/index.ts
+2
-0
ITrackHistory.ts
backend/src/interfaces/ITrackHistory.ts
+7
-0
auth.ts
backend/src/middleware/auth.ts
+0
-1
track.history.ts
backend/src/models/track.history.ts
+29
-0
track.history.ts
backend/src/routes/track.history.ts
+9
-0
track.history.ts
backend/src/services/track.history.ts
+14
-0
environment.d.ts
backend/src/types/environment.d.ts
+2
-0
2b86aca7eb05c47dae33d9c2652bce95
backend/uploads/2b86aca7eb05c47dae33d9c2652bce95
+0
-0
3a7519f1dd8ef7a56b35f2280db9fba3
backend/uploads/3a7519f1dd8ef7a56b35f2280db9fba3
+0
-0
3ffb8d679e5318fe0c3a0567dc374b45
backend/uploads/3ffb8d679e5318fe0c3a0567dc374b45
+0
-0
91fa3b49bc6628bb6d3eb4e556d3f5a8
backend/uploads/91fa3b49bc6628bb6d3eb4e556d3f5a8
+0
-0
a17d22fc4f6983e968a8b2f8015bb497
backend/uploads/a17d22fc4f6983e968a8b2f8015bb497
+0
-0
b9659a7a87249070eac3126ad3604985
backend/uploads/b9659a7a87249070eac3126ad3604985
+0
-0
e3d90ad1d406b3e742d384e55cbfc1d2
backend/uploads/e3d90ad1d406b3e742d384e55cbfc1d2
+0
-0
fdd427485a073f7bdd1e4b88337687ab
backend/uploads/fdd427485a073f7bdd1e4b88337687ab
+0
-0
No files found.
backend/src/controllers/track.history.ts
0 → 100644
View file @
256ed262
import
{
Request
,
Response
}
from
'express'
;
import
UserModel
from
'../models/user'
;
import
{
getErrorMessage
}
from
'../utils/errors.util'
;
import
*
as
TrackHistoryService
from
'../services/track.history'
;
import
TrackModel
from
'../models/track'
;
export
const
authorize
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
bearedHeader
=
req
.
headers
[
'authorization'
];
const
bearer
=
bearedHeader
!
.
split
(
' '
);
const
token
=
bearer
[
1
];
UserModel
.
findOne
({
token
})
.
then
(
async
(
user
)
=>
{
if
(
!
user
)
return
res
.
status
(
401
).
json
({
error
:
'Unauthorized'
});
const
trackExists
=
await
TrackModel
.
exists
({
_id
:
req
.
body
.
track
});
if
(
!
trackExists
)
return
res
.
json
({
error
:
'This track does not exist. Please choode another one'
,
});
TrackHistoryService
.
create
({
track
:
req
.
body
.
track
,
user
:
user
.
_id
,
})
.
then
((
result
)
=>
{
return
res
.
send
(
'Successfully created track history'
);
})
.
catch
((
err
)
=>
{
return
res
.
json
({
error
:
err
.
message
});
});
})
.
catch
((
err
)
=>
{
return
res
.
json
({
err
});
});
}
catch
(
error
)
{
return
res
.
status
(
500
).
send
(
getErrorMessage
(
error
));
}
};
backend/src/index.ts
View file @
256ed262
...
...
@@ -6,6 +6,7 @@ import {ArtistRouter} from './routes/artist';
import
{
AlbumRouter
}
from
'./routes/albums'
;
import
{
TrackRouter
}
from
'./routes/track'
;
import
{
UsersRouter
}
from
'./routes/user'
;
import
{
TrackHistoryRouter
}
from
'./routes/track.history'
;
mongoose
.
run
();
...
...
@@ -19,6 +20,7 @@ app.use('/artists', ArtistRouter);
app
.
use
(
'/albums'
,
AlbumRouter
);
app
.
use
(
'/tracks'
,
TrackRouter
);
app
.
use
(
'/users'
,
UsersRouter
);
app
.
use
(
'/track_history'
,
TrackHistoryRouter
);
app
.
listen
(
process
.
env
.
PORT
,
()
=>
{
console
.
log
(
`App started on port
${
process
.
env
.
PORT
}
`
);
...
...
backend/src/interfaces/ITrackHistory.ts
0 → 100644
View file @
256ed262
import
{
Date
,
ObjectId
}
from
'mongoose'
;
export
default
interface
ITrackHistory
{
user
:
ObjectId
;
track
:
ObjectId
;
datetime
?:
Date
;
}
backend/src/middleware/auth.ts
View file @
256ed262
...
...
@@ -11,7 +11,6 @@ export interface CustomRequest extends Request {
export
const
auth
=
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
try
{
const
token
=
req
.
header
(
'Authorization'
)?.
replace
(
'Bearer '
,
''
);
if
(
!
token
)
{
throw
new
Error
();
}
...
...
backend/src/models/track.history.ts
0 → 100644
View file @
256ed262
import
mongoose
,
{
model
,
Schema
}
from
'mongoose'
;
import
ITrackHistory
from
'../interfaces/ITrackHistory'
;
const
TrackHistorySchema
:
mongoose
.
Schema
<
ITrackHistory
>
=
new
mongoose
.
Schema
<
ITrackHistory
>
(
{
user
:
{
type
:
Schema
.
Types
.
ObjectId
,
required
:
[
true
,
'User is required'
],
ref
:
'user'
,
},
track
:
{
type
:
Schema
.
Types
.
ObjectId
,
required
:
[
true
,
'Track is required'
],
ref
:
'track'
,
},
datetime
:
{
type
:
Date
,
default
:
Date
.
now
,
},
},
{
versionKey
:
false
}
);
const
TrackHistoryModel
=
model
<
ITrackHistory
>
(
'trackHistory'
,
TrackHistorySchema
);
export
default
TrackHistoryModel
;
backend/src/routes/track.history.ts
0 → 100644
View file @
256ed262
import
{
Router
}
from
'express'
;
import
*
as
TrackHistoryController
from
'../controllers/track.history'
;
import
{
auth
}
from
'../middleware/auth'
;
const
router
:
Router
=
Router
();
router
.
post
(
'/'
,
auth
,
TrackHistoryController
.
authorize
);
export
{
router
as
TrackHistoryRouter
};
backend/src/services/track.history.ts
0 → 100644
View file @
256ed262
import
ITrackHistory
from
'../interfaces/ITrackHistory'
;
import
TrackHistoryModel
from
'../models/track.history'
;
export
async
function
create
(
trackHistory
:
ITrackHistory
)
{
try
{
const
newTrackHistory
=
await
new
TrackHistoryModel
({
user
:
trackHistory
.
user
,
track
:
trackHistory
.
track
,
}).
save
();
return
newTrackHistory
.
populate
(
'track user'
);
}
catch
(
error
)
{
throw
error
;
}
}
backend/src/types/environment.d.ts
View file @
256ed262
import
{
JwtPayload
}
from
'jsonwebtoken'
;
declare
global
{
namespace
NodeJS
{
interface
ProcessEnv
{
...
...
backend/uploads/2b86aca7eb05c47dae33d9c2652bce95
0 → 100644
View file @
256ed262
File added
backend/uploads/3a7519f1dd8ef7a56b35f2280db9fba3
0 → 100644
View file @
256ed262
File added
backend/uploads/3ffb8d679e5318fe0c3a0567dc374b45
0 → 100644
View file @
256ed262
File added
backend/uploads/91fa3b49bc6628bb6d3eb4e556d3f5a8
0 → 100644
View file @
256ed262
File added
backend/uploads/a17d22fc4f6983e968a8b2f8015bb497
0 → 100644
View file @
256ed262
File added
backend/uploads/b9659a7a87249070eac3126ad3604985
0 → 100644
View file @
256ed262
File added
backend/uploads/e3d90ad1d406b3e742d384e55cbfc1d2
0 → 100644
View file @
256ed262
File added
backend/uploads/fdd427485a073f7bdd1e4b88337687ab
0 → 100644
View file @
256ed262
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