Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async setLoggedInUser(user = {}) {
if (!user._id) throw new Error("setLoggedInUser: user must have _id property set");
const { users } = this.reactionNodeApp.collections;
const loginToken = Random.id();
const hashedToken = hashToken(loginToken);
const existing = await users.findOne({ _id: user._id });
if (!existing) {
await this.createUserAndAccount(user);
}
// Set the hashed login token on the users document
await users.updateOne({ _id: user._id }, {
$push: {
"services.resume.loginTokens": {
hashedToken,
when: new Date()
}
}
});
if (user.emails[0] && user.emails[0].address.indexOf("localhost") > -1) {
user.emails[0].verified = true;
emailIsVerified = true;
}
// Set the first email to be the default
if (user.emails[0]) {
user.emails[0].provides = "default";
}
// create a tokenObj and send a welcome email to new users,
// but skip the first default admin user and anonymous users
// (default admins already get a verification email)
let tokenObj;
if (shopId && !emailIsVerified && user.emails[0]) {
tokenObj = generateVerificationTokenObject({ address: user.emails[0].address });
}
// Get GraphQL context to pass to mutation
// This is the only place in the app that still
// uses `getGraphQLContextInMeteorMethod`
// Prioritize removing if possible
const context = Promise.await(getGraphQLContextInMeteorMethod(null));
Promise.await(context.mutations.createAccount({ ...context, isInternalCall: true }, {
emails: user.emails,
name: user.name,
profile,
shopId,
userId: user._id,
verificationToken: tokenObj && tokenObj.token
}));
export default async function groups(_, { shopId, ...connectionArgs }, context, info) {
// Transform ID from base64
const dbShopId = decodeShopOpaqueId(shopId);
const query = await context.queries.groups(context, dbShopId);
return getPaginatedResponse(query, connectionArgs, {
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info),
includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info),
includeTotalCount: wasFieldRequested("totalCount", info)
});
}
export default async function groups(_, { shopId, ...connectionArgs }, context, info) {
// Transform ID from base64
const dbShopId = decodeShopOpaqueId(shopId);
const query = await context.queries.groups(context, dbShopId);
return getPaginatedResponse(query, connectionArgs, {
includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info),
includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info),
includeTotalCount: wasFieldRequested("totalCount", info)
});
}
export default async function items(fulfillmentGroup, connectionArgs, context) {
let { items: orderItems } = fulfillmentGroup;
if (!Array.isArray(orderItems) || orderItems.length === 0) return xformArrayToConnection(connectionArgs, []);
// Apply requested sorting
orderItems = sortOrderItems(orderItems, connectionArgs);
return xformArrayToConnection(connectionArgs, xformOrderItems(context, orderItems));
}
export default async function items(cart, connectionArgs, context) {
let { items: cartItems } = cart;
if (!Array.isArray(cartItems) || cartItems.length === 0) return xformArrayToConnection(connectionArgs, []);
// Apply requested sorting
cartItems = sortCartItems(cartItems, connectionArgs);
return xformArrayToConnection(connectionArgs, xformCartItems(context, cartItems));
}
export default async function items(fulfillmentGroup, connectionArgs, context) {
let { items: orderItems } = fulfillmentGroup;
if (!Array.isArray(orderItems) || orderItems.length === 0) return xformArrayToConnection(connectionArgs, []);
// Apply requested sorting
orderItems = sortOrderItems(orderItems, connectionArgs);
return xformArrayToConnection(connectionArgs, xformOrderItems(context, orderItems));
}
export default async function items(cart, connectionArgs, context) {
let { items: cartItems } = cart;
if (!Array.isArray(cartItems) || cartItems.length === 0) return xformArrayToConnection(connectionArgs, []);
// Apply requested sorting
cartItems = sortCartItems(cartItems, connectionArgs);
return xformArrayToConnection(connectionArgs, xformCartItems(context, cartItems));
}
export default async function items(cart, connectionArgs, context) {
let { items: cartItems } = cart;
if (!Array.isArray(cartItems) || cartItems.length === 0) return xformArrayToConnection(connectionArgs, []);
// Apply requested sorting
cartItems = sortCartItems(cartItems, connectionArgs);
return xformArrayToConnection(connectionArgs, xformCartItems(context, cartItems));
}
export default async function items(fulfillmentGroup, connectionArgs, context) {
let { items: orderItems } = fulfillmentGroup;
if (!Array.isArray(orderItems) || orderItems.length === 0) return xformArrayToConnection(connectionArgs, []);
// Apply requested sorting
orderItems = sortOrderItems(orderItems, connectionArgs);
return xformArrayToConnection(connectionArgs, xformOrderItems(context, orderItems));
}