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 1d1d37877a..19f0c8f164 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 1cd24fe659..b2af751114 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 7f694bc62f..a12ad92f8f 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 a601f5d645..5b7a8e05e3 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 14602157ac..b0803277db 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 ec6a555693..e5a9ad3286 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 5b1e1e057d..212d4a0f29 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 eb4199bcd4..02eb7363cf 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 a51817bf49..9071b96222 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 911d729c3b..2d59c9d6de 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 4d17c9220f..4344422af4 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 c7a5e9af38..6ff7bbe1c3 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 00d7210463..e8d3e38647 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 cc782246ea..876fbef520 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 a5527580d5..a4f80abaef 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 107aba64e2..3b16ac0586 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 2891817791..c3181e6a28 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 ada1efdc02..865ce0d2f5 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 4d14c4e9ac..5ff8c66599 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 74cb532e3e..5ad7321eb1 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 06feda8a62..0f9d01fa85 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 3ac560ede3..7926d34a52 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 f9d7f5ea26..bfa0d31acf 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 b0fc2055b2..7cb40d610e 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 227d1c98ac..ede2673870 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 670ddd5d37..5eb26ea4a2 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 abc23dd781..ef631a0e8a 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 bfa5338e4f..5bf76a91a0 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 32288aa52d..05a651ab6f 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 e7c7e004c7..084d0fea49 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 89f90fc47b..56b0b0661b 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 0f034cc2a0..7356c50424 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 ec8109f896..da6ef7f10d 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 b17fdade97..6475741114 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 e0c71e404d..4e8d2a88bd 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 1f479aebed..85d029d094 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 dc9ec36d0f..329d155c4d 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 },