mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-26 17:02:27 -04:00
refactor: saving portfolio items (#47635)
This commit is contained in:
committed by
GitHub
parent
147ef7ba8b
commit
a2790190b2
@@ -115,23 +115,14 @@ function updateMyEmail(req, res, next) {
|
||||
// }
|
||||
|
||||
function updateMyPortfolio(...args) {
|
||||
const portfolioKeys = [
|
||||
'id',
|
||||
'title',
|
||||
'description',
|
||||
'url',
|
||||
'image',
|
||||
'isSaved'
|
||||
];
|
||||
const portfolioKeys = ['id', 'title', 'description', 'url', 'image'];
|
||||
const buildUpdate = body => {
|
||||
const portfolio = body?.portfolio?.map(elem => _.pick(elem, portfolioKeys));
|
||||
return { portfolio };
|
||||
};
|
||||
const validate = ({ portfolio }) => portfolio?.every(isPortfolioElement);
|
||||
const isPortfolioElement = elem =>
|
||||
Object.values(elem).every(
|
||||
val => typeof val == 'string' || typeof val === 'boolean'
|
||||
);
|
||||
Object.values(elem).every(val => typeof val == 'string');
|
||||
createUpdateUserProperties(buildUpdate, validate)(...args);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user