From 0d9b6e83558b8175e903150964358363f33da03b Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Fri, 29 Sep 2023 20:24:48 -0700 Subject: [PATCH] Update useValidate calls. --- src/pages/api/event-data/events.ts | 4 +--- src/pages/api/event-data/fields.ts | 4 +--- src/pages/api/event-data/stats.ts | 4 +--- src/pages/api/me/password.ts | 4 +--- src/pages/api/me/teams.ts | 4 +--- src/pages/api/me/websites.ts | 4 +--- src/pages/api/realtime/[id].ts | 4 +--- src/pages/api/reports/[id].ts | 4 +--- src/pages/api/reports/funnel.ts | 4 +--- src/pages/api/reports/index.ts | 4 +--- src/pages/api/reports/insights.ts | 4 +--- src/pages/api/reports/retention.ts | 4 +--- src/pages/api/send.ts | 3 +-- src/pages/api/share/[id].ts | 3 +-- src/pages/api/teams/[id]/index.ts | 4 +--- src/pages/api/teams/[id]/users/[userId].ts | 4 +--- src/pages/api/teams/[id]/users/index.ts | 3 +-- src/pages/api/teams/[id]/websites/[websiteId].ts | 4 +--- src/pages/api/teams/[id]/websites/index.ts | 4 +--- src/pages/api/teams/index.ts | 4 +--- src/pages/api/teams/join.ts | 4 +--- src/pages/api/users/[id]/index.ts | 4 +--- src/pages/api/users/[id]/teams.ts | 4 +--- src/pages/api/users/[id]/usage.ts | 4 +--- src/pages/api/users/[id]/websites.ts | 4 +--- src/pages/api/users/index.ts | 4 +--- src/pages/api/websites/[id]/active.ts | 4 +--- src/pages/api/websites/[id]/daterange.ts | 4 +--- src/pages/api/websites/[id]/events.ts | 4 +--- src/pages/api/websites/[id]/index.ts | 4 +--- src/pages/api/websites/[id]/metrics.ts | 4 +--- src/pages/api/websites/[id]/pageviews.ts | 4 +--- src/pages/api/websites/[id]/reports.ts | 4 +--- src/pages/api/websites/[id]/reset.ts | 3 +-- src/pages/api/websites/[id]/stats.ts | 4 +--- src/pages/api/websites/[id]/values.ts | 4 +--- src/pages/api/websites/index.ts | 4 ++-- 37 files changed, 38 insertions(+), 106 deletions(-) diff --git a/src/pages/api/event-data/events.ts b/src/pages/api/event-data/events.ts index 1d1d3787..19f0c8f1 100644 --- a/src/pages/api/event-data/events.ts +++ b/src/pages/api/event-data/events.ts @@ -28,9 +28,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'GET') { const { websiteId, startAt, endAt, event } = req.query; diff --git a/src/pages/api/event-data/fields.ts b/src/pages/api/event-data/fields.ts index 1cd24fe6..b2af7511 100644 --- a/src/pages/api/event-data/fields.ts +++ b/src/pages/api/event-data/fields.ts @@ -28,9 +28,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'GET') { const { websiteId, startAt, endAt, field } = req.query; diff --git a/src/pages/api/event-data/stats.ts b/src/pages/api/event-data/stats.ts index 7f694bc6..a12ad92f 100644 --- a/src/pages/api/event-data/stats.ts +++ b/src/pages/api/event-data/stats.ts @@ -26,9 +26,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'GET') { const { websiteId, startAt, endAt } = req.query; diff --git a/src/pages/api/me/password.ts b/src/pages/api/me/password.ts index a601f5d6..5b7a8e05 100644 --- a/src/pages/api/me/password.ts +++ b/src/pages/api/me/password.ts @@ -37,9 +37,7 @@ export default async ( } await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { currentPassword, newPassword } = req.body; const { id } = req.auth.user; diff --git a/src/pages/api/me/teams.ts b/src/pages/api/me/teams.ts index 14602157..b0803277 100644 --- a/src/pages/api/me/teams.ts +++ b/src/pages/api/me/teams.ts @@ -21,9 +21,7 @@ export default async ( res: NextApiResponse, ) => { await useCors(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'GET') { req.query.id = req.auth.user.id; diff --git a/src/pages/api/me/websites.ts b/src/pages/api/me/websites.ts index ec6a5556..e5a9ad32 100644 --- a/src/pages/api/me/websites.ts +++ b/src/pages/api/me/websites.ts @@ -22,9 +22,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'GET') { req.query.id = req.auth.user.id; diff --git a/src/pages/api/realtime/[id].ts b/src/pages/api/realtime/[id].ts index 5b1e1e05..212d4a0f 100644 --- a/src/pages/api/realtime/[id].ts +++ b/src/pages/api/realtime/[id].ts @@ -23,9 +23,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'GET') { const { id: websiteId, startAt } = req.query; diff --git a/src/pages/api/reports/[id].ts b/src/pages/api/reports/[id].ts index eb4199bc..02eb7363 100644 --- a/src/pages/api/reports/[id].ts +++ b/src/pages/api/reports/[id].ts @@ -46,9 +46,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: reportId } = req.query; const { diff --git a/src/pages/api/reports/funnel.ts b/src/pages/api/reports/funnel.ts index a51817bf..9071b962 100644 --- a/src/pages/api/reports/funnel.ts +++ b/src/pages/api/reports/funnel.ts @@ -44,9 +44,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'POST') { const { diff --git a/src/pages/api/reports/index.ts b/src/pages/api/reports/index.ts index 911d729c..2d59c9d6 100644 --- a/src/pages/api/reports/index.ts +++ b/src/pages/api/reports/index.ts @@ -43,9 +43,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { user: { id: userId }, diff --git a/src/pages/api/reports/insights.ts b/src/pages/api/reports/insights.ts index 4d17c922..4344422a 100644 --- a/src/pages/api/reports/insights.ts +++ b/src/pages/api/reports/insights.ts @@ -69,9 +69,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'POST') { const { diff --git a/src/pages/api/reports/retention.ts b/src/pages/api/reports/retention.ts index c7a5e9af..6ff7bbe1 100644 --- a/src/pages/api/reports/retention.ts +++ b/src/pages/api/reports/retention.ts @@ -32,9 +32,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'POST') { const { diff --git a/src/pages/api/send.ts b/src/pages/api/send.ts index 00d72104..e8d3e386 100644 --- a/src/pages/api/send.ts +++ b/src/pages/api/send.ts @@ -80,8 +80,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => { const { type, payload } = req.body; - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (await hasBlockedIp(req)) { return forbidden(res); diff --git a/src/pages/api/share/[id].ts b/src/pages/api/share/[id].ts index cc782246..876fbef5 100644 --- a/src/pages/api/share/[id].ts +++ b/src/pages/api/share/[id].ts @@ -25,8 +25,7 @@ export default async ( req: NextApiRequestQueryBody, res: NextApiResponse, ) => { - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: shareId } = req.query; diff --git a/src/pages/api/teams/[id]/index.ts b/src/pages/api/teams/[id]/index.ts index a5527580..a4f80aba 100644 --- a/src/pages/api/teams/[id]/index.ts +++ b/src/pages/api/teams/[id]/index.ts @@ -35,9 +35,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: teamId } = req.query; diff --git a/src/pages/api/teams/[id]/users/[userId].ts b/src/pages/api/teams/[id]/users/[userId].ts index 107aba64..3b16ac05 100644 --- a/src/pages/api/teams/[id]/users/[userId].ts +++ b/src/pages/api/teams/[id]/users/[userId].ts @@ -20,9 +20,7 @@ const schema = { export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'DELETE') { const { id: teamId, userId } = req.query; diff --git a/src/pages/api/teams/[id]/users/index.ts b/src/pages/api/teams/[id]/users/index.ts index 28918177..c3181e6a 100644 --- a/src/pages/api/teams/[id]/users/index.ts +++ b/src/pages/api/teams/[id]/users/index.ts @@ -21,8 +21,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: teamId } = req.query; diff --git a/src/pages/api/teams/[id]/websites/[websiteId].ts b/src/pages/api/teams/[id]/websites/[websiteId].ts index ada1efdc..865ce0d2 100644 --- a/src/pages/api/teams/[id]/websites/[websiteId].ts +++ b/src/pages/api/teams/[id]/websites/[websiteId].ts @@ -23,9 +23,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: teamId, websiteId } = req.query; diff --git a/src/pages/api/teams/[id]/websites/index.ts b/src/pages/api/teams/[id]/websites/index.ts index 4d14c4e9..5ff8c665 100644 --- a/src/pages/api/teams/[id]/websites/index.ts +++ b/src/pages/api/teams/[id]/websites/index.ts @@ -32,9 +32,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: teamId } = req.query; diff --git a/src/pages/api/teams/index.ts b/src/pages/api/teams/index.ts index 74cb532e..5ad7321e 100644 --- a/src/pages/api/teams/index.ts +++ b/src/pages/api/teams/index.ts @@ -30,9 +30,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { user: { id: userId }, diff --git a/src/pages/api/teams/join.ts b/src/pages/api/teams/join.ts index 06feda8a..0f9d01fa 100644 --- a/src/pages/api/teams/join.ts +++ b/src/pages/api/teams/join.ts @@ -21,9 +21,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'POST') { const { accessCode } = req.body; diff --git a/src/pages/api/users/[id]/index.ts b/src/pages/api/users/[id]/index.ts index 3ac560ed..7926d34a 100644 --- a/src/pages/api/users/[id]/index.ts +++ b/src/pages/api/users/[id]/index.ts @@ -33,9 +33,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { user: { id: userId, isAdmin }, diff --git a/src/pages/api/users/[id]/teams.ts b/src/pages/api/users/[id]/teams.ts index f9d7f5ea..bfa0d31a 100644 --- a/src/pages/api/users/[id]/teams.ts +++ b/src/pages/api/users/[id]/teams.ts @@ -29,9 +29,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { user } = req.auth; const { id: userId } = req.query; diff --git a/src/pages/api/users/[id]/usage.ts b/src/pages/api/users/[id]/usage.ts index b0fc2055..7cb40d61 100644 --- a/src/pages/api/users/[id]/usage.ts +++ b/src/pages/api/users/[id]/usage.ts @@ -36,9 +36,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { user } = req.auth; diff --git a/src/pages/api/users/[id]/websites.ts b/src/pages/api/users/[id]/websites.ts index 227d1c98..ede26738 100644 --- a/src/pages/api/users/[id]/websites.ts +++ b/src/pages/api/users/[id]/websites.ts @@ -27,9 +27,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { user } = req.auth; const { id: userId, page, query, includeTeams, onlyTeams } = req.query; diff --git a/src/pages/api/users/index.ts b/src/pages/api/users/index.ts index 670ddd5d..5eb26ea4 100644 --- a/src/pages/api/users/index.ts +++ b/src/pages/api/users/index.ts @@ -37,9 +37,7 @@ export default async ( res: NextApiResponse, ) => { await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); if (req.method === 'GET') { if (!(await canViewUsers(req.auth))) { diff --git a/src/pages/api/websites/[id]/active.ts b/src/pages/api/websites/[id]/active.ts index abc23dd7..ef631a0e 100644 --- a/src/pages/api/websites/[id]/active.ts +++ b/src/pages/api/websites/[id]/active.ts @@ -22,9 +22,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId } = req.query; diff --git a/src/pages/api/websites/[id]/daterange.ts b/src/pages/api/websites/[id]/daterange.ts index bfa5338e..5bf76a91 100644 --- a/src/pages/api/websites/[id]/daterange.ts +++ b/src/pages/api/websites/[id]/daterange.ts @@ -22,9 +22,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId } = req.query; diff --git a/src/pages/api/websites/[id]/events.ts b/src/pages/api/websites/[id]/events.ts index 32288aa5..05a651ab 100644 --- a/src/pages/api/websites/[id]/events.ts +++ b/src/pages/api/websites/[id]/events.ts @@ -34,9 +34,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId, timezone, url } = req.query; const { startDate, endDate, unit } = await parseDateRangeQuery(req); diff --git a/src/pages/api/websites/[id]/index.ts b/src/pages/api/websites/[id]/index.ts index e7c7e004..084d0fea 100644 --- a/src/pages/api/websites/[id]/index.ts +++ b/src/pages/api/websites/[id]/index.ts @@ -36,9 +36,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId } = req.query; diff --git a/src/pages/api/websites/[id]/metrics.ts b/src/pages/api/websites/[id]/metrics.ts index 89f90fc4..56b0b066 100644 --- a/src/pages/api/websites/[id]/metrics.ts +++ b/src/pages/api/websites/[id]/metrics.ts @@ -54,9 +54,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId, diff --git a/src/pages/api/websites/[id]/pageviews.ts b/src/pages/api/websites/[id]/pageviews.ts index 0f034cc2..7356c504 100644 --- a/src/pages/api/websites/[id]/pageviews.ts +++ b/src/pages/api/websites/[id]/pageviews.ts @@ -50,9 +50,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId, diff --git a/src/pages/api/websites/[id]/reports.ts b/src/pages/api/websites/[id]/reports.ts index ec8109f8..da6ef7f1 100644 --- a/src/pages/api/websites/[id]/reports.ts +++ b/src/pages/api/websites/[id]/reports.ts @@ -22,9 +22,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId } = req.query; diff --git a/src/pages/api/websites/[id]/reset.ts b/src/pages/api/websites/[id]/reset.ts index b17fdade..64757411 100644 --- a/src/pages/api/websites/[id]/reset.ts +++ b/src/pages/api/websites/[id]/reset.ts @@ -22,8 +22,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId } = req.query; diff --git a/src/pages/api/websites/[id]/stats.ts b/src/pages/api/websites/[id]/stats.ts index e0c71e40..4e8d2a88 100644 --- a/src/pages/api/websites/[id]/stats.ts +++ b/src/pages/api/websites/[id]/stats.ts @@ -50,9 +50,7 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId, diff --git a/src/pages/api/websites/[id]/values.ts b/src/pages/api/websites/[id]/values.ts index 1f479aeb..85d029d0 100644 --- a/src/pages/api/websites/[id]/values.ts +++ b/src/pages/api/websites/[id]/values.ts @@ -20,9 +20,7 @@ const schema = { export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => { await useCors(req, res); await useAuth(req, res); - - req.yup = schema; - await useValidate(req, res); + await useValidate(schema, req, res); const { id: websiteId, type } = req.query; diff --git a/src/pages/api/websites/index.ts b/src/pages/api/websites/index.ts index dc9ec36d..329d155c 100644 --- a/src/pages/api/websites/index.ts +++ b/src/pages/api/websites/index.ts @@ -34,8 +34,8 @@ export default async ( ) => { await useCors(req, res); await useAuth(req, res); - req.yup = schema; - await useValidate(req, res); + + await useValidate(schema, req, res); const { user: { id: userId },