feat: add phone number sanitization helper and integrate into queue manager
- Introduced sanitizePhoneNumber function to clean and format phone numbers. - Updated GenerateQueueManager to use sanitizePhoneNumber for customer phone input.pull/172/head
parent
e478c5ed27
commit
f76bbcf19d
|
@ -14,6 +14,29 @@ export function phoneNumberOnly(phone: string): string {
|
|||
return phone.replace(/[^0-9]/g, '');
|
||||
}
|
||||
|
||||
export function sanitizePhoneNumber(phone: string): string {
|
||||
// Remove all non-numeric characters first
|
||||
const cleanPhone = phone.replace(/[^0-9]/g, '');
|
||||
|
||||
// If the number starts with '0', replace it with '+62'
|
||||
if (cleanPhone.startsWith('0')) {
|
||||
return '+62' + cleanPhone.slice(1);
|
||||
}
|
||||
|
||||
// If the number starts with '62', add '+' prefix
|
||||
if (cleanPhone.startsWith('62')) {
|
||||
return '+' + cleanPhone;
|
||||
}
|
||||
|
||||
// If the number doesn't start with '62' and is not empty, assume it's a local number and add '+62'
|
||||
if (cleanPhone.length > 0) {
|
||||
return '+62' + cleanPhone;
|
||||
}
|
||||
|
||||
// Return original if empty or invalid
|
||||
return phone;
|
||||
}
|
||||
|
||||
export function timeIsBefore(
|
||||
currentTime: number,
|
||||
time: number,
|
||||
|
|
|
@ -14,6 +14,7 @@ import { QueueTimeFormula } from './formula/queue-time.formula';
|
|||
import { RegisterQueueManager } from './register-queue.manager';
|
||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||
import { QueueModel } from '../../data/models/queue.model';
|
||||
import { sanitizePhoneNumber } from '../helpers/time.helper';
|
||||
|
||||
@Injectable()
|
||||
export class GenerateQueueManager {
|
||||
|
@ -34,7 +35,7 @@ export class GenerateQueueManager {
|
|||
const customerOrder = {
|
||||
code: invoice_code,
|
||||
customer: customer_name,
|
||||
phone: customer_phone,
|
||||
phone: sanitizePhoneNumber(customer_phone),
|
||||
date: queue_date * 1000,
|
||||
transaction_id: id,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue