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 });
|
res.render('index', { uuid: req.cookies.sessionUuid });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.post('/api/session-npubbed', async (req, res) => {
|
app.post('/api/session-npubbed', async (req, res) => {
|
||||||
console.log(req.body);
|
|
||||||
const sessionUuid = req.cookies.sessionUuid;
|
const sessionUuid = req.cookies.sessionUuid;
|
||||||
const npub = req.body.npub;
|
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' });
|
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 {
|
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({
|
await SessionNpubbed.create({
|
||||||
sessionNpubbedUuid: uuid.v7(),
|
sessionNpubbedUuid: uuid.v7(),
|
||||||
sessionUuid: sessionUuid,
|
sessionUuid,
|
||||||
npub: npub,
|
npub,
|
||||||
created_at: new Date().toISOString()
|
created_at: new Date().toISOString()
|
||||||
});
|
});
|
||||||
|
|
||||||
res.json({ message: 'SessionNpubbed record created successfully' });
|
return res.json({ message: 'SessionNpubbed record created successfully' });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error("Error handling SessionNpubbed record:", error);
|
||||||
console.error('Error creating sessionNpubbed record:', error);
|
return res.status(500).json({ error: 'Failed to process sessionNpubbed record' });
|
||||||
res.status(500).json({ error: 'Failed to create sessionNpubbed record' });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue