Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (entityFetcher: EntityFetcher) => async (
root: any,
args: Object,
context: Object
) => {
const User = entityFetcher(context);
const { user } = context;
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!");
};
title: sourceRev.title,
snippet: sourceRev.snippet,
settings: sourceRev.settings,
content: sourceRev.content,
category: await sourceRev.category,
parent: sourceRev.parent
});
await newRevision.save();
} catch (e) {
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(newRevision);
};
export default (entityFetcher: EntityFetcher) => async (
root: any,
args: Object,
context: Object
) => {
const User = entityFetcher(context);
const { user } = context;
if (user) {
const instance = await User.findById(user.id);
if (!instance) {
return new NotFoundResponse(`User with ID ${user.id} was not found!`);
}
return new Response(instance);
}
return new Response(null);
};
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;
await settings.save();
return new Response(newHomePage);
};
context: Object
) => {
const User = entityFetcher(context);
const { user } = context;
if (user) {
const instance = await User.findById(user.id);
if (!instance) {
return new NotFoundResponse(`User with ID ${user.id} was not found!`);
}
return new Response(instance);
}
return new Response(null);
};