Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const resolveGet = ({ model }: Object) => async (
root: any,
args: Object,
context: Object
) => {
if (args.id) {
args.where = { _id: ObjectId(args.id) };
}
const entry = await findEntry({ model, args, context });
if (!entry) {
return entryNotFound();
}
return new Response(entry);
};
export default async (root: any, args: Object, context: Object) => {
const { user } = context;
if (user) {
const { SecurityUser } = context.models;
const instance = await SecurityUser.findById(user.id);
if (!instance) {
return new NotFoundResponse(`User with ID ${user.id} was not found!`);
}
return new Response(instance);
}
return new Response(null);
};
export default async (root: any, args: Object, context: Object) => {
const { SecurityUser } = context.models;
const { user } = context;
const currentUser = await SecurityUser.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!");
};
) => {
const entry = {};
try {
const params = { models, model, context };
await populateEntry(entry, args.data, params);
entry._id = await saveEntry(entry, params);
} catch (e) {
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data || null
});
}
return new Response(entry);
};
if (!entry) {
return entryNotFound(args.id);
}
try {
await populateEntry(entry, args.data, { models, model, context });
await saveEntry(entry, { models, model, context });
} catch (e) {
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data || null
});
}
return new Response(entry);
};
export default async (root: any, args: Object, context: Object) => {
const { user } = context;
if (user) {
const { SecurityUser } = context.models;
const instance = await SecurityUser.findById(user.id);
if (!instance) {
return new NotFoundResponse(`User with ID ${user.id} was not found!`);
}
return new Response(instance);
}
return new Response(null);
};