@francesco_ksh/app-ksh-mgd-schemas 2.5.6 → 2.5.8
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/index.js +2 -0
- package/models/Listing.js +35 -0
- package/models/PromoDailyStat.js +38 -0
- package/models/Promotion.js +5 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -37,6 +37,7 @@ const bonusSchema = require('./models/Bonus');
|
|
|
37
37
|
const payoutContactSchema = require('./models/PayoutContact');
|
|
38
38
|
const claimSchema = require('./models/Claim');
|
|
39
39
|
const promotionSchema = require('./models/Promotion');
|
|
40
|
+
const promoDailyStatSchema = require('./models/PromoDailyStat');
|
|
40
41
|
// Register Counter model so it's available when User.js and other models try to use it
|
|
41
42
|
const mongoose = require('mongoose');
|
|
42
43
|
if (!mongoose.models.Counter) {
|
|
@@ -83,4 +84,5 @@ module.exports = {
|
|
|
83
84
|
payoutContactSchema,
|
|
84
85
|
claimSchema,
|
|
85
86
|
promotionSchema,
|
|
87
|
+
promoDailyStatSchema,
|
|
86
88
|
};
|
package/models/Listing.js
CHANGED
|
@@ -480,6 +480,36 @@ const listingSchema = new Schema(
|
|
|
480
480
|
type: Number,
|
|
481
481
|
},
|
|
482
482
|
},
|
|
483
|
+
|
|
484
|
+
promotion: {
|
|
485
|
+
// True if listing is eligible for promoted serving today
|
|
486
|
+
isActive: { type: Boolean, default: false, index: true },
|
|
487
|
+
|
|
488
|
+
// Rome day key for which these values are valid
|
|
489
|
+
dayKey: { type: String, index: true }, // "YYYY-MM-DD"
|
|
490
|
+
|
|
491
|
+
// Sum of per-campaign scores for today (computed nightly)
|
|
492
|
+
scoreForThisDay: { type: Number, default: 0 },
|
|
493
|
+
|
|
494
|
+
// Campaign membership + per-campaign score (no counters here)
|
|
495
|
+
campaigns: {
|
|
496
|
+
type: [
|
|
497
|
+
{
|
|
498
|
+
campaignId: {
|
|
499
|
+
type: Schema.Types.ObjectId,
|
|
500
|
+
ref: 'Promotion',
|
|
501
|
+
required: true,
|
|
502
|
+
},
|
|
503
|
+
dayKey: { type: String, required: true }, // "YYYY-MM-DD"
|
|
504
|
+
scoreForThisDay: { type: Number, default: 0 },
|
|
505
|
+
isActive: { type: Boolean, default: true },
|
|
506
|
+
},
|
|
507
|
+
],
|
|
508
|
+
default: [],
|
|
509
|
+
},
|
|
510
|
+
|
|
511
|
+
lastCalculatedAt: { type: Date },
|
|
512
|
+
},
|
|
483
513
|
},
|
|
484
514
|
{
|
|
485
515
|
suppressReservedKeysWarning: true, // Added schema option here
|
|
@@ -536,5 +566,10 @@ listingSchema.index({ date: -1 });
|
|
|
536
566
|
listingSchema.index({ status: 1 });
|
|
537
567
|
listingSchema.index({ kashewId: 1 }, { unique: true, sparse: true });
|
|
538
568
|
listingSchema.index({ slug: 1 }, { unique: true, sparse: true });
|
|
569
|
+
listingSchema.index({
|
|
570
|
+
'promotion.isActive': 1,
|
|
571
|
+
'promotion.dayKey': 1,
|
|
572
|
+
'promotion.scoreForThisDay': -1,
|
|
573
|
+
});
|
|
539
574
|
|
|
540
575
|
module.exports = listingSchema;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// models/PromoDailyStat.js
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
const { Schema } = mongoose;
|
|
4
|
+
|
|
5
|
+
const promoDailyStatSchema = new Schema(
|
|
6
|
+
{
|
|
7
|
+
dayKey: { type: String, required: true, index: true }, // "YYYY-MM-DD"
|
|
8
|
+
listingId: {
|
|
9
|
+
type: Schema.Types.ObjectId,
|
|
10
|
+
ref: 'Listing',
|
|
11
|
+
required: true,
|
|
12
|
+
index: true,
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
// NULL means listing-total row (rotation stats)
|
|
16
|
+
// set means campaign-specific attribution row
|
|
17
|
+
campaignId: {
|
|
18
|
+
type: Schema.Types.ObjectId,
|
|
19
|
+
ref: 'Promotion',
|
|
20
|
+
default: null,
|
|
21
|
+
index: true,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
impressions: { type: Number, default: 0 },
|
|
25
|
+
clicks: { type: Number, default: 0 },
|
|
26
|
+
purchases: { type: Number, default: 0 },
|
|
27
|
+
lastServedAt: { type: Date },
|
|
28
|
+
},
|
|
29
|
+
{ timestamps: true }
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// One doc per day+listing+campaignId (campaignId can be null)
|
|
33
|
+
promoDailyStatSchema.index(
|
|
34
|
+
{ dayKey: 1, listingId: 1, campaignId: 1 },
|
|
35
|
+
{ unique: true }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
module.exports = promoDailyStatSchema;
|
package/models/Promotion.js
CHANGED
|
@@ -12,9 +12,7 @@ const promotionSchema = new Schema(
|
|
|
12
12
|
default: 10,
|
|
13
13
|
min: 1,
|
|
14
14
|
},
|
|
15
|
-
|
|
16
|
-
type: Number,
|
|
17
|
-
},
|
|
15
|
+
|
|
18
16
|
promotionType: {
|
|
19
17
|
type: String,
|
|
20
18
|
enum: ['allCategories', 'byCategory', 'byId'],
|
|
@@ -34,6 +32,9 @@ const promotionSchema = new Schema(
|
|
|
34
32
|
type: String,
|
|
35
33
|
default: null,
|
|
36
34
|
},
|
|
35
|
+
useAccountBalance: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
},
|
|
37
38
|
payments: [
|
|
38
39
|
{
|
|
39
40
|
paymentMethod: {
|
|
@@ -70,7 +71,7 @@ const promotionSchema = new Schema(
|
|
|
70
71
|
default: Date.now,
|
|
71
72
|
},
|
|
72
73
|
},
|
|
73
|
-
{
|
|
74
|
+
{ suppressReservedKeysWarning: true }
|
|
74
75
|
);
|
|
75
76
|
|
|
76
77
|
module.exports = promotionSchema;
|