This repository has been archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create param validator * Move discord * Move user settings getter to app router * Use standard var * move getAllPublicUserData to app router * Better error handling * Delete getAllData.ts * Delete discord * Throw errors * Handle error throwing * Move updateSettings to app router * Update confluence.svg * Add present params return * Fix token getter * Fix token getter
- Loading branch information
1 parent
a5d0da1
commit 3fe55bd
Showing
15 changed files
with
160 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextResponse } from "next/server"; | ||
import validateParams from "../../../../utils/api/validateParams"; | ||
import getAllPublicUserData from "../../../../utils/db/user/getAllPublicUserData"; | ||
|
||
export async function POST(request: Request) { | ||
const req = await request.json(); | ||
const { missingParams } = validateParams(req, ["email"]); | ||
|
||
if (missingParams.length > 0) { | ||
return NextResponse.json({ | ||
error: `Missing parameters: ${missingParams.join(", ")}`, | ||
}); | ||
} | ||
|
||
try { | ||
let dbResponse = await getAllPublicUserData({ email: req.email }); | ||
return NextResponse.json(dbResponse); | ||
} catch (err) { | ||
console.error("Error fetching db data:", err); | ||
return NextResponse.json({ error: "Failed to fetch db data." }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextResponse } from "next/server"; | ||
import getUserSettings from "../../../../utils/db/user/settings"; | ||
import validateParams from "../../../../utils/api/validateParams"; | ||
|
||
export async function POST(request: Request) { | ||
const req = await request.json(); | ||
const { missingParams } = validateParams(req, ["email"]); | ||
|
||
if (missingParams.length > 0) { | ||
return NextResponse.json({ | ||
error: `Missing parameters: ${missingParams.join(", ")}`, | ||
}); | ||
} | ||
|
||
try { | ||
let dbResponse = await getUserSettings({ email: req.email }); | ||
return NextResponse.json(dbResponse); | ||
} catch (err) { | ||
console.error("Error fetching db data:", err); | ||
return NextResponse.json({ error: "Failed to fetch db data." }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NextResponse } from "next/server"; | ||
import validateParams from "../../../../utils/api/validateParams"; | ||
import patchUserSettings from "../../../../utils/db/user/patchUserSettings"; | ||
|
||
export async function POST(request: Request) { | ||
const req = await request.json(); | ||
const { missingParams } = validateParams(req, ["email", "userSettings"]); | ||
|
||
if (missingParams.length > 0) { | ||
return NextResponse.json({ | ||
error: `Missing parameters: ${missingParams.join(", ")}`, | ||
}); | ||
} | ||
|
||
try { | ||
let dbResponse = await patchUserSettings({ | ||
email: req.email, | ||
userSettings: req.userSettings, | ||
}); | ||
return NextResponse.json(dbResponse); | ||
} catch (err) { | ||
console.error("Error fetching db data:", err); | ||
return NextResponse.json({ error: "Failed to fetch db data." }); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
interface ValidationResult { | ||
missingParams: string[]; | ||
presentParams: string[]; | ||
requiredParams: string[]; | ||
} | ||
|
||
export default function validateParams( | ||
body: any, | ||
requiredParams: string[] | ||
): ValidationResult { | ||
let missingParams: string[] = []; | ||
let presentParams: string[] = []; | ||
|
||
for (let paramName of requiredParams) { | ||
if (body[paramName]) { | ||
presentParams.push(paramName); | ||
} else { | ||
missingParams.push(paramName); | ||
} | ||
} | ||
|
||
return { missingParams, presentParams, requiredParams }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import "server-only"; | ||
import executeRequest from "../azuredb"; | ||
|
||
export default async function getAllPublicUserData(user): Promise<any> { | ||
export default async function getAllPublicUserData({ email }): Promise<any> { | ||
try { | ||
let data = await executeRequest( | ||
`EXEC dbo.get_user_all_public_data @watermelon_user = '${user}'` | ||
`EXEC dbo.get_user_all_public_data @watermelon_user = '${email}'` | ||
); | ||
return data; | ||
} catch (err) { | ||
console.error(err); | ||
return err; | ||
throw err; | ||
} | ||
} |
Oops, something went wrong.
3fe55bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
watermelon – ./
watermelon-nine.vercel.app
app.watermelontools.com
watermelon-git-main-watermelontools.vercel.app
watermelon-watermelontools.vercel.app