Standardize phone number formatting in member service and MembersView
Integrated phone number standardization in the member service to ensure consistent formatting during member updates and contact creation. Added a new utility function in MembersView for phone number standardization, enhancing data integrity and user experience when adding or updating member information.
This commit is contained in:
@@ -8,6 +8,7 @@ import fs from 'fs';
|
||||
import sharp from 'sharp';
|
||||
|
||||
import { devLog } from '../utils/logger.js';
|
||||
import { standardizePhoneNumber } from '../utils/phoneUtils.js';
|
||||
class MemberService {
|
||||
async getApprovalRequests(userToken, clubId) {
|
||||
await checkAccess(userToken, clubId);
|
||||
@@ -93,7 +94,7 @@ class MemberService {
|
||||
member.city = city;
|
||||
if (postalCode !== undefined) member.postalCode = postalCode;
|
||||
member.birthDate = birthdate;
|
||||
member.phone = phone;
|
||||
member.phone = phone ? standardizePhoneNumber(phone) : phone;
|
||||
member.email = email;
|
||||
member.active = active;
|
||||
member.testMembership = testMembership;
|
||||
@@ -111,10 +112,15 @@ class MemberService {
|
||||
// Create new contacts
|
||||
for (const contact of contacts) {
|
||||
if (contact.value && contact.type) {
|
||||
// Standardisiere Telefonnummern
|
||||
let standardizedValue = contact.value;
|
||||
if (contact.type === 'phone') {
|
||||
standardizedValue = standardizePhoneNumber(contact.value);
|
||||
}
|
||||
await MemberContact.create({
|
||||
memberId: member.id,
|
||||
type: contact.type,
|
||||
value: contact.value,
|
||||
value: standardizedValue,
|
||||
isParent: contact.isParent || false,
|
||||
parentName: contact.parentName || null,
|
||||
isPrimary: contact.isPrimary || false
|
||||
@@ -130,7 +136,7 @@ class MemberService {
|
||||
city: city,
|
||||
postalCode: postalCode || null,
|
||||
birthDate: birthdate,
|
||||
phone: phone,
|
||||
phone: phone ? standardizePhoneNumber(phone) : phone,
|
||||
email: email,
|
||||
clubId: clubId,
|
||||
active: active,
|
||||
@@ -146,10 +152,15 @@ class MemberService {
|
||||
if (Array.isArray(contacts)) {
|
||||
for (const contact of contacts) {
|
||||
if (contact.value && contact.type) {
|
||||
// Standardisiere Telefonnummern
|
||||
let standardizedValue = contact.value;
|
||||
if (contact.type === 'phone') {
|
||||
standardizedValue = standardizePhoneNumber(contact.value);
|
||||
}
|
||||
await MemberContact.create({
|
||||
memberId: newMember.id,
|
||||
type: contact.type,
|
||||
value: contact.value,
|
||||
value: standardizedValue,
|
||||
isParent: contact.isParent || false,
|
||||
parentName: contact.parentName || null,
|
||||
isPrimary: contact.isPrimary || false
|
||||
|
||||
Reference in New Issue
Block a user