@@ -32,7 +32,7 @@ import { Order } from '../models/order.entity';
3232import { Plan } from '../models/plan.entity' ;
3333import { getSlowQueries , clearSlowQueries } from '../utils/slowQueryCollector' ;
3434import { executeDeletionRequest } from '../jobs/deletionExecutionJob' ;
35- import { getGeoBlockRules , getGeoBlockLevelFromRules , getGeoBlockLevel } from '../utils/eu' ;
35+ import { getGeoBlockRules , getGeoBlockLevelFromRules , getGeoBlockLevel , getMinimumAgeForCountry } from '../utils/eu' ;
3636import { getPanelFeatureToggles } from '../utils/featureToggles' ;
3737import path from 'path' ;
3838import fs from 'fs' ;
@@ -41,6 +41,20 @@ import * as tar from 'tar';
4141import { promises as fsp } from 'fs' ;
4242import { normalizeProcessConfig } from '../utils/startupDetection' ;
4343
44+ function getAgeFromDate ( date ?: Date | string | null ) : number | null {
45+ if ( ! date ) return null ;
46+ const dob = date instanceof Date ? date : new Date ( String ( date ) ) ;
47+ if ( isNaN ( dob . getTime ( ) ) ) return null ;
48+ const now = new Date ( ) ;
49+ let age = now . getUTCFullYear ( ) - dob . getUTCFullYear ( ) ;
50+ const monthDiff = now . getUTCMonth ( ) - dob . getUTCMonth ( ) ;
51+ const dayDiff = now . getUTCDate ( ) - dob . getUTCDate ( ) ;
52+ if ( monthDiff < 0 || ( monthDiff === 0 && dayDiff < 0 ) ) {
53+ age -= 1 ;
54+ }
55+ return age ;
56+ }
57+
4458function getSafeRelativeFilePath ( base : string , relPath : string ) : string | null {
4559 const normalised = path . normalize ( String ( relPath || '' ) ) . replace ( / ^ ( [ / \\ ] ) + / , '' ) . replace ( / ^ ( \. { 2 } ( \/ | \\ | $ ) ) + / , '' ) ;
4660 const fullPath = path . join ( base , normalised ) ;
@@ -1131,10 +1145,11 @@ export async function adminRoutes(app: any, prefix = '') {
11311145 return { error : 'invalid_date_of_birth' , message : 'dateOfBirth must be a valid date string in YYYY-MM-DD format.' } ;
11321146 }
11331147 const updatedAge = getAgeFromDate ( dob ) ;
1134- if ( updatedAge !== null && updatedAge < 14 ) {
1148+ const minimumAge = await getMinimumAgeForCountry ( user . billingCountry ) ;
1149+ if ( updatedAge !== null && updatedAge < minimumAge ) {
11351150 user . suspended = true ;
11361151 user . fraudFlag = true ;
1137- user . fraudReason = ' Underage account (<14 years)' ;
1152+ user . fraudReason = ` Underage account (<${ minimumAge } years)` ;
11381153 }
11391154 user . dateOfBirth = dob ;
11401155 }
0 commit comments