@resolveio/server-lib 12.7.1 → 12.7.3

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.
@@ -123,8 +123,9 @@ export declare class MongoManagerCollection<T extends CollectionDocument> {
123
123
  createLogs: boolean;
124
124
  useRB: boolean;
125
125
  collectionOptions: CreateCollectionOptions;
126
- private static indexQueue;
127
126
  constructor(options: MongoManagerCollectionOptions);
127
+ private static indexQueue;
128
+ extractIndexNameFromError(errorMessage: any): any;
128
129
  aggregate(pipeline: object[], options?: AggregateOptions, skipCache?: boolean): Promise<any[]>;
129
130
  aggregateCount(pipeline: object[], options?: AggregateOptions): Promise<number>;
130
131
  aggregateCursor(pipeline: object[], options?: AggregateOptions): AggregationCursor;
@@ -441,6 +441,17 @@ var MongoManagerCollection = /** @class */ (function () {
441
441
  }
442
442
  }, 1);
443
443
  }
444
+ // Method to extract index name from error message
445
+ MongoManagerCollection.prototype.extractIndexNameFromError = function (errorMessage) {
446
+ var regexPattern = /Index already exists with a different name: (\S+)/;
447
+ var matches = errorMessage.match(regexPattern);
448
+ if (!matches || matches.length <= 1) {
449
+ // If the first pattern doesn't match, try the second pattern
450
+ regexPattern = /existing index:.*name: "([^"]+)"/;
451
+ matches = errorMessage.match(regexPattern);
452
+ }
453
+ return matches && matches.length > 1 ? matches[1] : null;
454
+ };
444
455
  MongoManagerCollection.prototype.aggregate = function (pipeline, options, skipCache) {
445
456
  var _this = this;
446
457
  if (skipCache === void 0) { skipCache = false; }
@@ -619,13 +630,13 @@ var MongoManagerCollection = /** @class */ (function () {
619
630
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
620
631
  var docs, i, doc, versionDoc, monitor;
621
632
  var _this = this;
622
- return __generator(this, function (_a) {
623
- switch (_a.label) {
633
+ return __generator(this, function (_b) {
634
+ switch (_b.label) {
624
635
  case 0:
625
636
  if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
626
637
  return [4 /*yield*/, this.find(filter)];
627
638
  case 1:
628
- docs = _a.sent();
639
+ docs = _b.sent();
629
640
  for (i = 0; i < docs.length; i++) {
630
641
  doc = docs[i];
631
642
  log_collection_1.Logs.insertOne({
@@ -647,7 +658,7 @@ var MongoManagerCollection = /** @class */ (function () {
647
658
  index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [{ '_id._id': doc._id }, { '_id.__v': { $lt: doc.__v - 1 } }] });
648
659
  }
649
660
  }
650
- _a.label = 2;
661
+ _b.label = 2;
651
662
  case 2:
652
663
  monitor = new monitor_manager_1.MonitorMongo('deleteMany', this.collectionName, JSON.stringify([filter, options]));
653
664
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).deleteMany(filter, options).then(function (res) {
@@ -676,12 +687,12 @@ var MongoManagerCollection = /** @class */ (function () {
676
687
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
677
688
  var monitor_3, monitor_4;
678
689
  var _this = this;
679
- return __generator(this, function (_a) {
690
+ return __generator(this, function (_b) {
680
691
  if (this.createLogs && !bypassLogs) {
681
692
  monitor_3 = new monitor_manager_1.MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));
682
693
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).findOneAndDelete(filter, options).then(function (returnVal) { return __awaiter(_this, void 0, void 0, function () {
683
694
  var doc, versionDoc;
684
- return __generator(this, function (_a) {
695
+ return __generator(this, function (_b) {
685
696
  monitor_3.finish();
686
697
  doc = returnVal;
687
698
  if (doc) {
@@ -803,7 +814,7 @@ var MongoManagerCollection = /** @class */ (function () {
803
814
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
804
815
  var monitor_5;
805
816
  var _this = this;
806
- return __generator(this, function (_a) {
817
+ return __generator(this, function (_b) {
807
818
  if (!skipCache) {
808
819
  index_1.ResolveIOServer.getMongoManager().addToQueue({
809
820
  _id: 0,
@@ -941,7 +952,7 @@ var MongoManagerCollection = /** @class */ (function () {
941
952
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
942
953
  var monitor;
943
954
  var _this = this;
944
- return __generator(this, function (_a) {
955
+ return __generator(this, function (_b) {
945
956
  monitor = new monitor_manager_1.MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));
946
957
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).findOneAndDelete(filter, options).then(function (res) {
947
958
  monitor.finish();
@@ -989,7 +1000,7 @@ var MongoManagerCollection = /** @class */ (function () {
989
1000
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
990
1001
  var validation, isValid, date, monitor;
991
1002
  var _this = this;
992
- return __generator(this, function (_a) {
1003
+ return __generator(this, function (_b) {
993
1004
  if (this.checkSchema && !bypassCheckSchema) {
994
1005
  validation = this.simplschema.newContext();
995
1006
  isValid = validation.validate(replacement);
@@ -1062,7 +1073,7 @@ var MongoManagerCollection = /** @class */ (function () {
1062
1073
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1063
1074
  var validation, isValid, date, monitor;
1064
1075
  var _this = this;
1065
- return __generator(this, function (_a) {
1076
+ return __generator(this, function (_b) {
1066
1077
  if (this.checkSchema && !bypassCheckSchema) {
1067
1078
  validation = this.simplschema.newContext();
1068
1079
  isValid = validation.validate(update, { modifier: true });
@@ -1180,7 +1191,7 @@ var MongoManagerCollection = /** @class */ (function () {
1180
1191
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1181
1192
  var validationResults, validDocs, i, doc, date, monitor_7;
1182
1193
  var _this = this;
1183
- return __generator(this, function (_a) {
1194
+ return __generator(this, function (_b) {
1184
1195
  if (!docs.length) {
1185
1196
  resolve([]);
1186
1197
  return [2 /*return*/];
@@ -1261,7 +1272,7 @@ var MongoManagerCollection = /** @class */ (function () {
1261
1272
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1262
1273
  var validation, isValid, date, monitor;
1263
1274
  var _this = this;
1264
- return __generator(this, function (_a) {
1275
+ return __generator(this, function (_b) {
1265
1276
  if (!doc._id) {
1266
1277
  doc._id = objectIdHexString();
1267
1278
  }
@@ -1347,8 +1358,8 @@ var MongoManagerCollection = /** @class */ (function () {
1347
1358
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1348
1359
  var validation, isValid, date, versionDoc, monitor_8, prevDoc, docId, docVersion, updatedDoc_1, monitor_9, monitor_10, monitor_11, monitor_12;
1349
1360
  var _this = this;
1350
- return __generator(this, function (_a) {
1351
- switch (_a.label) {
1361
+ return __generator(this, function (_b) {
1362
+ switch (_b.label) {
1352
1363
  case 0:
1353
1364
  if (this.checkSchema && !bypassCheckSchema) {
1354
1365
  validation = this.simplschema.newContext();
@@ -1368,8 +1379,8 @@ var MongoManagerCollection = /** @class */ (function () {
1368
1379
  if (!!doc) return [3 /*break*/, 2];
1369
1380
  return [4 /*yield*/, this.findOne(filter, null, true)];
1370
1381
  case 1:
1371
- doc = _a.sent();
1372
- _a.label = 2;
1382
+ doc = _b.sent();
1383
+ _b.label = 2;
1373
1384
  case 2:
1374
1385
  if (!doc) return [3 /*break*/, 6];
1375
1386
  if (this.timestamps && !replacement.createdAt && doc.createdAt) {
@@ -1422,7 +1433,7 @@ var MongoManagerCollection = /** @class */ (function () {
1422
1433
  }
1423
1434
  }, null, true)];
1424
1435
  case 4:
1425
- prevDoc = _a.sent();
1436
+ prevDoc = _b.sent();
1426
1437
  if (prevDoc) {
1427
1438
  docId = doc._id;
1428
1439
  docVersion = doc.__v;
@@ -1462,7 +1473,7 @@ var MongoManagerCollection = /** @class */ (function () {
1462
1473
  else {
1463
1474
  reject('Invalid Version And Could Not Find History - DB: ' + doc.__v + ', Trying to update with :' + replacement.__v);
1464
1475
  }
1465
- _a.label = 5;
1476
+ _b.label = 5;
1466
1477
  case 5: return [3 /*break*/, 7];
1467
1478
  case 6:
1468
1479
  if (options && options.upsert) {
@@ -1506,7 +1517,7 @@ var MongoManagerCollection = /** @class */ (function () {
1506
1517
  else {
1507
1518
  reject('No Document');
1508
1519
  }
1509
- _a.label = 7;
1520
+ _b.label = 7;
1510
1521
  case 7: return [3 /*break*/, 9];
1511
1522
  case 8:
1512
1523
  if (options && options.upsert) {
@@ -1582,7 +1593,7 @@ var MongoManagerCollection = /** @class */ (function () {
1582
1593
  reject(err);
1583
1594
  });
1584
1595
  }
1585
- _a.label = 9;
1596
+ _b.label = 9;
1586
1597
  case 9: return [2 /*return*/];
1587
1598
  }
1588
1599
  });
@@ -1596,8 +1607,8 @@ var MongoManagerCollection = /** @class */ (function () {
1596
1607
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1597
1608
  var date, validation, isValid, docs, i, doc, versionDoc, monitor;
1598
1609
  var _this = this;
1599
- return __generator(this, function (_a) {
1600
- switch (_a.label) {
1610
+ return __generator(this, function (_b) {
1611
+ switch (_b.label) {
1601
1612
  case 0:
1602
1613
  if ((!update.$inc || JSON.stringify(update.$inc) === '{}') && (!update.$set || JSON.stringify(update.$set) === '{}') && (!update.$setOnInsert || JSON.stringify(update.$setOnInsert) === '{}') && (!update.$unset || JSON.stringify(update.$unset) === '{}')) {
1603
1614
  resolve(1);
@@ -1625,7 +1636,7 @@ var MongoManagerCollection = /** @class */ (function () {
1625
1636
  if (!((this.useVersions && !bypassVersions) || (this.createLogs && !bypassLogs))) return [3 /*break*/, 2];
1626
1637
  return [4 /*yield*/, this.find(filter)];
1627
1638
  case 1:
1628
- docs = _a.sent();
1639
+ docs = _b.sent();
1629
1640
  for (i = 0; i < docs.length; i++) {
1630
1641
  doc = docs[i];
1631
1642
  if (this.createLogs && !bypassLogs) {
@@ -1659,7 +1670,7 @@ var MongoManagerCollection = /** @class */ (function () {
1659
1670
  }
1660
1671
  }
1661
1672
  }
1662
- _a.label = 2;
1673
+ _b.label = 2;
1663
1674
  case 2:
1664
1675
  monitor = new monitor_manager_1.MonitorMongo('updateMany', this.collectionName, JSON.stringify([filter, update, options]));
1665
1676
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateMany(filter, update, options).then(function (res) {
@@ -1688,8 +1699,8 @@ var MongoManagerCollection = /** @class */ (function () {
1688
1699
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1689
1700
  var validation, isValid, date, doc, versionDoc, monitor_13, monitor_14, monitor_15, monitor_16;
1690
1701
  var _this = this;
1691
- return __generator(this, function (_a) {
1692
- switch (_a.label) {
1702
+ return __generator(this, function (_b) {
1703
+ switch (_b.label) {
1693
1704
  case 0:
1694
1705
  if (this.checkSchema && !bypassCheckSchema) {
1695
1706
  validation = this.simplschema.newContext();
@@ -1717,7 +1728,7 @@ var MongoManagerCollection = /** @class */ (function () {
1717
1728
  if (!this.useVersions) return [3 /*break*/, 2];
1718
1729
  return [4 /*yield*/, this.findOne(filter, null, true)];
1719
1730
  case 1:
1720
- doc = _a.sent();
1731
+ doc = _b.sent();
1721
1732
  if (doc) {
1722
1733
  if (this.createLogs && !bypassLogs) {
1723
1734
  log_collection_1.Logs.insertOne({
@@ -1913,7 +1924,7 @@ var MongoManagerCollection = /** @class */ (function () {
1913
1924
  reject(err);
1914
1925
  });
1915
1926
  }
1916
- _a.label = 3;
1927
+ _b.label = 3;
1917
1928
  case 3: return [2 /*return*/];
1918
1929
  }
1919
1930
  });
@@ -1939,22 +1950,64 @@ var MongoManagerCollection = /** @class */ (function () {
1939
1950
  });
1940
1951
  return stream;
1941
1952
  };
1942
- MongoManagerCollection.indexQueue = async_1.default.queue(function (task, callback) {
1943
- var action = task.action, collection = task.collection, specs = task.specs, options = task.options;
1944
- var dbCollection = index_1.ResolveIOServer.getMainDB().collection(collection.collectionName, collection.collectionOptions);
1945
- if (!dbCollection) {
1946
- return callback(new Error("Collection ".concat(collection.collectionName, " not found")));
1947
- }
1948
- var monitor = new monitor_manager_1.MonitorMongo(action, collection.collectionName, JSON.stringify([specs, options]));
1949
- dbCollection[action].apply(dbCollection, __spreadArray(__spreadArray([], specs, false), [options], false)).then(function (res) {
1950
- monitor.finish();
1951
- callback(null, res);
1952
- }).catch(function (err) {
1953
- monitor.finish();
1954
- console.log(new Date(), "Error Setting Up ".concat(action === 'createIndex' ? 'Index' : 'Indexes', " for Collection"), collection.collectionName, specs, options, err);
1955
- callback(err);
1953
+ var _a;
1954
+ _a = MongoManagerCollection;
1955
+ MongoManagerCollection.indexQueue = async_1.default.queue(function (task, callback) { return __awaiter(void 0, void 0, void 0, function () {
1956
+ var action, collection, specs, options, dbCollection, monitor, createIndex;
1957
+ return __generator(_a, function (_b) {
1958
+ switch (_b.label) {
1959
+ case 0:
1960
+ action = task.action, collection = task.collection, specs = task.specs, options = task.options;
1961
+ dbCollection = index_1.ResolveIOServer.getMainDB().collection(collection.collectionName, collection.collectionOptions);
1962
+ if (!dbCollection) {
1963
+ return [2 /*return*/, callback(new Error("Collection ".concat(collection.collectionName, " not found")))];
1964
+ }
1965
+ monitor = new monitor_manager_1.MonitorMongo(action, collection.collectionName, JSON.stringify([specs, options]));
1966
+ createIndex = function () { return __awaiter(void 0, void 0, void 0, function () {
1967
+ var result, err_1, existingIndexName, innerError_1;
1968
+ return __generator(this, function (_b) {
1969
+ switch (_b.label) {
1970
+ case 0:
1971
+ _b.trys.push([0, 2, , 9]);
1972
+ return [4 /*yield*/, dbCollection[action].apply(dbCollection, __spreadArray(__spreadArray([], specs, false), [options], false))];
1973
+ case 1:
1974
+ result = _b.sent();
1975
+ monitor.finish();
1976
+ callback(null, result);
1977
+ return [3 /*break*/, 9];
1978
+ case 2:
1979
+ err_1 = _b.sent();
1980
+ if (!(err_1.code === 85 || err_1.message.includes('IndexOptionsConflict'))) return [3 /*break*/, 8];
1981
+ _b.label = 3;
1982
+ case 3:
1983
+ _b.trys.push([3, 7, , 8]);
1984
+ existingIndexName = collection.extractIndexNameFromError(err_1.message);
1985
+ if (!existingIndexName) return [3 /*break*/, 6];
1986
+ return [4 /*yield*/, dbCollection.dropIndex(existingIndexName)];
1987
+ case 4:
1988
+ _b.sent();
1989
+ return [4 /*yield*/, createIndex()];
1990
+ case 5: return [2 /*return*/, _b.sent()];
1991
+ case 6: return [3 /*break*/, 8];
1992
+ case 7:
1993
+ innerError_1 = _b.sent();
1994
+ callback(innerError_1);
1995
+ return [3 /*break*/, 8];
1996
+ case 8:
1997
+ monitor.finish();
1998
+ callback(err_1);
1999
+ return [3 /*break*/, 9];
2000
+ case 9: return [2 /*return*/];
2001
+ }
2002
+ });
2003
+ }); };
2004
+ return [4 /*yield*/, createIndex()];
2005
+ case 1:
2006
+ _b.sent();
2007
+ return [2 /*return*/];
2008
+ }
1956
2009
  });
1957
- }, 1);
2010
+ }); }, 1);
1958
2011
  return MongoManagerCollection;
1959
2012
  }());
1960
2013
  exports.MongoManagerCollection = MongoManagerCollection;
@@ -1967,11 +2020,11 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
1967
2020
  var _this = this;
1968
2021
  return function (username, password, cb) { return __awaiter(_this, void 0, void 0, function () {
1969
2022
  var user;
1970
- return __generator(this, function (_a) {
1971
- switch (_a.label) {
2023
+ return __generator(this, function (_b) {
2024
+ switch (_b.label) {
1972
2025
  case 0: return [4 /*yield*/, user_collection_1.Users.findOne({ username: username })];
1973
2026
  case 1:
1974
- user = _a.sent();
2027
+ user = _b.sent();
1975
2028
  this.authenticate(user, password).then(function (authUser) {
1976
2029
  if (authUser.data) {
1977
2030
  cb(null, user, null);
@@ -1992,8 +2045,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
1992
2045
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1993
2046
  var attemptsInterval, calculatedInterval;
1994
2047
  var _this = this;
1995
- return __generator(this, function (_a) {
1996
- switch (_a.label) {
2048
+ return __generator(this, function (_b) {
2049
+ switch (_b.label) {
1997
2050
  case 0:
1998
2051
  attemptsInterval = Math.pow(100, Math.log(user.attempts + 1));
1999
2052
  calculatedInterval = attemptsInterval < 300000 ? attemptsInterval : 300000;
@@ -2002,7 +2055,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2002
2055
  user.last = new Date();
2003
2056
  return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last } })];
2004
2057
  case 1:
2005
- _a.sent();
2058
+ _b.sent();
2006
2059
  resolve({
2007
2060
  data: null,
2008
2061
  error: 'Attempt Too Soon'
@@ -2011,7 +2064,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2011
2064
  case 2: return [3 /*break*/, 4];
2012
2065
  case 3:
2013
2066
  user.last = new Date();
2014
- _a.label = 4;
2067
+ _b.label = 4;
2015
2068
  case 4:
2016
2069
  if (user.attempts >= 5) {
2017
2070
  resolve({
@@ -2032,8 +2085,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2032
2085
  keylen: 512,
2033
2086
  digestAlgorithm: 'sha256'
2034
2087
  }, function (err, hashBuffer) { return __awaiter(_this, void 0, void 0, function () {
2035
- return __generator(this, function (_a) {
2036
- switch (_a.label) {
2088
+ return __generator(this, function (_b) {
2089
+ switch (_b.label) {
2037
2090
  case 0:
2038
2091
  if (err) {
2039
2092
  return [2 /*return*/, reject(err)];
@@ -2043,7 +2096,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2043
2096
  user.attempts = 0;
2044
2097
  return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
2045
2098
  case 1:
2046
- _a.sent();
2099
+ _b.sent();
2047
2100
  resolve({
2048
2101
  data: user,
2049
2102
  error: ''
@@ -2054,7 +2107,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2054
2107
  user.attempts = user.attempts + 1;
2055
2108
  return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
2056
2109
  case 3:
2057
- _a.sent();
2110
+ _b.sent();
2058
2111
  if (user.attempts >= 5) {
2059
2112
  resolve({
2060
2113
  data: null,
@@ -2067,7 +2120,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2067
2120
  error: 'Invalid Username And Password'
2068
2121
  });
2069
2122
  }
2070
- _a.label = 4;
2123
+ _b.label = 4;
2071
2124
  case 4: return [2 /*return*/];
2072
2125
  }
2073
2126
  });
@@ -2095,8 +2148,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2095
2148
  var _this = this;
2096
2149
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
2097
2150
  var saltBuffer, salt, hashRaw, hash;
2098
- return __generator(this, function (_a) {
2099
- switch (_a.label) {
2151
+ return __generator(this, function (_b) {
2152
+ switch (_b.label) {
2100
2153
  case 0:
2101
2154
  if (!!user) return [3 /*break*/, 1];
2102
2155
  reject('No User');
@@ -2107,7 +2160,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2107
2160
  return [3 /*break*/, 5];
2108
2161
  case 2: return [4 /*yield*/, randomBytes(32)];
2109
2162
  case 3:
2110
- saltBuffer = _a.sent();
2163
+ saltBuffer = _b.sent();
2111
2164
  salt = saltBuffer.toString('hex');
2112
2165
  return [4 /*yield*/, pbkdf2Promisified(password, salt, {
2113
2166
  iterations: 25000,
@@ -2115,10 +2168,10 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2115
2168
  digestAlgorithm: 'sha256'
2116
2169
  })];
2117
2170
  case 4:
2118
- hashRaw = _a.sent();
2171
+ hashRaw = _b.sent();
2119
2172
  hash = Buffer.from(hashRaw, 'binary').toString('hex');
2120
2173
  user_collection_1.Users.updateOne({ _id: user._id }, { $set: { hash: hash, salt: salt, services: {}, attempts: 0 } }).then(function (res) { return resolve(res); }, function (rej) { return reject(rej); });
2121
- _a.label = 5;
2174
+ _b.label = 5;
2122
2175
  case 5: return [2 /*return*/];
2123
2176
  }
2124
2177
  });
@@ -2129,8 +2182,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2129
2182
  var _this = this;
2130
2183
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
2131
2184
  var authUser;
2132
- return __generator(this, function (_a) {
2133
- switch (_a.label) {
2185
+ return __generator(this, function (_b) {
2186
+ switch (_b.label) {
2134
2187
  case 0:
2135
2188
  if (!!user) return [3 /*break*/, 1];
2136
2189
  reject('Missing User');
@@ -2141,14 +2194,14 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2141
2194
  return [3 /*break*/, 4];
2142
2195
  case 2: return [4 /*yield*/, this.authenticate(user, oldPassword)];
2143
2196
  case 3:
2144
- authUser = _a.sent();
2197
+ authUser = _b.sent();
2145
2198
  if (!authUser['data']) {
2146
2199
  reject(authUser['error']);
2147
2200
  }
2148
2201
  else {
2149
2202
  this.setPassword(user, newPassword).then(function (res) { return resolve(res); }, function (rej) { return reject(rej); });
2150
2203
  }
2151
- _a.label = 4;
2204
+ _b.label = 4;
2152
2205
  case 4: return [2 /*return*/];
2153
2206
  }
2154
2207
  });
@@ -2158,21 +2211,21 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2158
2211
  var _this = this;
2159
2212
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
2160
2213
  var dbUser;
2161
- return __generator(this, function (_a) {
2162
- switch (_a.label) {
2214
+ return __generator(this, function (_b) {
2215
+ switch (_b.label) {
2163
2216
  case 0:
2164
2217
  if (!!user.username) return [3 /*break*/, 1];
2165
2218
  reject('Missing Username');
2166
2219
  return [3 /*break*/, 5];
2167
2220
  case 1: return [4 /*yield*/, user_collection_1.Users.findOne({ username: user.username })];
2168
2221
  case 2:
2169
- dbUser = _a.sent();
2222
+ dbUser = _b.sent();
2170
2223
  if (!dbUser) return [3 /*break*/, 3];
2171
2224
  reject('Username Exists');
2172
2225
  return [3 /*break*/, 5];
2173
2226
  case 3: return [4 /*yield*/, user_collection_1.Users.findOne({ email: user.email })];
2174
2227
  case 4:
2175
- dbUser = _a.sent();
2228
+ dbUser = _b.sent();
2176
2229
  if (dbUser) {
2177
2230
  reject('Email Exists');
2178
2231
  }
@@ -2180,7 +2233,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2180
2233
  user.setPassword(password);
2181
2234
  resolve(user);
2182
2235
  }
2183
- _a.label = 5;
2236
+ _b.label = 5;
2184
2237
  case 5: return [2 /*return*/];
2185
2238
  }
2186
2239
  });