Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bodysch-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KSZK
DevTeam
org
BodySCH
bodysch-backend
Commits
0c4bae11
Commit
0c4bae11
authored
4 years ago
by
Rafael László
Browse files
Options
Downloads
Patches
Plain Diff
get own profile picture
parent
6b8c84d5
No related branches found
No related tags found
3 merge requests
!24
Auth, Profile, News, Entry Card, File management
,
!21
update feature/news_api branch
,
!19
Profile and Entry Card
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/middlewares/files/getOwnProfilePicture.ts
+33
-0
33 additions, 0 deletions
src/middlewares/files/getOwnProfilePicture.ts
src/routes/file.ts
+2
-0
2 additions, 0 deletions
src/routes/file.ts
with
35 additions
and
0 deletions
src/middlewares/files/getOwnProfilePicture.ts
0 → 100644
+
33
−
0
View file @
0c4bae11
import
File
,
{
FileType
}
from
"
../../models/FileSchema
"
;
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
Profile
from
"
../../models/ProfileSchema
"
;
import
fs
from
"
fs
"
;
const
getOwnProfilePicture
=
()
=>
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
Profile
.
findOne
(
{
external_id
:
req
.
session
!
.
user
!
.
id
},
async
(
error
,
profile
)
=>
{
if
(
error
)
{
console
.
warn
(
error
);
res
.
status
(
400
);
}
else
{
if
(
profile
!
.
pictureId
)
{
const
file
=
await
File
.
findById
(
profile
!
.
pictureId
).
exec
();
return
res
.
sendFile
(
file
!
.
path
,
{
root
:
"
.
"
});
}
else
{
return
res
.
status
(
400
)
.
send
({
message
:
"
You dont have a profile picture!
"
});
}
}
}
);
};
export
default
getOwnProfilePicture
;
This diff is collapsed.
Click to expand it.
src/routes/file.ts
+
2
−
0
View file @
0c4bae11
import
{
Application
}
from
"
express
"
;
import
authenticated
from
"
../middlewares/auth/authenticated
"
;
import
cardImageStorage
from
"
../middlewares/files/cardImageStorage
"
;
import
getOwnProfilePicture
from
"
../middlewares/files/getOwnProfilePicture
"
;
import
multer
from
"
multer
"
;
import
profilePictureStorage
from
"
../middlewares/files/profilePictureStorage
"
;
import
responseUser
from
"
../middlewares/user/responseUser
"
;
...
...
@@ -22,6 +23,7 @@ const fileRoute = (app: Application): void => {
profilePictureUpload
.
single
(
"
profile_picture
"
),
uploadProfilePicture
()
);
app
.
get
(
"
/api/v1/files/profile
"
,
authenticated
(),
getOwnProfilePicture
());
};
export
default
fileRoute
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment