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
shancheas 2025-07-08 14:12:02 +07:00
parent e478c5ed27
commit f76bbcf19d
2 changed files with 25 additions and 1 deletions

View File

@ -14,6 +14,29 @@ export function phoneNumberOnly(phone: string): string {
return phone.replace(/[^0-9]/g, ''); 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( export function timeIsBefore(
currentTime: number, currentTime: number,
time: number, time: number,

View File

@ -14,6 +14,7 @@ import { QueueTimeFormula } from './formula/queue-time.formula';
import { RegisterQueueManager } from './register-queue.manager'; import { RegisterQueueManager } from './register-queue.manager';
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model'; import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
import { QueueModel } from '../../data/models/queue.model'; import { QueueModel } from '../../data/models/queue.model';
import { sanitizePhoneNumber } from '../helpers/time.helper';
@Injectable() @Injectable()
export class GenerateQueueManager { export class GenerateQueueManager {
@ -34,7 +35,7 @@ export class GenerateQueueManager {
const customerOrder = { const customerOrder = {
code: invoice_code, code: invoice_code,
customer: customer_name, customer: customer_name,
phone: customer_phone, phone: sanitizePhoneNumber(customer_phone),
date: queue_date * 1000, date: queue_date * 1000,
transaction_id: id, transaction_id: id,
}; };