picker-db 4.2.4 → 4.3.0

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.
@@ -892,21 +892,25 @@ module.exports = (connection) => {
892
892
  },
893
893
  }, { timestamps: true });
894
894
 
895
- BookingSchema.pre("save", function (next) {
895
+ BookingSchema.pre("save", async function (next) {
896
896
  if (!this.isNew) {
897
897
  return next();
898
898
  }
899
899
  const doc = this;
900
- const query = { model: "Bookings" };
901
- const update = { $inc: { count: 1 } };
902
- const options = { new: true };
903
- IdentityCounterModel.findOneAndUpdate(query, update, options, function (error, counter) {
904
- if (error) {
900
+
901
+ if (!doc.bookingNumericId) {
902
+ try {
903
+ const query = { model: "Bookings" };
904
+ const update = { $inc: { count: 1 } };
905
+ const options = { new: true };
906
+ const result = await IdentityCounterModel.findOneAndUpdate(query, update, options);
907
+ doc.bookingNumericId = result.count;
908
+ return next();
909
+ } catch (error) {
905
910
  return next(error);
906
911
  }
907
- doc.bookingNumericId = counter.count;
908
- next();
909
- });
912
+ }
913
+ return next();
910
914
  });
911
915
 
912
916
  return BookingSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picker-db",
3
- "version": "4.2.4",
3
+ "version": "4.3.0",
4
4
  "description": "Picker DB services",
5
5
  "main": "index.js",
6
6
  "scripts": {