remove console.logs, POST only for updateReceipt
This commit is contained in:
parent
210f84a0b3
commit
4a957bce10
3 changed files with 12 additions and 8 deletions
|
@ -1,17 +1,22 @@
|
|||
import { MongoClient } from 'mongodb';
|
||||
import { Db, MongoClient } from 'mongodb';
|
||||
|
||||
const USERNAME = process.env.MONGO_USERNAME
|
||||
const PASSWORD = process.env.MONGO_PASSWORD
|
||||
const HOSTNAME = process.env.MONGO_HOSTNAME
|
||||
const DATABASENAME = process.env.MONGO_DATABASE_NAME
|
||||
|
||||
const URI =
|
||||
`mongodb://${USERNAME}:${PASSWORD}@${HOSTNAME ?? 'localhost'}:3001`;
|
||||
|
||||
|
||||
let db: Db | null = null;
|
||||
|
||||
export const getMongoDBClient = async () => {
|
||||
if (db) {
|
||||
return db;
|
||||
}
|
||||
const client = new MongoClient(URI);
|
||||
|
||||
await client.connect();
|
||||
const receiptdb = client.db("receipt");
|
||||
|
||||
return receiptdb.collection('receipt');
|
||||
return client.db(DATABASENAME);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,12 @@ export default async function handler(
|
|||
req: NextApiRequest,
|
||||
res: NextApiResponse<Record<string, string>[] | Record<string, string>>
|
||||
) {
|
||||
if (req.method !== 'POST') {
|
||||
return res.status(405).json({message: 'Only POST method allowed'});
|
||||
}
|
||||
const receipt = req.body;
|
||||
const client = await getMongoDBClient();
|
||||
|
||||
console.log('called', receipt);
|
||||
|
||||
try {
|
||||
// TODO implement this
|
||||
res.status(200).json(receipt);
|
||||
|
|
|
@ -58,8 +58,6 @@ const Home: NextPage = () => {
|
|||
};
|
||||
|
||||
const receiptJSONString = JSON.stringify(receiptJson);
|
||||
console.log("ASDFASDF", receiptJSONString);
|
||||
|
||||
useEffect(() => {
|
||||
const updateDb = async () => {
|
||||
const response = await fetch("/api/createReceipt", {
|
||||
|
|
Loading…
Reference in a new issue