Support uploading structured JSON to create courses, classes, and students without wiping existing data, and merge user name fields while adding gender and registration details from source sheets.
25 lines
659 B
JavaScript
25 lines
659 B
JavaScript
// /utils/userProfile.js
|
|
'use strict';
|
|
|
|
const ALLOWED_GENDERS = ['male', 'female'];
|
|
|
|
const mergeFullName = (name, surname) => {
|
|
const parts = [name, surname].map((v) => (v == null ? '' : String(v).trim())).filter(Boolean);
|
|
return parts.join(' ').trim();
|
|
};
|
|
|
|
const normalizeGender = (value) => {
|
|
if (value == null || value === '') return undefined;
|
|
const g = String(value).trim().toLowerCase();
|
|
if (ALLOWED_GENDERS.includes(g)) return g;
|
|
if (g === 'مرد' || g === 'آقا') return 'male';
|
|
if (g === 'زن' || g === 'خانم') return 'female';
|
|
return undefined;
|
|
};
|
|
|
|
module.exports = {
|
|
ALLOWED_GENDERS,
|
|
mergeFullName,
|
|
normalizeGender
|
|
};
|