feat: add append-only course/user data import and expand user profile
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.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// /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
|
||||
};
|
||||
Reference in New Issue
Block a user