also set nym

This commit is contained in:
counterweight 2025-02-14 01:56:41 +01:00
parent 6b52d06b3e
commit 90d8e39eb3
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
4 changed files with 82 additions and 3 deletions

27
src/models/NymSet.js Normal file
View file

@ -0,0 +1,27 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
const NymSet = sequelize.define('NymSet', {
uuid: {
type: DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true
},
public_key: {
type: DataTypes.STRING,
allowNull: false
},
nym: {
type: DataTypes.TEXT,
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: false
}
}, {
tableName: 'nym_set'
});
module.exports = NymSet;

View file

@ -88,6 +88,17 @@ window.onload = () => {
},
body: JSON.stringify({ encryptedContactDetails })
});
const nym = document.querySelector('#nym-input').value;
await fetch('/api/set-nym',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ nym })
});
}
);
};

View file

@ -115,6 +115,34 @@ router.post(
success: true,
message: 'Contact details set successfully.'
})
})
}
);
router.post(
"/set-nym",
rejectIfNotAuthorizedMiddleware,
attachPublicKeyMiddleware,
async (req, res) => {
const nym = req.body.nym;
const publicKey = req.cookies.publicKey;
if (!nym) {
return res.status(400).json({
success: false,
message: 'Missing nym'
})
}
await profileService.setNym(
publicKey,
nym
)
return res.status(200).json({
success: true,
message: 'Nym set successfully.'
})
}
);
module.exports = router;

View file

@ -1,8 +1,9 @@
const uuid = require('uuid');
const ContactDetailsSet = require('../models/ContactDetailsSet');
const NymSet = require('../models/NymSet');
async function setContactDetails(publicKey, encryptedContactDetails) {
return ContactDetailsSet.create(
return await ContactDetailsSet.create(
{
'uuid': uuid.v7(),
public_key: publicKey,
@ -12,6 +13,18 @@ async function setContactDetails(publicKey, encryptedContactDetails) {
)
}
async function setNym(publicKey, nym) {
return await NymSet.create(
{
'uuid': uuid.v7(),
public_key: publicKey,
nym: nym,
created_at: new Date().toISOString()
}
)
}
module.exports = {
setContactDetails
setContactDetails,
setNym
};