dt-common-device 13.3.8 → 13.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,2 @@
1
1
  export * from "./twilio.service";
2
+ export * from "./interface/twilloInterface";
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./twilio.service"), exports);
18
+ __exportStar(require("./interface/twilloInterface"), exports);
@@ -1,7 +1,4 @@
1
1
  export interface ISendSMSRequest {
2
2
  propertyId: string;
3
- payload: {
4
- guestNumber: string;
5
- message: string;
6
- };
3
+ message: string;
7
4
  }
@@ -1,6 +1,7 @@
1
1
  import { ISendSMSRequest } from "./interface/twilloInterface";
2
2
  export declare class TwilioService {
3
3
  private readonly connectionRepository;
4
+ private readonly propertyRepository;
4
5
  constructor();
5
6
  sendSMS(data: ISendSMSRequest): Promise<any>;
6
7
  }
@@ -79,6 +79,7 @@ const typedi_1 = __importStar(require("typedi"));
79
79
  const Connection_repository_1 = require("../../entities/connection/Connection.repository");
80
80
  const IConnection_1 = require("../../entities/connection/IConnection");
81
81
  const twilio_1 = __importDefault(require("twilio"));
82
+ const Property_repository_1 = require("../../entities/property/Property.repository");
82
83
  let TwilioService = (() => {
83
84
  let _classDecorators = [(0, typedi_1.Service)()];
84
85
  let _classDescriptor;
@@ -87,12 +88,13 @@ let TwilioService = (() => {
87
88
  var TwilioService = _classThis = class {
88
89
  constructor() {
89
90
  this.connectionRepository = typedi_1.default.get(Connection_repository_1.ConnectionRepository);
91
+ this.propertyRepository = typedi_1.default.get(Property_repository_1.PropertyRepository);
90
92
  }
91
93
  // -----------------------------
92
94
  // Send SMS
93
95
  // -----------------------------
94
96
  async sendSMS(data) {
95
- const { propertyId, payload } = data;
97
+ const { propertyId, message } = data;
96
98
  //find fromNumber from the dt_connections table based on the propertyId
97
99
  const response = await this.connectionRepository.queryConnections({ propertyId, connectionProvider: IConnection_1.ConnectionProvider.Twilio });
98
100
  //need connectionId, clientSecret, metaData
@@ -101,15 +103,28 @@ let TwilioService = (() => {
101
103
  if (!fromNumber) {
102
104
  throw new Error("From number not found");
103
105
  }
106
+ //find toNumber and sms_enabled from the property settings table based on the propertyId
107
+ const _settingsRes = await this.propertyRepository.getPropertyPreferences(propertyId);
108
+ if (!_settingsRes) {
109
+ throw new Error("Property settings not found");
110
+ }
111
+ const smsEnabled = _settingsRes?.settings?.notificationPreferences?.smsNotification?.enabled;
112
+ const toNumber = _settingsRes?.settings?.notificationPreferences?.smsNotification?.toNumber;
113
+ if (!toNumber) {
114
+ return;
115
+ }
116
+ if (!smsEnabled) {
117
+ return;
118
+ }
104
119
  //TODO: Need to do singletone pattern for the client
105
120
  const client = (0, twilio_1.default)(id, clientSecret);
106
121
  try {
107
- const message = await client.messages.create({
108
- body: payload.message,
122
+ const smsResponse = await client.messages.create({
123
+ body: message,
109
124
  from: fromNumber,
110
- to: payload.guestNumber,
125
+ to: toNumber,
111
126
  });
112
- return message;
127
+ return smsResponse;
113
128
  }
114
129
  catch (error) {
115
130
  throw new Error(`Error sending SMS: ${error}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.3.8",
3
+ "version": "13.3.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [