add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View 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);
}
};
}