@optimiser/common 1.0.213 → 1.0.214

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.
@@ -65,4 +65,20 @@ declare const SubscribeEmailForAllDomains: (db: Db, email: string, isSubscribe:
65
65
  }
66
66
  */
67
67
  declare const IsValidPhoneNumber: (phoneNumber: string, countryCode: string) => AnyObjectInterface;
68
- export { GetCompanyDetails, GetListSchema, GetEmailwiseUnsubscribeData, GenerateAutoIncrementFieldValue, GetAccountDetailByName, GetContactDetailByEmail, GetSystemEmailTemplate, UpdateContactDetails, CreateContact, MapAccountContact, UpdatePipelineMailStatus, AddLog, CheckDateExistInRange, GetDateRangeFromOperatorValue, GetEmailSubscribeStatus, SubscribeEmailForAllDomains, IsValidPhoneNumber };
68
+ /**
69
+ *
70
+ * Server side field validatinon
71
+ * @param {db} object database connection
72
+ * @param {dataObj} object contains field data
73
+ * @param {objectType} string object name
74
+ * @param {countryCode} string, ISO country code
75
+ * @returns {
76
+ IsValid: boolean, //phone is valid or not
77
+ CountryCode?: string, //phone country code
78
+ PhoneCallingCode?: CountryCallingCode, //phone country calling code
79
+ PhoneNumberParsed?: NationalNumber, //phone no local to the country, without country calling code and only digits
80
+ Error: Error
81
+ }
82
+ */
83
+ declare function ValidateData(db: Db, dataObj: AnyObjectInterface, objectType: string): Promise<unknown>;
84
+ export { GetCompanyDetails, GetListSchema, GetEmailwiseUnsubscribeData, GenerateAutoIncrementFieldValue, GetAccountDetailByName, GetContactDetailByEmail, GetSystemEmailTemplate, UpdateContactDetails, CreateContact, MapAccountContact, UpdatePipelineMailStatus, AddLog, CheckDateExistInRange, GetDateRangeFromOperatorValue, GetEmailSubscribeStatus, SubscribeEmailForAllDomains, IsValidPhoneNumber, ValidateData };
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.IsValidPhoneNumber = exports.SubscribeEmailForAllDomains = exports.GetEmailSubscribeStatus = exports.GetDateRangeFromOperatorValue = exports.CheckDateExistInRange = exports.AddLog = exports.UpdatePipelineMailStatus = exports.MapAccountContact = exports.CreateContact = exports.UpdateContactDetails = exports.GetSystemEmailTemplate = exports.GetContactDetailByEmail = exports.GetAccountDetailByName = exports.GenerateAutoIncrementFieldValue = exports.GetEmailwiseUnsubscribeData = exports.GetListSchema = exports.GetCompanyDetails = void 0;
42
+ exports.ValidateData = exports.IsValidPhoneNumber = exports.SubscribeEmailForAllDomains = exports.GetEmailSubscribeStatus = exports.GetDateRangeFromOperatorValue = exports.CheckDateExistInRange = exports.AddLog = exports.UpdatePipelineMailStatus = exports.MapAccountContact = exports.CreateContact = exports.UpdateContactDetails = exports.GetSystemEmailTemplate = exports.GetContactDetailByEmail = exports.GetAccountDetailByName = exports.GenerateAutoIncrementFieldValue = exports.GetEmailwiseUnsubscribeData = exports.GetListSchema = exports.GetCompanyDetails = void 0;
43
43
  var mongodb_1 = require("mongodb");
44
44
  var moment_1 = __importDefault(require("moment"));
45
45
  var libphonenumber_js_1 = require("libphonenumber-js");
@@ -242,48 +242,97 @@ function UpdateContactDetails(db, contactData) {
242
242
  });
243
243
  }
244
244
  exports.UpdateContactDetails = UpdateContactDetails;
245
+ // function CreateContact(db: Db, contactData: AnyObjectInterface): Promise<null | AnyObjectInterface> {
246
+ // return new Promise(function (resolve, reject) {
247
+ // let contactObj = {
248
+ // "Salutation": null,
249
+ // "OwnerID": contactData.OwnerID,
250
+ // "FirstName": contactData.FirstName,
251
+ // "LastName": contactData.LastName,
252
+ // "ReportsTo": null,
253
+ // "JobTitle": contactData.JobTitle,
254
+ // "Department": null,
255
+ // "Email": contactData.Email,
256
+ // "PrimaryEmailCategory": contactData.PrimaryEmailCategory,
257
+ // "PhoneCountryCode": contactData.PhoneCountryCode,
258
+ // "Phone": contactData.Phone,
259
+ // "Mobile": null,
260
+ // "Birthdate": null,
261
+ // "LinkedIn": null,
262
+ // "AccountID": null,
263
+ // "Address": null,
264
+ // "City": null,
265
+ // "State": null,
266
+ // "Country": null,
267
+ // "PostalCode": null,
268
+ // "SearchAddress": {
269
+ // "lat": "",
270
+ // "lng": ""
271
+ // },
272
+ // "CreatedBy": contactData.OwnerID,
273
+ // "CreatedDate": new Date(),
274
+ // "IsActive": true,
275
+ // "RelationID": null
276
+ // }
277
+ // db.collection("Contact").insertOne(contactObj, function (error, result) {
278
+ // if (error) {
279
+ // resolve(null);
280
+ // }
281
+ // if (result) {
282
+ // resolve(result);
283
+ // } else {
284
+ // resolve(null);
285
+ // }
286
+ // });
287
+ // });
288
+ // }
245
289
  function CreateContact(db, contactData) {
246
290
  return new Promise(function (resolve, reject) {
247
- var contactObj = {
248
- "Salutation": null,
249
- "OwnerID": contactData.OwnerID,
250
- "FirstName": contactData.FirstName,
251
- "LastName": contactData.LastName,
252
- "ReportsTo": null,
253
- "JobTitle": contactData.JobTitle,
254
- "Department": null,
255
- "Email": contactData.Email,
256
- "PrimaryEmailCategory": contactData.PrimaryEmailCategory,
257
- "PhoneCountryCode": contactData.PhoneCountryCode,
258
- "Phone": contactData.Phone,
259
- "Mobile": null,
260
- "Birthdate": null,
261
- "LinkedIn": null,
262
- "AccountID": null,
263
- "Address": null,
264
- "City": null,
265
- "State": null,
266
- "Country": null,
267
- "PostalCode": null,
268
- "SearchAddress": {
269
- "lat": "",
270
- "lng": ""
271
- },
272
- "CreatedBy": contactData.OwnerID,
273
- "CreatedDate": new Date(),
274
- "IsActive": true,
275
- "RelationID": null
276
- };
277
- db.collection("Contact").insertOne(contactObj, function (error, result) {
278
- if (error) {
279
- resolve(null);
280
- }
281
- if (result) {
282
- resolve(result);
283
- }
284
- else {
285
- resolve(null);
286
- }
291
+ return __awaiter(this, void 0, void 0, function () {
292
+ var contactObj;
293
+ return __generator(this, function (_a) {
294
+ contactObj = {
295
+ "Salutation": contactData.Salutation,
296
+ "OwnerID": contactData.OwnerID,
297
+ "FirstName": contactData.FirstName,
298
+ "LastName": contactData.LastName,
299
+ "ReportsTo": null,
300
+ "JobTitle": contactData.JobTitle,
301
+ "Department": null,
302
+ "Email": contactData.Email,
303
+ "PrimaryEmailCategory": contactData.PrimaryEmailCategory,
304
+ "PhoneCountryCode": contactData.PhoneCountryCode,
305
+ "Phone": contactData.Phone,
306
+ "Mobile": null,
307
+ "Birthdate": null,
308
+ "LinkedIn": null,
309
+ "AccountID": null,
310
+ "Address": null,
311
+ "City": null,
312
+ "State": null,
313
+ "Country": null,
314
+ "PostalCode": null,
315
+ "SearchAddress": {
316
+ "lat": "",
317
+ "lng": ""
318
+ },
319
+ "CreatedBy": contactData.OwnerID,
320
+ "CreatedDate": new Date(),
321
+ "IsActive": true,
322
+ "RelationID": null
323
+ };
324
+ // let validationMsg = await ValidateData(db,contactObj,"Contact");
325
+ // if(validationMsg == 'success'){
326
+ db.collection("Contact").insertOne(contactObj, function (error, result) {
327
+ if (error) {
328
+ resolve([error, null]);
329
+ }
330
+ if (result) {
331
+ resolve([null, result]);
332
+ }
333
+ });
334
+ return [2 /*return*/];
335
+ });
287
336
  });
288
337
  });
289
338
  }
@@ -830,3 +879,40 @@ var IsValidPhoneNumber = function (phoneNumber, countryCode) {
830
879
  return result;
831
880
  };
832
881
  exports.IsValidPhoneNumber = IsValidPhoneNumber;
882
+ /**
883
+ *
884
+ * Server side field validatinon
885
+ * @param {db} object database connection
886
+ * @param {dataObj} object contains field data
887
+ * @param {objectType} string object name
888
+ * @param {countryCode} string, ISO country code
889
+ * @returns {
890
+ IsValid: boolean, //phone is valid or not
891
+ CountryCode?: string, //phone country code
892
+ PhoneCallingCode?: CountryCallingCode, //phone country calling code
893
+ PhoneNumberParsed?: NationalNumber, //phone no local to the country, without country calling code and only digits
894
+ Error: Error
895
+ }
896
+ */
897
+ function ValidateData(db, dataObj, objectType) {
898
+ return new Promise(function (resolve, reject) {
899
+ db.collection("ObjectSchema").findOne({ "Name": objectType }, function (error, result) {
900
+ if (error) {
901
+ resolve('error');
902
+ }
903
+ if (result && result.Fields) {
904
+ var emailRegexp = /^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
905
+ for (var i = 0; i < result.Fields.length; i++) {
906
+ if (result.Fields[i].IsRequired && result.Fields[i].IsRequired == true && result.Fields[i].UIDataType != 'formula' && (dataObj[result.Fields[i].Name] == '' || dataObj[result.Fields[i].Name] == null)) {
907
+ resolve(result.Fields[i].Name + ' is required');
908
+ }
909
+ if (result.Fields[i].Name == 'Email' && (!emailRegexp.test(dataObj[result.Fields[i].Name]))) {
910
+ resolve(result.Fields[i].Name + ' is not valid');
911
+ }
912
+ }
913
+ resolve('success');
914
+ }
915
+ });
916
+ });
917
+ }
918
+ exports.ValidateData = ValidateData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.213",
3
+ "version": "1.0.214",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {