Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async execute(query: GetTenantsQuery): Promise {
Logger.log(query, 'GetTenantsQuery'); // write here
const { where, user } = query;
if (!user) { throw Error('Missing get current user'); }
try {
return await this.tenantRepository.find({ conditions: {...where, ownerId: new ObjectId(user.id)} });
} catch (e) {
throw new ApolloError(e);
}
}
}
async function getProfile(parent: any, args: any, context: { me: GUser }, info: any) {
const condition = { email: context.me.email };
let user: UserDocument | null = await Users.findOne(condition).exec();
if (user == null) {
throw new ApolloError('User does not exist.');
}
let profile: Profile = {
email: user.email,
displayName: user.displayName,
isEmailVeried: user.isEmailVerified,
image: user.profile.image,
firstName: user.profile.firstName,
middleName: user.profile.middleName,
lastName: user.profile.lastName,
birthDay: user.profile.birthDay && user.profile.birthDay.toISOString(),
createdAt: user.createdAt && user.createdAt.toISOString(),
updatedAt: user.updatedAt && user.updatedAt.toISOString()
};
return profile;
}
export const resolveUser: Resolver = async (
root,
args,
) => {
const { uniqueUsername } = args;
const user = await users.getUserByUniqueUsername(uniqueUsername);
if (!user) {
throw new ApolloError('user not found');
}
return user;
};
const getHistories = async (_, __, { user }) => {
try {
const histories = (await Histories.find({ userId: user.userId })) || [];
const payloads = await Promise.all(histories.map((history) => history.toPayload()));
return payloads;
} catch (err) {
throw new ApolloError(err.message);
}
};
userErrors {
field
message
}
}
}
`
);
if (response.userErrors.length > 0) {
throw new Error(response.userErrors[0].message);
}
return response.customer.id;
} catch (error) {
throw new ApolloError(error.message);
}
};
function newInternalServerError (context) {
let errorId = (context && context.request) ? context.request.id : uuid.v4()
const genericErrorMsg = `An internal server error occurred, please contact the server administrator and provide the following id: ${errorId}`
return new ApolloError(genericErrorMsg, INTERNAL_SERVER_ERROR, { id: errorId })
}
}
}
`
);
const errors = response.data.data.tagsAdd.userErrors;
if (response.errors || errors.length > 0) {
const allErrors = [].concat(
response.errors.map(({ message }) => message),
errors.map(({ message }) => message)
);
logger.error(allErrors);
throw new ApolloError(allErrors[0]);
}
logger.verbose(`Added new tags: ${tags.join(', ')}`);
};
const cacheData = await this.cacheStore.get(cacheKey);
if (cacheData !== undefined && typeof cacheData !== 'undefined') {
return cacheData;
}
const cardObjs = await this.stripeClient.customers.listSources(customerId, {
object: 'card',
});
const cardsList = cardObjs.data as unknown as Stripe.cards.ICard[];
const card = convertFromToCard(cardsList) as unknown as Card[];
await this.cacheStore.set(cacheKey, card, {ttl: 50});
return card;
} catch (e) {
this.logger.error(e);
throw new ApolloError(e);
}
}
}