diff --git a/src/controllers/profileInitialSetupController.js b/src/controllers/profileInitialSetupController.js index 9c307b88f..60d66424c 100644 --- a/src/controllers/profileInitialSetupController.js +++ b/src/controllers/profileInitialSetupController.js @@ -272,10 +272,12 @@ const profileInitialSetupController = function ( const token = jwt.sign(jwtPayload, JWT_SECRET); const locationData = { + title: '', firstName: req.body.firstName, lastName: req.body.lastName, jobTitle: req.body.jobTitle, location: req.body.homeCountry, + isActive: true, }; res.send({ token }).status(200); diff --git a/src/models/mapLocation.js b/src/models/mapLocation.js index cb5644d31..5f42678d0 100644 --- a/src/models/mapLocation.js +++ b/src/models/mapLocation.js @@ -2,6 +2,23 @@ const mongoose = require('mongoose'); const { Schema } = mongoose; +const capitalizeString = (s) => { + + if (typeof s !== 'string') { + return s; + } + const words = s.split(' '); + const capitalizedWords = words.map(word => { + if (word.length > 0) { + return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); + } else { + return ''; + } + }); + const capitalizedString = capitalizedWords.join(' '); + return capitalizedString; +} + const mapLocation = new Schema({ title: { type: String, @@ -40,4 +57,12 @@ const mapLocation = new Schema({ }, }); +mapLocation.pre('save', function (next) { + this.firstName = capitalizeString(this.firstName); + this.lastName = capitalizeString(this.lastName); + this.jobTitle = capitalizeString(this.jobTitle); + this.location.userProvided = capitalizeString(this.location.userProvided); + next(); +}); + module.exports = mongoose.model('MapLocation', mapLocation, 'maplocations');