now not duplicating npubbing
This commit is contained in:
parent
ecdaf3dfd6
commit
4df414a403
1 changed files with 18 additions and 19 deletions
37
src/app.js
37
src/app.js
|
|
@ -39,9 +39,7 @@ app.get('/', (req, res) => {
|
|||
res.render('index', { uuid: req.cookies.sessionUuid });
|
||||
});
|
||||
|
||||
|
||||
app.post('/api/session-npubbed', async (req, res) => {
|
||||
console.log(req.body);
|
||||
const sessionUuid = req.cookies.sessionUuid;
|
||||
const npub = req.body.npub;
|
||||
|
||||
|
|
@ -49,30 +47,31 @@ app.post('/api/session-npubbed', async (req, res) => {
|
|||
return res.status(400).json({ error: 'Missing session_uuid or npub' });
|
||||
}
|
||||
|
||||
console.log("This is the npub: ${npub}");
|
||||
|
||||
const thereIsAMatchingRecord = boolean(await SessionNpubbed.findOne(
|
||||
{
|
||||
where: {
|
||||
sessionUuid,
|
||||
npub
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
try {
|
||||
const existingRecord = await SessionNpubbed.findOne({
|
||||
where: { sessionUuid, npub }
|
||||
});
|
||||
|
||||
if (existingRecord) {
|
||||
console.log("Record already exists. No need to create a new one.");
|
||||
return res.json({ message: 'SessionNpubbed record already exists' });
|
||||
}
|
||||
|
||||
|
||||
console.log("No matching record found. Creating a new one...");
|
||||
|
||||
await SessionNpubbed.create({
|
||||
sessionNpubbedUuid: uuid.v7(),
|
||||
sessionUuid: sessionUuid,
|
||||
npub: npub,
|
||||
sessionUuid,
|
||||
npub,
|
||||
created_at: new Date().toISOString()
|
||||
});
|
||||
|
||||
res.json({ message: 'SessionNpubbed record created successfully' });
|
||||
return res.json({ message: 'SessionNpubbed record created successfully' });
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error('Error creating sessionNpubbed record:', error);
|
||||
res.status(500).json({ error: 'Failed to create sessionNpubbed record' });
|
||||
console.error("Error handling SessionNpubbed record:", error);
|
||||
return res.status(500).json({ error: 'Failed to process sessionNpubbed record' });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue