@resolveio/server-lib 12.7.1 → 12.7.2

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,12 @@ 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
+ return matches && matches.length > 1 ? matches[1] : null;
449
+ };
444
450
  MongoManagerCollection.prototype.aggregate = function (pipeline, options, skipCache) {
445
451
  var _this = this;
446
452
  if (skipCache === void 0) { skipCache = false; }
@@ -619,13 +625,13 @@ var MongoManagerCollection = /** @class */ (function () {
619
625
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
620
626
  var docs, i, doc, versionDoc, monitor;
621
627
  var _this = this;
622
- return __generator(this, function (_a) {
623
- switch (_a.label) {
628
+ return __generator(this, function (_b) {
629
+ switch (_b.label) {
624
630
  case 0:
625
631
  if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
626
632
  return [4 /*yield*/, this.find(filter)];
627
633
  case 1:
628
- docs = _a.sent();
634
+ docs = _b.sent();
629
635
  for (i = 0; i < docs.length; i++) {
630
636
  doc = docs[i];
631
637
  log_collection_1.Logs.insertOne({
@@ -647,7 +653,7 @@ var MongoManagerCollection = /** @class */ (function () {
647
653
  index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [{ '_id._id': doc._id }, { '_id.__v': { $lt: doc.__v - 1 } }] });
648
654
  }
649
655
  }
650
- _a.label = 2;
656
+ _b.label = 2;
651
657
  case 2:
652
658
  monitor = new monitor_manager_1.MonitorMongo('deleteMany', this.collectionName, JSON.stringify([filter, options]));
653
659
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).deleteMany(filter, options).then(function (res) {
@@ -676,12 +682,12 @@ var MongoManagerCollection = /** @class */ (function () {
676
682
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
677
683
  var monitor_3, monitor_4;
678
684
  var _this = this;
679
- return __generator(this, function (_a) {
685
+ return __generator(this, function (_b) {
680
686
  if (this.createLogs && !bypassLogs) {
681
687
  monitor_3 = new monitor_manager_1.MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));
682
688
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).findOneAndDelete(filter, options).then(function (returnVal) { return __awaiter(_this, void 0, void 0, function () {
683
689
  var doc, versionDoc;
684
- return __generator(this, function (_a) {
690
+ return __generator(this, function (_b) {
685
691
  monitor_3.finish();
686
692
  doc = returnVal;
687
693
  if (doc) {
@@ -803,7 +809,7 @@ var MongoManagerCollection = /** @class */ (function () {
803
809
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
804
810
  var monitor_5;
805
811
  var _this = this;
806
- return __generator(this, function (_a) {
812
+ return __generator(this, function (_b) {
807
813
  if (!skipCache) {
808
814
  index_1.ResolveIOServer.getMongoManager().addToQueue({
809
815
  _id: 0,
@@ -941,7 +947,7 @@ var MongoManagerCollection = /** @class */ (function () {
941
947
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
942
948
  var monitor;
943
949
  var _this = this;
944
- return __generator(this, function (_a) {
950
+ return __generator(this, function (_b) {
945
951
  monitor = new monitor_manager_1.MonitorMongo('findOneAndDelete', this.collectionName, JSON.stringify([filter, options]));
946
952
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).findOneAndDelete(filter, options).then(function (res) {
947
953
  monitor.finish();
@@ -989,7 +995,7 @@ var MongoManagerCollection = /** @class */ (function () {
989
995
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
990
996
  var validation, isValid, date, monitor;
991
997
  var _this = this;
992
- return __generator(this, function (_a) {
998
+ return __generator(this, function (_b) {
993
999
  if (this.checkSchema && !bypassCheckSchema) {
994
1000
  validation = this.simplschema.newContext();
995
1001
  isValid = validation.validate(replacement);
@@ -1062,7 +1068,7 @@ var MongoManagerCollection = /** @class */ (function () {
1062
1068
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1063
1069
  var validation, isValid, date, monitor;
1064
1070
  var _this = this;
1065
- return __generator(this, function (_a) {
1071
+ return __generator(this, function (_b) {
1066
1072
  if (this.checkSchema && !bypassCheckSchema) {
1067
1073
  validation = this.simplschema.newContext();
1068
1074
  isValid = validation.validate(update, { modifier: true });
@@ -1180,7 +1186,7 @@ var MongoManagerCollection = /** @class */ (function () {
1180
1186
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1181
1187
  var validationResults, validDocs, i, doc, date, monitor_7;
1182
1188
  var _this = this;
1183
- return __generator(this, function (_a) {
1189
+ return __generator(this, function (_b) {
1184
1190
  if (!docs.length) {
1185
1191
  resolve([]);
1186
1192
  return [2 /*return*/];
@@ -1261,7 +1267,7 @@ var MongoManagerCollection = /** @class */ (function () {
1261
1267
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1262
1268
  var validation, isValid, date, monitor;
1263
1269
  var _this = this;
1264
- return __generator(this, function (_a) {
1270
+ return __generator(this, function (_b) {
1265
1271
  if (!doc._id) {
1266
1272
  doc._id = objectIdHexString();
1267
1273
  }
@@ -1347,8 +1353,8 @@ var MongoManagerCollection = /** @class */ (function () {
1347
1353
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1348
1354
  var validation, isValid, date, versionDoc, monitor_8, prevDoc, docId, docVersion, updatedDoc_1, monitor_9, monitor_10, monitor_11, monitor_12;
1349
1355
  var _this = this;
1350
- return __generator(this, function (_a) {
1351
- switch (_a.label) {
1356
+ return __generator(this, function (_b) {
1357
+ switch (_b.label) {
1352
1358
  case 0:
1353
1359
  if (this.checkSchema && !bypassCheckSchema) {
1354
1360
  validation = this.simplschema.newContext();
@@ -1368,8 +1374,8 @@ var MongoManagerCollection = /** @class */ (function () {
1368
1374
  if (!!doc) return [3 /*break*/, 2];
1369
1375
  return [4 /*yield*/, this.findOne(filter, null, true)];
1370
1376
  case 1:
1371
- doc = _a.sent();
1372
- _a.label = 2;
1377
+ doc = _b.sent();
1378
+ _b.label = 2;
1373
1379
  case 2:
1374
1380
  if (!doc) return [3 /*break*/, 6];
1375
1381
  if (this.timestamps && !replacement.createdAt && doc.createdAt) {
@@ -1422,7 +1428,7 @@ var MongoManagerCollection = /** @class */ (function () {
1422
1428
  }
1423
1429
  }, null, true)];
1424
1430
  case 4:
1425
- prevDoc = _a.sent();
1431
+ prevDoc = _b.sent();
1426
1432
  if (prevDoc) {
1427
1433
  docId = doc._id;
1428
1434
  docVersion = doc.__v;
@@ -1462,7 +1468,7 @@ var MongoManagerCollection = /** @class */ (function () {
1462
1468
  else {
1463
1469
  reject('Invalid Version And Could Not Find History - DB: ' + doc.__v + ', Trying to update with :' + replacement.__v);
1464
1470
  }
1465
- _a.label = 5;
1471
+ _b.label = 5;
1466
1472
  case 5: return [3 /*break*/, 7];
1467
1473
  case 6:
1468
1474
  if (options && options.upsert) {
@@ -1506,7 +1512,7 @@ var MongoManagerCollection = /** @class */ (function () {
1506
1512
  else {
1507
1513
  reject('No Document');
1508
1514
  }
1509
- _a.label = 7;
1515
+ _b.label = 7;
1510
1516
  case 7: return [3 /*break*/, 9];
1511
1517
  case 8:
1512
1518
  if (options && options.upsert) {
@@ -1582,7 +1588,7 @@ var MongoManagerCollection = /** @class */ (function () {
1582
1588
  reject(err);
1583
1589
  });
1584
1590
  }
1585
- _a.label = 9;
1591
+ _b.label = 9;
1586
1592
  case 9: return [2 /*return*/];
1587
1593
  }
1588
1594
  });
@@ -1596,8 +1602,8 @@ var MongoManagerCollection = /** @class */ (function () {
1596
1602
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1597
1603
  var date, validation, isValid, docs, i, doc, versionDoc, monitor;
1598
1604
  var _this = this;
1599
- return __generator(this, function (_a) {
1600
- switch (_a.label) {
1605
+ return __generator(this, function (_b) {
1606
+ switch (_b.label) {
1601
1607
  case 0:
1602
1608
  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
1609
  resolve(1);
@@ -1625,7 +1631,7 @@ var MongoManagerCollection = /** @class */ (function () {
1625
1631
  if (!((this.useVersions && !bypassVersions) || (this.createLogs && !bypassLogs))) return [3 /*break*/, 2];
1626
1632
  return [4 /*yield*/, this.find(filter)];
1627
1633
  case 1:
1628
- docs = _a.sent();
1634
+ docs = _b.sent();
1629
1635
  for (i = 0; i < docs.length; i++) {
1630
1636
  doc = docs[i];
1631
1637
  if (this.createLogs && !bypassLogs) {
@@ -1659,7 +1665,7 @@ var MongoManagerCollection = /** @class */ (function () {
1659
1665
  }
1660
1666
  }
1661
1667
  }
1662
- _a.label = 2;
1668
+ _b.label = 2;
1663
1669
  case 2:
1664
1670
  monitor = new monitor_manager_1.MonitorMongo('updateMany', this.collectionName, JSON.stringify([filter, update, options]));
1665
1671
  index_1.ResolveIOServer.getMainDB().collection(this.collectionName, this.collectionOptions).updateMany(filter, update, options).then(function (res) {
@@ -1688,8 +1694,8 @@ var MongoManagerCollection = /** @class */ (function () {
1688
1694
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1689
1695
  var validation, isValid, date, doc, versionDoc, monitor_13, monitor_14, monitor_15, monitor_16;
1690
1696
  var _this = this;
1691
- return __generator(this, function (_a) {
1692
- switch (_a.label) {
1697
+ return __generator(this, function (_b) {
1698
+ switch (_b.label) {
1693
1699
  case 0:
1694
1700
  if (this.checkSchema && !bypassCheckSchema) {
1695
1701
  validation = this.simplschema.newContext();
@@ -1717,7 +1723,7 @@ var MongoManagerCollection = /** @class */ (function () {
1717
1723
  if (!this.useVersions) return [3 /*break*/, 2];
1718
1724
  return [4 /*yield*/, this.findOne(filter, null, true)];
1719
1725
  case 1:
1720
- doc = _a.sent();
1726
+ doc = _b.sent();
1721
1727
  if (doc) {
1722
1728
  if (this.createLogs && !bypassLogs) {
1723
1729
  log_collection_1.Logs.insertOne({
@@ -1913,7 +1919,7 @@ var MongoManagerCollection = /** @class */ (function () {
1913
1919
  reject(err);
1914
1920
  });
1915
1921
  }
1916
- _a.label = 3;
1922
+ _b.label = 3;
1917
1923
  case 3: return [2 /*return*/];
1918
1924
  }
1919
1925
  });
@@ -1939,22 +1945,64 @@ var MongoManagerCollection = /** @class */ (function () {
1939
1945
  });
1940
1946
  return stream;
1941
1947
  };
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);
1948
+ var _a;
1949
+ _a = MongoManagerCollection;
1950
+ MongoManagerCollection.indexQueue = async_1.default.queue(function (task, callback) { return __awaiter(void 0, void 0, void 0, function () {
1951
+ var action, collection, specs, options, dbCollection, monitor, createIndex;
1952
+ return __generator(_a, function (_b) {
1953
+ switch (_b.label) {
1954
+ case 0:
1955
+ action = task.action, collection = task.collection, specs = task.specs, options = task.options;
1956
+ dbCollection = index_1.ResolveIOServer.getMainDB().collection(collection.collectionName, collection.collectionOptions);
1957
+ if (!dbCollection) {
1958
+ return [2 /*return*/, callback(new Error("Collection ".concat(collection.collectionName, " not found")))];
1959
+ }
1960
+ monitor = new monitor_manager_1.MonitorMongo(action, collection.collectionName, JSON.stringify([specs, options]));
1961
+ createIndex = function () { return __awaiter(void 0, void 0, void 0, function () {
1962
+ var result, err_1, existingIndexName, innerError_1;
1963
+ return __generator(this, function (_b) {
1964
+ switch (_b.label) {
1965
+ case 0:
1966
+ _b.trys.push([0, 2, , 9]);
1967
+ return [4 /*yield*/, dbCollection[action].apply(dbCollection, __spreadArray(__spreadArray([], specs, false), [options], false))];
1968
+ case 1:
1969
+ result = _b.sent();
1970
+ monitor.finish();
1971
+ callback(null, result);
1972
+ return [3 /*break*/, 9];
1973
+ case 2:
1974
+ err_1 = _b.sent();
1975
+ if (!(err_1.code === 85 || err_1.message.includes('IndexOptionsConflict'))) return [3 /*break*/, 8];
1976
+ _b.label = 3;
1977
+ case 3:
1978
+ _b.trys.push([3, 7, , 8]);
1979
+ existingIndexName = collection.extractIndexNameFromError(err_1.message);
1980
+ if (!existingIndexName) return [3 /*break*/, 6];
1981
+ return [4 /*yield*/, dbCollection.dropIndex(existingIndexName)];
1982
+ case 4:
1983
+ _b.sent();
1984
+ return [4 /*yield*/, createIndex()];
1985
+ case 5: return [2 /*return*/, _b.sent()];
1986
+ case 6: return [3 /*break*/, 8];
1987
+ case 7:
1988
+ innerError_1 = _b.sent();
1989
+ callback(innerError_1);
1990
+ return [3 /*break*/, 8];
1991
+ case 8:
1992
+ monitor.finish();
1993
+ callback(err_1);
1994
+ return [3 /*break*/, 9];
1995
+ case 9: return [2 /*return*/];
1996
+ }
1997
+ });
1998
+ }); };
1999
+ return [4 /*yield*/, createIndex()];
2000
+ case 1:
2001
+ _b.sent();
2002
+ return [2 /*return*/];
2003
+ }
1956
2004
  });
1957
- }, 1);
2005
+ }); }, 1);
1958
2006
  return MongoManagerCollection;
1959
2007
  }());
1960
2008
  exports.MongoManagerCollection = MongoManagerCollection;
@@ -1967,11 +2015,11 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
1967
2015
  var _this = this;
1968
2016
  return function (username, password, cb) { return __awaiter(_this, void 0, void 0, function () {
1969
2017
  var user;
1970
- return __generator(this, function (_a) {
1971
- switch (_a.label) {
2018
+ return __generator(this, function (_b) {
2019
+ switch (_b.label) {
1972
2020
  case 0: return [4 /*yield*/, user_collection_1.Users.findOne({ username: username })];
1973
2021
  case 1:
1974
- user = _a.sent();
2022
+ user = _b.sent();
1975
2023
  this.authenticate(user, password).then(function (authUser) {
1976
2024
  if (authUser.data) {
1977
2025
  cb(null, user, null);
@@ -1992,8 +2040,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
1992
2040
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1993
2041
  var attemptsInterval, calculatedInterval;
1994
2042
  var _this = this;
1995
- return __generator(this, function (_a) {
1996
- switch (_a.label) {
2043
+ return __generator(this, function (_b) {
2044
+ switch (_b.label) {
1997
2045
  case 0:
1998
2046
  attemptsInterval = Math.pow(100, Math.log(user.attempts + 1));
1999
2047
  calculatedInterval = attemptsInterval < 300000 ? attemptsInterval : 300000;
@@ -2002,7 +2050,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2002
2050
  user.last = new Date();
2003
2051
  return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last } })];
2004
2052
  case 1:
2005
- _a.sent();
2053
+ _b.sent();
2006
2054
  resolve({
2007
2055
  data: null,
2008
2056
  error: 'Attempt Too Soon'
@@ -2011,7 +2059,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2011
2059
  case 2: return [3 /*break*/, 4];
2012
2060
  case 3:
2013
2061
  user.last = new Date();
2014
- _a.label = 4;
2062
+ _b.label = 4;
2015
2063
  case 4:
2016
2064
  if (user.attempts >= 5) {
2017
2065
  resolve({
@@ -2032,8 +2080,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2032
2080
  keylen: 512,
2033
2081
  digestAlgorithm: 'sha256'
2034
2082
  }, function (err, hashBuffer) { return __awaiter(_this, void 0, void 0, function () {
2035
- return __generator(this, function (_a) {
2036
- switch (_a.label) {
2083
+ return __generator(this, function (_b) {
2084
+ switch (_b.label) {
2037
2085
  case 0:
2038
2086
  if (err) {
2039
2087
  return [2 /*return*/, reject(err)];
@@ -2043,7 +2091,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2043
2091
  user.attempts = 0;
2044
2092
  return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
2045
2093
  case 1:
2046
- _a.sent();
2094
+ _b.sent();
2047
2095
  resolve({
2048
2096
  data: user,
2049
2097
  error: ''
@@ -2054,7 +2102,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2054
2102
  user.attempts = user.attempts + 1;
2055
2103
  return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
2056
2104
  case 3:
2057
- _a.sent();
2105
+ _b.sent();
2058
2106
  if (user.attempts >= 5) {
2059
2107
  resolve({
2060
2108
  data: null,
@@ -2067,7 +2115,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2067
2115
  error: 'Invalid Username And Password'
2068
2116
  });
2069
2117
  }
2070
- _a.label = 4;
2118
+ _b.label = 4;
2071
2119
  case 4: return [2 /*return*/];
2072
2120
  }
2073
2121
  });
@@ -2095,8 +2143,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2095
2143
  var _this = this;
2096
2144
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
2097
2145
  var saltBuffer, salt, hashRaw, hash;
2098
- return __generator(this, function (_a) {
2099
- switch (_a.label) {
2146
+ return __generator(this, function (_b) {
2147
+ switch (_b.label) {
2100
2148
  case 0:
2101
2149
  if (!!user) return [3 /*break*/, 1];
2102
2150
  reject('No User');
@@ -2107,7 +2155,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2107
2155
  return [3 /*break*/, 5];
2108
2156
  case 2: return [4 /*yield*/, randomBytes(32)];
2109
2157
  case 3:
2110
- saltBuffer = _a.sent();
2158
+ saltBuffer = _b.sent();
2111
2159
  salt = saltBuffer.toString('hex');
2112
2160
  return [4 /*yield*/, pbkdf2Promisified(password, salt, {
2113
2161
  iterations: 25000,
@@ -2115,10 +2163,10 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2115
2163
  digestAlgorithm: 'sha256'
2116
2164
  })];
2117
2165
  case 4:
2118
- hashRaw = _a.sent();
2166
+ hashRaw = _b.sent();
2119
2167
  hash = Buffer.from(hashRaw, 'binary').toString('hex');
2120
2168
  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;
2169
+ _b.label = 5;
2122
2170
  case 5: return [2 /*return*/];
2123
2171
  }
2124
2172
  });
@@ -2129,8 +2177,8 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2129
2177
  var _this = this;
2130
2178
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
2131
2179
  var authUser;
2132
- return __generator(this, function (_a) {
2133
- switch (_a.label) {
2180
+ return __generator(this, function (_b) {
2181
+ switch (_b.label) {
2134
2182
  case 0:
2135
2183
  if (!!user) return [3 /*break*/, 1];
2136
2184
  reject('Missing User');
@@ -2141,14 +2189,14 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2141
2189
  return [3 /*break*/, 4];
2142
2190
  case 2: return [4 /*yield*/, this.authenticate(user, oldPassword)];
2143
2191
  case 3:
2144
- authUser = _a.sent();
2192
+ authUser = _b.sent();
2145
2193
  if (!authUser['data']) {
2146
2194
  reject(authUser['error']);
2147
2195
  }
2148
2196
  else {
2149
2197
  this.setPassword(user, newPassword).then(function (res) { return resolve(res); }, function (rej) { return reject(rej); });
2150
2198
  }
2151
- _a.label = 4;
2199
+ _b.label = 4;
2152
2200
  case 4: return [2 /*return*/];
2153
2201
  }
2154
2202
  });
@@ -2158,21 +2206,21 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2158
2206
  var _this = this;
2159
2207
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
2160
2208
  var dbUser;
2161
- return __generator(this, function (_a) {
2162
- switch (_a.label) {
2209
+ return __generator(this, function (_b) {
2210
+ switch (_b.label) {
2163
2211
  case 0:
2164
2212
  if (!!user.username) return [3 /*break*/, 1];
2165
2213
  reject('Missing Username');
2166
2214
  return [3 /*break*/, 5];
2167
2215
  case 1: return [4 /*yield*/, user_collection_1.Users.findOne({ username: user.username })];
2168
2216
  case 2:
2169
- dbUser = _a.sent();
2217
+ dbUser = _b.sent();
2170
2218
  if (!dbUser) return [3 /*break*/, 3];
2171
2219
  reject('Username Exists');
2172
2220
  return [3 /*break*/, 5];
2173
2221
  case 3: return [4 /*yield*/, user_collection_1.Users.findOne({ email: user.email })];
2174
2222
  case 4:
2175
- dbUser = _a.sent();
2223
+ dbUser = _b.sent();
2176
2224
  if (dbUser) {
2177
2225
  reject('Email Exists');
2178
2226
  }
@@ -2180,7 +2228,7 @@ var MongoManagerUserCollection = /** @class */ (function (_super) {
2180
2228
  user.setPassword(password);
2181
2229
  resolve(user);
2182
2230
  }
2183
- _a.label = 5;
2231
+ _b.label = 5;
2184
2232
  case 5: return [2 /*return*/];
2185
2233
  }
2186
2234
  });