-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b763fea
commit 34357b2
Showing
6 changed files
with
88 additions
and
23 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
File renamed without changes.
File renamed without changes.
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,55 @@ | ||
import {NextApiRequest, NextApiResponse} from 'next'; | ||
import {getClient, getTables, makeQuery} from "@/lib/databse"; | ||
import {GetOrigin} from "@/lib/api_tools"; | ||
import {getServerSession} from "next-auth"; | ||
import {authOptions} from "@/pages/api/auth/[...nextauth]"; | ||
|
||
export default async function handler( | ||
request: NextApiRequest, | ||
response: NextApiResponse, | ||
) { | ||
|
||
// Get the origin of the request | ||
const origin = GetOrigin(request); | ||
|
||
// Get the client | ||
const client = await getClient() | ||
|
||
// Get the tables | ||
const tables = getTables(); | ||
|
||
try { | ||
|
||
// Get the session | ||
const session = await getServerSession(request, response, authOptions) | ||
|
||
// If there is no session then return an error | ||
if(!session || !session.user) { | ||
return response.status(401).json({ error: 'User not logged in'}); | ||
} | ||
|
||
// Get the user details | ||
// @ts-ignore | ||
const user_id = session.user.database.id | ||
|
||
// Fetch the plants | ||
let query = `SELECT id, ${tables.preferred_name}, ${tables.english_name}, ${tables.maori_name}, ${tables.latin_name}, ${tables.last_modified}, ${tables.plant_type} FROM plants WHERE ${tables.author} LIKE '%,${user_id},%' OR ${tables.author} LIKE '${user_id},%' OR ${tables.author} LIKE '%,${user_id}' OR ${tables.author} LIKE '${user_id}'`; | ||
console.log(query); | ||
const plants = await makeQuery(query, client) | ||
|
||
if(plants.length == 0) { | ||
return response.status(400).json({ error: 'User doesnt have any plants'}); | ||
} | ||
|
||
// Return the user | ||
return response.status(200).json({ data: plants }); | ||
|
||
|
||
} catch (error) { | ||
console.log("Error"); | ||
console.log(error); | ||
|
||
// If there is an error, return the error | ||
return response.status(500).json({ error: error }); | ||
} | ||
} |
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
34357b2
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:
13-dgt-website – ./
13-dgt-website-maxtyson123.vercel.app
13-dgt-website.vercel.app
13-dgt-website-git-main-maxtyson123.vercel.app
rongoa.stream
www.rongoa.stream