api route

This commit is contained in:
BGV
2025-03-30 02:23:30 -04:00
parent 7cc033e74b
commit 5431e1fa5e

View File

@@ -23,7 +23,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { email, codeword, contacts } = req.body; const { email, codeword, contacts } = req.body;
// Perform database operations here // Perform database operations here
// query database to see if document with email exists
const existingUser = await mongoose.model('User').findOne({ email });
if (existingUser) {
// If user exists, update their codeword and contacts
await mongoose.model('User').updateOne({ email }, { codeword, contacts });
} else {
// If user does not exist, create a new user
const User = mongoose.model('User');
const newUser = new User({ email, codeword, contacts });
await newUser.save();
}
console.log("Codeword:", codeword); console.log("Codeword:", codeword);
console.log("Contacts:", contacts); console.log("Contacts:", contacts);