Skip to content
Snippets Groups Projects
Commit 0c4bae11 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

get own profile picture

parent 6b8c84d5
No related branches found
No related tags found
3 merge requests!24Auth, Profile, News, Entry Card, File management,!21update feature/news_api branch,!19Profile and Entry Card
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;
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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment