@francesco_ksh/app-ksh-mgd-schemas 1.6.4 → 1.6.6
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.
- package/models/Listing.js +1 -0
- package/models/Order.js +3 -2
- package/package.json +1 -1
package/models/Listing.js
CHANGED
|
@@ -417,6 +417,7 @@ const listingSchema = new Schema(
|
|
|
417
417
|
listingSchema.index({ '$**': 'text' });
|
|
418
418
|
listingSchema.index({ author: 1 });
|
|
419
419
|
listingSchema.index({ region: 1 });
|
|
420
|
+
listingSchema.index({ date: -1 });
|
|
420
421
|
listingSchema.index({ status: 1 });
|
|
421
422
|
listingSchema.index({ kashewId: 1 }, { unique: true, sparse: true });
|
|
422
423
|
|
package/models/Order.js
CHANGED
|
@@ -524,10 +524,11 @@ orderSchema.pre('save', async function (next) {
|
|
|
524
524
|
const lastOrder = await mongoose
|
|
525
525
|
.model('Order')
|
|
526
526
|
.findOne({})
|
|
527
|
-
.sort({
|
|
527
|
+
.sort({ date: -1 })
|
|
528
|
+
.select('kashewId')
|
|
528
529
|
.exec();
|
|
529
530
|
|
|
530
|
-
let newId =
|
|
531
|
+
let newId = 10000; // Start from 10000 if no orders exist
|
|
531
532
|
if (lastOrder && lastOrder.kashewId) {
|
|
532
533
|
const lastIdNumber = parseInt(lastOrder.kashewId.slice(3), 10); // Remove "KSH" and parse the digits
|
|
533
534
|
newId = lastIdNumber + 1;
|