mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-09-08 00:47:10 -05:00
chore: fix linting in entire project
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { usePapr } from "~~/server/utils/papr";
|
||||
import { ApiAccountCheckoutLink, CheckoutSchema } from "~~/shared/api-types";
|
||||
import { usePapr } from '~~/server/utils/papr';
|
||||
import { CheckoutSchema } from '~~/shared/api-types';
|
||||
import type { ApiAccountCheckoutLink } from '~~/shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAccountCheckoutLink> => {
|
||||
const auth = enforceLoggedIn(event);
|
||||
const papr = await usePapr(event);
|
||||
const stripe = useStripe(event);
|
||||
const config = useRuntimeConfig(event);
|
||||
if (!stripe || !papr) throw createError({
|
||||
status: 400,
|
||||
message: 'Stripe integration not configured',
|
||||
})
|
||||
if (!stripe || !papr) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Stripe integration not configured'
|
||||
});
|
||||
}
|
||||
|
||||
const body = await readZodBody(event, CheckoutSchema);
|
||||
const { data: searchResults } = await stripe.customers.search({
|
||||
@@ -29,15 +32,15 @@ export default defineEventHandler(async (event): Promise<ApiAccountCheckoutLink>
|
||||
if (auth.accessLevel >= 2) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Staff members do not need to purchase tiers',
|
||||
})
|
||||
message: 'Staff members do not need to purchase tiers'
|
||||
});
|
||||
}
|
||||
await papr.Pnid.updateOne({ pid: auth.pid }, {
|
||||
$set: {
|
||||
'connections.stripe.customer_id': customer.id,
|
||||
'connections.stripe.latest_webhook_timestamp': 0
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const priceId = body.priceId;
|
||||
const session = await stripe.checkout.sessions.create({
|
||||
@@ -50,11 +53,13 @@ export default defineEventHandler(async (event): Promise<ApiAccountCheckoutLink>
|
||||
customer: customer.id,
|
||||
mode: 'subscription',
|
||||
success_url: new URL('/account?upgrade_success=true', config.public.baseUrl).toString(),
|
||||
cancel_url: new URL('/account?upgrade_success=false', config.public.baseUrl).toString(),
|
||||
cancel_url: new URL('/account?upgrade_success=false', config.public.baseUrl).toString()
|
||||
});
|
||||
if (!session.url) throw new Error("Failed to create session");
|
||||
if (!session.url) {
|
||||
throw new Error('Failed to create session');
|
||||
}
|
||||
|
||||
return {
|
||||
url: session.url,
|
||||
}
|
||||
url: session.url
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { useDiscord } from "~~/server/utils/discord";
|
||||
import { ApiAccountDiscordLink } from "~~/shared/api-types";
|
||||
import { useDiscord } from '~~/server/utils/discord';
|
||||
import type { ApiAccountDiscordLink } from '~~/shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAccountDiscordLink> => {
|
||||
enforceLoggedIn(event);
|
||||
const discord = useDiscord(event);
|
||||
if (!discord) throw createError({
|
||||
status: 400,
|
||||
message: 'Discord integration not configured',
|
||||
})
|
||||
if (!discord) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Discord integration not configured'
|
||||
});
|
||||
}
|
||||
|
||||
const redirectUrl = discord.makeCallbackUrl();
|
||||
const url = new URL("https://discord.com/oauth2/authorize");
|
||||
const url = new URL('https://discord.com/oauth2/authorize');
|
||||
url.searchParams.set('response_type', 'code');
|
||||
url.searchParams.set('client_id', 'code');
|
||||
url.searchParams.set('scope', 'identify');
|
||||
@@ -18,6 +20,6 @@ export default defineEventHandler(async (event): Promise<ApiAccountDiscordLink>
|
||||
url.searchParams.set('prompt', 'scope');
|
||||
url.searchParams.set('integration_type', '1');
|
||||
return {
|
||||
url: url.toString(),
|
||||
}
|
||||
url: url.toString()
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import { removeDiscordMemberSupporterRole, removeDiscordMemberTesterRole } from "~~/server/utils/discord";
|
||||
import { removeDiscordMemberSupporterRole, removeDiscordMemberTesterRole } from '~~/server/utils/discord';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<void> => {
|
||||
const auth = enforceLoggedIn(event);
|
||||
const discord = useDiscord(event);
|
||||
if (!discord) throw createError({
|
||||
status: 400,
|
||||
message: 'Discord integration not configured',
|
||||
})
|
||||
if (!discord) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Discord integration not configured'
|
||||
});
|
||||
}
|
||||
|
||||
const grpc = useApiGrpcWithToken(event, auth.token);
|
||||
const oldUserData = await grpc.getUserData({});
|
||||
const oldDiscordId = oldUserData.connections?.discord?.id;
|
||||
await grpc.setDiscordConnectionData({
|
||||
id: '',
|
||||
id: ''
|
||||
});
|
||||
|
||||
const priceId = oldUserData.connections?.stripe?.priceId;
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
import { ApiAccountTiers, TierItem } from "~~/shared/api-types";
|
||||
import type { ApiAccountTiers, TierItem } from '~~/shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAccountTiers> => {
|
||||
enforceLoggedIn(event);
|
||||
const stripe = useStripe(event);
|
||||
if (!stripe) throw createError({
|
||||
status: 400,
|
||||
message: 'Stripe integration not configured',
|
||||
})
|
||||
if (!stripe) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Stripe integration not configured'
|
||||
});
|
||||
}
|
||||
|
||||
const prices = await stripe.prices.list().autoPagingToArray({ limit: 10 });
|
||||
const products = await stripe.products.list().autoPagingToArray({ limit: 10 });
|
||||
|
||||
const tiers: TierItem[] = [];
|
||||
|
||||
for (let product of products) {
|
||||
if (!product.active) continue;
|
||||
for (const product of products) {
|
||||
if (!product.active) {
|
||||
continue;
|
||||
}
|
||||
const price = prices.find(price => price.id === product.default_price);
|
||||
if (!price) continue;
|
||||
if (!price) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const tierLevel = Number(product.metadata.tier_level ?? "0");
|
||||
const tierLevel = Number(product.metadata.tier_level ?? '0');
|
||||
const hasDiscordReadPerk = product.metadata.discord_read === 'true';
|
||||
const hasBetaAccessPerk = product.metadata.beta === 'true';
|
||||
|
||||
@@ -31,12 +37,12 @@ export default defineEventHandler(async (event): Promise<ApiAccountTiers> => {
|
||||
description: product.description,
|
||||
perks: {
|
||||
discordRead: hasDiscordReadPerk,
|
||||
beta: hasBetaAccessPerk,
|
||||
},
|
||||
})
|
||||
beta: hasBetaAccessPerk
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
tiers,
|
||||
}
|
||||
tiers
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AccountUpdateSchema } from "~~/shared/api-types";
|
||||
import { AccountUpdateSchema } from '~~/shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<void> => {
|
||||
const body = await readZodBody(event, AccountUpdateSchema);
|
||||
@@ -8,11 +8,11 @@ export default defineEventHandler(async (event): Promise<void> => {
|
||||
// There's no equivalent GRPC endpoint to use, so we're using the HTTP api
|
||||
await apiFetch('/v1/user', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${auth.token}`,
|
||||
Authorization: `Bearer ${auth.token}`
|
||||
},
|
||||
body: {
|
||||
mii: body.mii,
|
||||
environment: body.environment
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import { hcaptchaVerify } from "~~/server/utils/hcaptcha";
|
||||
import { ForgotPasswordSchema } from "~~/shared/api-types";
|
||||
import { hcaptchaVerify } from '~~/server/utils/hcaptcha';
|
||||
import { ForgotPasswordSchema } from '~~/shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<void> => {
|
||||
const body = await readZodBody(event, ForgotPasswordSchema);
|
||||
const grpc = useApiGrpc(event);
|
||||
|
||||
const captchaResult = await hcaptchaVerify(event, body.captchaResponse);
|
||||
if (!captchaResult) throw createError({
|
||||
status: 400,
|
||||
message: 'Invalid captcha',
|
||||
});
|
||||
if (!captchaResult) {
|
||||
throw createError({
|
||||
status: 400,
|
||||
message: 'Invalid captcha'
|
||||
});
|
||||
}
|
||||
|
||||
await grpc.forgotPassword({
|
||||
emailAddressOrUsername: body.emailOrPassword,
|
||||
})
|
||||
emailAddressOrUsername: body.emailOrPassword
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ServerError } from "nice-grpc";
|
||||
import { ApiAuthLogin, LoginSchema } from "#shared/api-types"
|
||||
import { useLegacyApiGrpc } from "~~/server/utils/useGrpc";
|
||||
import { ServerError } from 'nice-grpc';
|
||||
import { LoginSchema } from '#shared/api-types';
|
||||
import type { ApiAuthLogin } from '#shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAuthLogin> => {
|
||||
const body = await readZodBody(event, LoginSchema);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { GetApiAuthMe } from "#shared/api-types"
|
||||
import type { GetApiAuthMe } from '#shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<GetApiAuthMe> => {
|
||||
const auth = enforceLoggedIn(event);
|
||||
@@ -8,9 +8,11 @@ export default defineEventHandler(async (event): Promise<GetApiAuthMe> => {
|
||||
return {
|
||||
pid: data.pid,
|
||||
username: data.username,
|
||||
mii: data.mii ? {
|
||||
imageUrl: `https://r2-cdn.pretendo.cc/mii/${data.pid}/normal_face.png`,
|
||||
name: data.mii.name,
|
||||
} : null,
|
||||
mii: data.mii
|
||||
? {
|
||||
imageUrl: `https://r2-cdn.pretendo.cc/mii/${data.pid}/normal_face.png`,
|
||||
name: data.mii.name
|
||||
}
|
||||
: null
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { ApiAuthLogin, RegisterSchema } from "#shared/api-types"
|
||||
import { RegisterSchema } from '#shared/api-types';
|
||||
import type { ApiAuthLogin } from '#shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<ApiAuthLogin> => {
|
||||
const body = await readZodBody(event, RegisterSchema);
|
||||
const grpc = useApiGrpc(event);
|
||||
|
||||
// eslint-disable-next-line no-useless-catch -- Temp before error handling is implemented
|
||||
try {
|
||||
// TODO Add ip
|
||||
// TODO Add birthday
|
||||
@@ -13,7 +15,7 @@ export default defineEventHandler(async (event): Promise<ApiAuthLogin> => {
|
||||
captchaResponse: body.captchaResponse,
|
||||
username: body.username,
|
||||
password: body.password,
|
||||
passwordConfirm: body.password,
|
||||
passwordConfirm: body.password
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -21,6 +23,7 @@ export default defineEventHandler(async (event): Promise<ApiAuthLogin> => {
|
||||
refreshToken: res.refreshToken
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
// TODO handle errors
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ResetPasswordSchema } from "~~/shared/api-types";
|
||||
import { ResetPasswordSchema } from '~~/shared/api-types';
|
||||
|
||||
export default defineEventHandler(async (event): Promise<void> => {
|
||||
const body = await readZodBody(event, ResetPasswordSchema);
|
||||
@@ -7,6 +7,6 @@ export default defineEventHandler(async (event): Promise<void> => {
|
||||
await grpc.resetPassword({
|
||||
password: body.password,
|
||||
passwordConfirm: body.passwordConfirm,
|
||||
token: body.resetToken,
|
||||
})
|
||||
token: body.resetToken
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { GetProgress, ProgressItem } from "#shared/api-types"
|
||||
import { getGithubProjects } from "../utils/getGithubProgress";
|
||||
import { getStripeDonations } from "../utils/getStripeDonations";
|
||||
import { getGithubProjects } from '../utils/getGithubProgress';
|
||||
import { getStripeDonations } from '../utils/getStripeDonations';
|
||||
import type { GetProgress, ProgressItem } from '#shared/api-types';
|
||||
|
||||
const donationGoalCents = 3000 * 100;
|
||||
|
||||
@@ -10,7 +10,7 @@ export default defineEventHandler(async (event): Promise<GetProgress> => {
|
||||
const donationData = await getStripeDonations(stripe);
|
||||
const { projects } = await getGithubProjects(octokit);
|
||||
|
||||
const items: ProgressItem[] = projects.map(v => {
|
||||
const items: ProgressItem[] = projects.map((v) => {
|
||||
const totalTasks = v.tasks.length;
|
||||
const completedTasks = v.tasks.filter(v => v.status === 'completed').length;
|
||||
const percentage = Math.floor(completedTasks / totalTasks * 100);
|
||||
@@ -21,9 +21,9 @@ export default defineEventHandler(async (event): Promise<GetProgress> => {
|
||||
completion: percentage,
|
||||
tasks: v.tasks.map(task => ({
|
||||
status: task.status,
|
||||
title: task.title,
|
||||
title: task.title
|
||||
}))
|
||||
}
|
||||
};
|
||||
});
|
||||
const summedCompletion = items.reduce((a, v) => a + v.completion, 0);
|
||||
const completionPercentage = Math.floor(summedCompletion / items.length * 100);
|
||||
@@ -32,9 +32,9 @@ export default defineEventHandler(async (event): Promise<GetProgress> => {
|
||||
completion: completionPercentage,
|
||||
donations: {
|
||||
currentCents: donationData.totalDonationsCents,
|
||||
goalCents: donationGoalCents,
|
||||
goalCents: donationGoalCents
|
||||
},
|
||||
items: projects.map(v => {
|
||||
items: projects.map((v) => {
|
||||
const totalTasks = v.tasks.length;
|
||||
const completedTasks = v.tasks.filter(v => v.status === 'completed').length;
|
||||
const percentage = Math.floor(completedTasks / totalTasks * 100);
|
||||
@@ -45,9 +45,9 @@ export default defineEventHandler(async (event): Promise<GetProgress> => {
|
||||
completion: percentage,
|
||||
tasks: v.tasks.map(task => ({
|
||||
status: task.status,
|
||||
title: task.title,
|
||||
title: task.title
|
||||
}))
|
||||
}
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user