Initialized Project with default middlewares and helpers, connected to Atlas Instance and created Swagger Setup. Created necessary DB models and authentication-authorization logic
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import {
|
||||
createProfile,
|
||||
getProfileByQuery,
|
||||
updateProfile,
|
||||
} from "../models/Profile/operations.js";
|
||||
|
||||
export const createOrEditProfileController = async (req, res, next) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
|
||||
const profile = await updateProfile(user.id, req.body, {
|
||||
new: true,
|
||||
upsert: true,
|
||||
});
|
||||
|
||||
res.status(200).json({ result: profile });
|
||||
} catch (error) {
|
||||
console.log("createProfileController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getProfileController = async (req, res, next) => {
|
||||
try {
|
||||
const { user } = res.locals;
|
||||
const profile = await getProfileByQuery({ userId: user.id });
|
||||
res.status(200).json({ result: profile });
|
||||
} catch (error) {
|
||||
console.log("getProfileController Error", error);
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user