Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const currentUser: ?Entity = await User.findById(user.id);
if (currentUser) {
try {
currentUser.populate(args.data);
await currentUser.save();
return new Response(currentUser);
} catch (e) {
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data || null
});
}
}
return new NotFoundResponse("User not found!");
};
export default async (root: any, args: Object, context: Object) => {
const Page = context.getEntity("PbPage");
const Settings = context.getEntity("PbSettings");
const { id } = args;
const newHomePage = await Page.findById(id);
if (!newHomePage) {
return new NotFoundResponse(id);
}
const settings = await Settings.load();
if (settings.data.pages.home === newHomePage.parent) {
return new ErrorResponse({
code: "ALREADY_HOMEPAGE",
message: `The page is already set as homepage.`
});
}
if (!newHomePage.published) {
newHomePage.published = true;
await newHomePage.save();
}
settings.data.pages.home = newHomePage.parent;