Add about me

This commit is contained in:
xfarrow
2024-03-04 15:15:09 +01:00
parent 08623759cb
commit 3b5114dee0
6 changed files with 35 additions and 32 deletions

View File

@ -78,12 +78,16 @@ app.use('/api', protectedRoutes); // Routes requiring token
===== END ROUTE HANDLING ===== ===== END ROUTE HANDLING =====
*/ */
// Start the server // Do not start the server in testing environment
// Default port is 3000 // It will be started by the test suite
const port = process.env.API_SERVER_PORT || 3000; if (process.argv[2] != 'testing') {
app.listen(port, () => { // Start the server
console.log(`Blink API server is running on port ${port}`); // Default port is 3000
}); const port = process.env.API_SERVER_PORT || 3000;
app.listen(port, () => {
console.log(`Blink API server is running on port ${port}`);
});
}
// Export the app for testing purposes // Export the app for testing purposes
module.exports = app; module.exports = app;

View File

@ -18,22 +18,23 @@ const bcrypt = require('bcrypt');
* Creates Person object by the specified fields * Creates Person object by the specified fields
* @param {*} email * @param {*} email
* @param {*} password * @param {*} password
* @param {*} display_name * @param {*} displayName
* @param {*} date_of_birth * @param {*} dateOfBirth
* @param {*} available * @param {*} available
* @param {*} enabled * @param {*} enabled
* @param {*} place_of_living * @param {*} placeOfLiving
* @returns * @returns
*/ */
function createPerson (email, password, display_name, date_of_birth, available, enabled, place_of_living) { function createPerson (email, password, displayName, dateOfBirth, available, enabled, placeOfLiving, aboutMe) {
const person = { const person = {
email: email.toLowerCase(), email: email.toLowerCase(),
password, password,
display_name, display_name: displayName,
date_of_birth, date_of_birth: dateOfBirth,
available, available,
enabled, enabled,
place_of_living place_of_living: placeOfLiving,
about_me: aboutMe
}; };
return person; return person;
} }
@ -72,15 +73,7 @@ async function registerPerson (person, activationLink) {
// and in the "ActivationLink" one, or in neither // and in the "ActivationLink" one, or in neither
await knex.transaction(async (tr) => { await knex.transaction(async (tr) => {
const personIdResult = await tr('Person') const personIdResult = await tr('Person')
.insert({ .insert(person)
email: person.email.toLowerCase(),
password: person.password,
display_name: person.display_name,
date_of_birth: person.date_of_birth,
available: person.available,
enabled: person.enabled,
place_of_living: person.place_of_living
})
.returning('id'); .returning('id');
await tr('ActivationLink') await tr('ActivationLink')
.insert({ .insert({

View File

@ -31,7 +31,7 @@ async function createOrganization (req, res) {
try { try {
const organization = organizationModel.createOrganization(req.body.name, req.body.location, req.body.description, req.body.is_hiring); const organization = organizationModel.createOrganization(req.body.name, req.body.location, req.body.description, req.body.is_hiring);
await organizationModel.insertOrganization(organization, req.jwt.person_id); await organizationModel.insertOrganization(organization, req.jwt.person_id);
return res.status(200).json({ Organization: organization }); return res.status(200).json(organization);
} catch (error) { } catch (error) {
console.error(`Error in function ${createOrganization.name}: ${error}`); console.error(`Error in function ${createOrganization.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });

View File

@ -56,12 +56,13 @@ async function registerPerson (req, res) {
req.body.display_name, req.body.display_name,
req.body.date_of_birth, req.body.date_of_birth,
req.body.available, req.body.available,
true, false,
req.body.place_of_living); req.body.place_of_living,
req.body.about_me);
await personModel.registerPerson(personToInsert, activationLink); await personModel.registerPerson(personToInsert, activationLink);
return res.status(200).json({ activationLink }); return res.status(200).json({ activationLink });
} catch (error) { } catch (error) {
console.error(`Error in function ${console.trace()}: ${error}`); console.error(`Error in function ${registerPerson.name}: ${error}`);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
} }
} }
@ -175,6 +176,10 @@ async function updatePerson (req, res) {
updatePerson.place_of_living = req.body.place_of_living; updatePerson.place_of_living = req.body.place_of_living;
} }
if(req.body.about_me) {
updatePerson.about_me = req.body.about_me;
}
// If we are tying to change password, the old password must be provided // If we are tying to change password, the old password must be provided
if (req.body.old_password || req.body.new_password) { if (req.body.old_password || req.body.new_password) {
if(!req.body.old_password){ if(!req.body.old_password){

View File

@ -11,7 +11,8 @@ CREATE TABLE IF NOT EXISTS public."Person"
date_of_birth date, date_of_birth date,
available boolean, available boolean,
enabled boolean NOT NULL DEFAULT false, enabled boolean NOT NULL DEFAULT false,
place_of_living character varying(128) place_of_living character varying(128),
about_me character varying(4096)
) )
TABLESPACE pg_default; TABLESPACE pg_default;

View File

@ -12,11 +12,11 @@
<header> <header>
<img src="../content/profile-picture-example.jpg" alt="Profile Picture" class="profile-picture"> <img src="../content/profile-picture-example.jpg" alt="Profile Picture" class="profile-picture">
<h1 id="displayName">Name Surname</h1> <h1 id="displayName">Name Surname</h1>
<p id="profession">Web Developer</p> <p id="profession">Title</p>
</header> </header>
<section> <section>
<h2>About Me</h2> <h2>About Me</h2>
<p id="aboutMe">I am a passionate web developer with experience in HTML, CSS, and JavaScript. I enjoy creating responsive and user-friendly websites.</p> <p id="aboutMe">About me</p>
</section> </section>
<section> <section>
<h2>Experience</h2> <h2>Experience</h2>
@ -80,11 +80,10 @@
const data = await response.json(); const data = await response.json();
if (response.ok){ if (response.ok){
populateFields(data.display_name, data.email); populateFields(data.display_name, data.email, data.about_me);
document.body.style.display = 'block'; // Show page document.body.style.display = 'block'; // Show page
} }
else if (response.status == 401){ else if (response.status == 401){
console.error(data.error);
window.location.href = 'login.html'; window.location.href = 'login.html';
} }
else{ else{
@ -92,10 +91,11 @@
} }
} }
function populateFields (displayName, email) { function populateFields (displayName, email, aboutMe) {
document.getElementById('displayName').textContent = displayName; document.getElementById('displayName').textContent = displayName;
document.title = `${displayName} - Blink` document.title = `${displayName} - Blink`
document.getElementById('email').textContent = email; document.getElementById('email').textContent = email;
document.getElementById('aboutMe').textContent = aboutMe;
} }
function editProfile () { function editProfile () {