Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!ctx.status || ctx.status === 404) {
ctx.matched.forEach((route) => {
route.methods.forEach((method) => {
allowed[method] = method;
});
});
const allowedArr = Object.keys(allowed);
if (!~implemented.indexOf(ctx.method)) {
if (options.throw) {
let notImplementedThrowable;
if (typeof options.notImplemented === 'function') {
notImplementedThrowable = options.notImplemented(); // set whatever the user returns from their function
} else {
notImplementedThrowable = new HttpError.NotImplemented();
}
throw notImplementedThrowable;
} else {
ctx.status = 501;
ctx.set('Allow', allowedArr.join(', '));
}
} else if (allowedArr.length) {
if (ctx.method === 'OPTIONS') {
ctx.status = 200;
ctx.body = '';
ctx.set('Content-Length', 0);
ctx.set('Allow', allowedArr.join(', '));
} else if (!allowed[ctx.method]) {
if (options.throw) {
let notAllowedThrowable;
if (typeof options.methodNotAllowed === 'function') {
async function upsertPreferences(ctx, next) {
const { matchmakingType } = ctx.params
const { race, alternateRace, mapPoolId, preferredMaps } = ctx.request.body
if (!isValidMatchmakingType(matchmakingType)) {
throw new httpErrors.BadRequest('invalid matchmaking type')
} else if (!isValidRace(race)) {
throw new httpErrors.BadRequest('invalid race')
} else if (!(await isValidMapPoolId(mapPoolId))) {
throw new httpErrors.NotImplemented('map pool support not implemented yet')
} else if (
alternateRace !== null &&
alternateRace !== undefined &&
!isValidAlternateRace(alternateRace)
) {
throw new httpErrors.BadRequest('invalid alternateRace')
} else if (preferredMaps !== undefined && preferredMaps !== null) {
// TODO(2Pac): Change this once matchmaking map pool support is added
throw new httpErrors.NotImplemented('preferredMaps support not implemented yet')
}
ctx.body = await upsertMatchmakingPreferences(
ctx.session.userId,
matchmakingType,
race,
alternateRace,
if (!ctx.status || ctx.status === 404) {
ctx.matched.forEach(function (route) {
route.methods.forEach(function (method) {
allowed[method] = method;
});
});
var allowedArr = Object.keys(allowed);
if (!~implemented.indexOf(ctx.method)) {
if (options.throw) {
var notImplementedThrowable;
if (typeof options.notImplemented === 'function') {
notImplementedThrowable = options.notImplemented(); // set whatever the user returns from their function
} else {
notImplementedThrowable = new HttpError.NotImplemented();
}
throw notImplementedThrowable;
} else {
ctx.status = 501;
ctx.set('Allow', allowedArr.join(', '));
}
} else if (allowedArr.length) {
if (ctx.method === 'OPTIONS') {
ctx.status = 200;
ctx.body = '';
ctx.set('Allow', allowedArr.join(', '));
} else if (!allowed[ctx.method]) {
if (options.throw) {
var notAllowedThrowable;
if (typeof options.methodNotAllowed === 'function') {
notAllowedThrowable = options.methodNotAllowed(); // set whatever the user returns from their function
if (!ctx.status || ctx.status === 404) {
ctx.matched.forEach(function (route) {
route.methods.forEach(function (method) {
allowed[method] = method;
});
});
var allowedArr = Object.keys(allowed);
if (!~implemented.indexOf(ctx.method)) {
if (options.throw) {
var notImplementedThrowable;
if (typeof options.notImplemented === 'function') {
notImplementedThrowable = options.notImplemented(); // set whatever the user returns from their function
} else {
notImplementedThrowable = new HttpError.NotImplemented();
}
throw notImplementedThrowable;
} else {
ctx.status = 501;
ctx.set('Allow', allowedArr.join(', '));
}
} else if (allowedArr.length) {
if (ctx.method === 'OPTIONS') {
ctx.status = 200;
ctx.body = '';
ctx.set('Allow', allowedArr.join(', '));
} else if (!allowed[ctx.method]) {
if (options.throw) {
var notAllowedThrowable;
if (typeof options.methodNotAllowed === 'function') {
notAllowedThrowable = options.methodNotAllowed(); // set whatever the user returns from their function
if (!isValidMatchmakingType(matchmakingType)) {
throw new httpErrors.BadRequest('invalid matchmaking type')
} else if (!isValidRace(race)) {
throw new httpErrors.BadRequest('invalid race')
} else if (!(await isValidMapPoolId(mapPoolId))) {
throw new httpErrors.NotImplemented('map pool support not implemented yet')
} else if (
alternateRace !== null &&
alternateRace !== undefined &&
!isValidAlternateRace(alternateRace)
) {
throw new httpErrors.BadRequest('invalid alternateRace')
} else if (preferredMaps !== undefined && preferredMaps !== null) {
// TODO(2Pac): Change this once matchmaking map pool support is added
throw new httpErrors.NotImplemented('preferredMaps support not implemented yet')
}
ctx.body = await upsertMatchmakingPreferences(
ctx.session.userId,
matchmakingType,
race,
alternateRace,
mapPoolId,
preferredMaps,
)
}
notImplemented: function notImplemented (message) {
return new createError.NotImplemented(message)
},
export function invalidParamLocation(location: string): HttpErrors.HttpError {
const msg = `Parameters with "in: ${location}" are not supported yet.`;
return new HttpErrors.NotImplemented(msg);
}
async function acceptInvite(ctx, next) {
if (!isValidEmail(ctx.params.email)) {
throw new httpErrors.BadRequest('Invalid email')
}
if (!ctx.request.body.isAccepted) {
throw new httpErrors.NotImplemented('Not implemented')
}
const token = cuid()
await transact(async client => {
const invite = await invites.accept(client, ctx.params.email, token)
await sendMail({
to: invite.email,
subject: 'Welcome to ShieldBattery',
templateName: 'invite',
templateData: {
email: invite.email,
escapedEmail: encodeURIComponent(invite.email),
token: invite.token,
feedbackUrl: config.feedbackUrl,
installerUrl: `${config.canonicalHost}/installer.msi`,