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
9943786c
Commit
9943786c
authored
4 years ago
by
Rafael László
Browse files
Options
Downloads
Patches
Plain Diff
accept user picture
parent
fc38e946
No related branches found
No related tags found
2 merge requests
!29
version 0.9
,
!28
API and Schema rework
Pipeline
#5656
passed
4 years ago
Stage: Build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/middlewares/files/deleteFile.ts
+27
-0
27 additions, 0 deletions
src/middlewares/files/deleteFile.ts
src/middlewares/user/acceptPicture.ts
+37
-0
37 additions, 0 deletions
src/middlewares/user/acceptPicture.ts
src/routes/user.ts
+13
-1
13 additions, 1 deletion
src/routes/user.ts
with
77 additions
and
1 deletion
src/middlewares/files/deleteFile.ts
0 → 100644
+
27
−
0
View file @
9943786c
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
File
from
"
../../models/FileSchema
"
;
import
Profile
from
"
../../models/ProfileSchema
"
;
import
fs
from
"
fs
"
;
/**
* Deletes the file if exists. Careful, doesn't remove reference!
*/
const
deleteFile
=
()
=>
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
try
{
if
(
!
res
.
data
.
value
)
return
next
();
const
oldFile
=
await
File
.
findByIdAndRemove
(
res
.
data
.
value
).
lean
().
exec
();
if
(
oldFile
)
fs
.
unlinkSync
(
oldFile
!
.
path
);
next
();
}
catch
(
err
)
{
next
(
err
);
}
};
export
default
deleteFile
;
This diff is collapsed.
Click to expand it.
src/middlewares/user/acceptPicture.ts
0 → 100644
+
37
−
0
View file @
9943786c
import
{
NextFunction
,
Request
,
Response
}
from
"
express
"
;
import
Profile
,
{
IProfile
}
from
"
../../models/ProfileSchema
"
;
/**
* userId -> updates the user
*/
const
acceptPicture
=
()
=>
async
(
req
:
Request
,
res
:
Response
,
next
:
NextFunction
)
=>
{
try
{
if
(
!
res
.
data
.
profile
?.
picture
)
return
res
.
status
(
400
).
json
({
message
:
"
The User doesn't have any unaccepted Profile picture!
"
,
});
await
Profile
.
updateOne
(
{
_id
:
req
.
params
.
userId
},
{
$set
:
{
picture
:
undefined
,
acceptedPicture
:
res
.
data
.
profile
?.
picture
,
},
},
{
upsert
:
true
,
runValidators
:
true
}
)
.
lean
()
.
exec
();
next
();
}
catch
(
err
)
{
next
(
err
);
}
};
export
default
acceptPicture
;
This diff is collapsed.
Click to expand it.
src/routes/user.ts
+
13
−
1
View file @
9943786c
import
{
Application
}
from
"
express
"
;
import
acceptPicture
from
"
../middlewares/user/acceptPicture
"
;
import
createdResponse
from
"
../middlewares/utils/createdResponse
"
;
import
deleteFile
from
"
../middlewares/files/deleteFile
"
;
import
deleteUser
from
"
../middlewares/user/deleteUser
"
;
import
example
from
"
../middlewares/example
"
;
import
getFieldValue
from
"
../middlewares/utils/getFieldValue
"
;
import
getUser
from
"
../middlewares/user/getUser
"
;
import
getUserWarningsList
from
"
../middlewares/user/getUserWarningsList
"
;
import
getUsersList
from
"
../middlewares/user/getUsersList
"
;
...
...
@@ -93,7 +96,16 @@ const usersRoute = (prefix: string, app: Application): void => {
noContentResponse
()
);
// Accept/Reject a users picture TODO
app
.
post
(
`
${
prefix
}
/user/:userId/picture/accept`
,
example
());
app
.
post
(
`
${
prefix
}
/user/:userId/picture/accept`
,
isRegistered
(),
isStaffOrAdmin
(),
getUser
(),
getFieldValue
(
"
profile
"
,
"
acceptedPicture
"
),
deleteFile
(),
acceptPicture
(),
noContentResponse
()
);
app
.
post
(
`
${
prefix
}
/user/:userId/picture/reject`
,
example
());
};
...
...
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