also set nym
This commit is contained in:
parent
6b52d06b3e
commit
90d8e39eb3
4 changed files with 82 additions and 3 deletions
27
src/models/NymSet.js
Normal file
27
src/models/NymSet.js
Normal 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;
|
||||||
|
|
@ -88,6 +88,17 @@ window.onload = () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ encryptedContactDetails })
|
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 })
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
@ -115,6 +115,34 @@ router.post(
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Contact details set successfully.'
|
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;
|
module.exports = router;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
const uuid = require('uuid');
|
const uuid = require('uuid');
|
||||||
const ContactDetailsSet = require('../models/ContactDetailsSet');
|
const ContactDetailsSet = require('../models/ContactDetailsSet');
|
||||||
|
const NymSet = require('../models/NymSet');
|
||||||
|
|
||||||
async function setContactDetails(publicKey, encryptedContactDetails) {
|
async function setContactDetails(publicKey, encryptedContactDetails) {
|
||||||
return ContactDetailsSet.create(
|
return await ContactDetailsSet.create(
|
||||||
{
|
{
|
||||||
'uuid': uuid.v7(),
|
'uuid': uuid.v7(),
|
||||||
public_key: publicKey,
|
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 = {
|
module.exports = {
|
||||||
setContactDetails
|
setContactDetails,
|
||||||
|
setNym
|
||||||
};
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue