refactor age check

This commit is contained in:
boi12321 2023-05-27 17:46:31 +02:00
parent 811c8e1c92
commit 6b92b2020d
1 changed files with 9 additions and 1 deletions

View File

@ -33,6 +33,7 @@ const capitalize = require('./utils/capitalize');
const resolvePlace = require('./utils/resolve-place');
const { resolveLayoutScraper } = require('./scrapers/resolve');
const getRecursiveParameters = require('./utils/get-recursive-parameters');
const dayjs = require('dayjs');
const hairColors = {
'jet-black': 'black',
@ -334,6 +335,13 @@ function curateProfileEntry(profile) {
return curatedProfileEntry;
}
/**
* @param {Date} birthDate
*/
function isAdult(birthDate) {
return dayjs(birthDate).diff(new Date(), "years") >= 18;
}
async function curateProfile(profile, actor) {
if (!profile) {
return null;
@ -375,7 +383,7 @@ async function curateProfile(profile, actor) {
const dateOfBirth = profile.dateOfBirth || profile.birthdate;
curatedProfile.dateOfBirth = (!Number.isNaN(Number(dateOfBirth)) // possibly valid date
&& new Date() - dateOfBirth > 567648000000 // over 18
&& isAdult(dateOfBirth) // over 18
&& dateOfBirth)
|| null;