Merge branch 'develop' of Software_Engineering_I/greenvironment-server into master

pull/5/head
Trivernis 5 years ago committed by Gitea
commit 79f099471c

@ -63,28 +63,35 @@ export class UploadRoute extends Route {
// Uploads a file to the data directory and returns the filename // Uploads a file to the data directory and returns the filename
this.router.use(async (req, res) => { this.router.use(async (req, res) => {
let uploadConfirmation: IUploadConfirmation; let uploadConfirmation: IUploadConfirmation;
if (req.session.userId) { try {
if (req.files.profilePicture) { if (req.session.userId) {
uploadConfirmation = await this.uploadProfilePicture(req); if (req.files.profilePicture) {
} else if (req.files.groupPicture) { uploadConfirmation = await this.uploadProfilePicture(req);
uploadConfirmation = await this.uploadGroupPicture(req); } else if (req.files.groupPicture) {
} else if (req.files.postMedia) { uploadConfirmation = await this.uploadGroupPicture(req);
uploadConfirmation = await this.uploadPostMedia(req); } else if (req.files.postMedia) {
uploadConfirmation = await this.uploadPostMedia(req);
} else {
res.status(status.BAD_REQUEST);
uploadConfirmation = {
error: "You did not provide a (valid) file.",
success: false,
};
}
} else { } else {
res.status(status.BAD_REQUEST); res.status(status.UNAUTHORIZED);
uploadConfirmation = { uploadConfirmation = {
error: "You did not provide a (valid) file.", error: "You are not logged in.",
success: false, success: false,
}; };
} }
} else { } catch (err) {
res.status(status.UNAUTHORIZED);
uploadConfirmation = { uploadConfirmation = {
error: "You are not logged in.", error: err,
success: false, success: false,
}; };
} }
if (uploadConfirmation.error) { if (uploadConfirmation?.error) {
res.status(httpStatus.BAD_REQUEST); res.status(httpStatus.BAD_REQUEST);
} }
res.json(uploadConfirmation); res.json(uploadConfirmation);

Loading…
Cancel
Save