mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
add server to monorepo.
This commit is contained in:
35
packages/server/src/services/Sales/SaleNotifyBySms.ts
Normal file
35
packages/server/src/services/Sales/SaleNotifyBySms.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import parsePhoneNumber from 'libphonenumber-js';
|
||||
import { Service } from 'typedi';
|
||||
|
||||
const ERRORS = {
|
||||
CUSTOMER_HAS_NO_PHONE_NUMBER: 'CUSTOMER_HAS_NO_PHONE_NUMBER',
|
||||
CUSTOMER_SMS_NOTIFY_PHONE_INVALID: 'CUSTOMER_SMS_NOTIFY_PHONE_INVALID',
|
||||
};
|
||||
|
||||
@Service()
|
||||
export default class SaleNotifyBySms {
|
||||
/**
|
||||
* Validate the customer phone number.
|
||||
* @param {ICustomer} customer
|
||||
*/
|
||||
public validateCustomerPhoneNumber = (personalPhone: string) => {
|
||||
if (!personalPhone) {
|
||||
throw new ServiceError(ERRORS.CUSTOMER_HAS_NO_PHONE_NUMBER);
|
||||
}
|
||||
|
||||
this.validateCustomerPhoneNumberLocally(personalPhone);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} personalPhone
|
||||
*/
|
||||
public validateCustomerPhoneNumberLocally = (personalPhone: string) => {
|
||||
const phoneNumber = parsePhoneNumber(personalPhone, 'LY');
|
||||
|
||||
if (!phoneNumber || !phoneNumber.isValid()) {
|
||||
throw new ServiceError(ERRORS.CUSTOMER_SMS_NOTIFY_PHONE_INVALID);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user