crazy-odds-bet-shared 1.0.32 → 1.0.34
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/player.js +72 -25
- package/models/team.js +76 -29
- package/package.json +1 -1
package/models/player.js
CHANGED
|
@@ -58,10 +58,10 @@ playerSchema.static('getActive', function () {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
playerSchema.static('findByExternalRefId', function (bookmakerSlug, sportId, externalId) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
return this.findOne({
|
|
62
|
+
sportId,
|
|
63
|
+
[`externalRefs.${bookmakerSlug}`]: { $elemMatch: { id: externalId } }
|
|
64
|
+
});
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
playerSchema.static('findBySport', function (sportId) {
|
|
@@ -96,7 +96,19 @@ playerSchema.method('deactivate', async function () {
|
|
|
96
96
|
return this.save();
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
+
// Normalize externalRefs[bookmakerSlug] to array (handles legacy single object)
|
|
100
|
+
function getRefsArray(externalRefs, bookmakerSlug) {
|
|
101
|
+
if (!externalRefs || typeof externalRefs !== 'object') return [];
|
|
102
|
+
const val = externalRefs[bookmakerSlug];
|
|
103
|
+
if (val == null) return [];
|
|
104
|
+
return Array.isArray(val) ? val : [val];
|
|
105
|
+
}
|
|
106
|
+
|
|
99
107
|
playerSchema.method('addExternalRef', async function (bookmakerSlug, externalId, data) {
|
|
108
|
+
if (!this.externalRefs || typeof this.externalRefs !== 'object') {
|
|
109
|
+
this.externalRefs = {};
|
|
110
|
+
}
|
|
111
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
100
112
|
const ref = {
|
|
101
113
|
id: externalId,
|
|
102
114
|
name: data.name || '',
|
|
@@ -104,40 +116,75 @@ playerSchema.method('addExternalRef', async function (bookmakerSlug, externalId,
|
|
|
104
116
|
isActive: data.isActive !== undefined ? data.isActive : true,
|
|
105
117
|
metadata: data.metadata || {}
|
|
106
118
|
};
|
|
107
|
-
|
|
119
|
+
const idStr = String(externalId);
|
|
120
|
+
const idx = refs.findIndex((r) => String(r.id) === idStr);
|
|
121
|
+
if (idx >= 0) {
|
|
122
|
+
refs[idx] = ref;
|
|
123
|
+
} else {
|
|
124
|
+
refs.push(ref);
|
|
125
|
+
}
|
|
126
|
+
this.externalRefs[bookmakerSlug] = refs;
|
|
108
127
|
this.markModified('externalRefs');
|
|
109
128
|
return this.save();
|
|
110
129
|
});
|
|
111
130
|
|
|
112
131
|
playerSchema.method('getExternalRef', function (bookmakerSlug) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
132
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
133
|
+
return refs.length > 0 ? refs[0] : null;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
playerSchema.method('getExternalRefByExternalId', function (bookmakerSlug, externalId) {
|
|
137
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
138
|
+
const idStr = String(externalId);
|
|
139
|
+
return refs.find((r) => String(r.id) === idStr) || null;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
playerSchema.method('removeExternalRef', async function (bookmakerSlug, externalId) {
|
|
143
|
+
if (!this.externalRefs?.[bookmakerSlug]) return this;
|
|
144
|
+
if (externalId != null) {
|
|
145
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
146
|
+
const idStr = String(externalId);
|
|
147
|
+
const filtered = refs.filter((r) => String(r.id) !== idStr);
|
|
148
|
+
if (filtered.length === 0) {
|
|
149
|
+
delete this.externalRefs[bookmakerSlug];
|
|
150
|
+
} else {
|
|
151
|
+
this.externalRefs[bookmakerSlug] = filtered;
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
118
154
|
delete this.externalRefs[bookmakerSlug];
|
|
119
|
-
this.markModified('externalRefs');
|
|
120
|
-
return this.save();
|
|
121
155
|
}
|
|
122
|
-
|
|
156
|
+
this.markModified('externalRefs');
|
|
157
|
+
return this.save();
|
|
123
158
|
});
|
|
124
159
|
|
|
125
|
-
playerSchema.method('activateExternalRef', async function (bookmakerSlug) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
160
|
+
playerSchema.method('activateExternalRef', async function (bookmakerSlug, externalId) {
|
|
161
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
162
|
+
if (refs.length === 0) return this;
|
|
163
|
+
if (externalId != null) {
|
|
164
|
+
const idStr = String(externalId);
|
|
165
|
+
const r = refs.find((ref) => String(ref.id) === idStr);
|
|
166
|
+
if (r) r.isActive = true;
|
|
167
|
+
} else {
|
|
168
|
+
refs.forEach((r) => { r.isActive = true; });
|
|
130
169
|
}
|
|
131
|
-
|
|
170
|
+
this.externalRefs[bookmakerSlug] = refs;
|
|
171
|
+
this.markModified('externalRefs');
|
|
172
|
+
return this.save();
|
|
132
173
|
});
|
|
133
174
|
|
|
134
|
-
playerSchema.method('deactivateExternalRef', async function (bookmakerSlug) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
175
|
+
playerSchema.method('deactivateExternalRef', async function (bookmakerSlug, externalId) {
|
|
176
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
177
|
+
if (refs.length === 0) return this;
|
|
178
|
+
if (externalId != null) {
|
|
179
|
+
const idStr = String(externalId);
|
|
180
|
+
const r = refs.find((ref) => String(ref.id) === idStr);
|
|
181
|
+
if (r) r.isActive = false;
|
|
182
|
+
} else {
|
|
183
|
+
refs.forEach((r) => { r.isActive = false; });
|
|
139
184
|
}
|
|
140
|
-
|
|
185
|
+
this.externalRefs[bookmakerSlug] = refs;
|
|
186
|
+
this.markModified('externalRefs');
|
|
187
|
+
return this.save();
|
|
141
188
|
});
|
|
142
189
|
|
|
143
190
|
playerSchema.method('addProviderRef', async function (providerSlug, externalId) {
|
package/models/team.js
CHANGED
|
@@ -53,17 +53,17 @@ teamSchema.static('getActive', function () {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
teamSchema.static('findByExternalRef', function (bookmakerSlug, sportId, externalId) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
return this.findOne({
|
|
57
|
+
sportId,
|
|
58
|
+
[`externalRefs.${bookmakerSlug}`]: { $elemMatch: { id: externalId } }
|
|
59
|
+
});
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
teamSchema.static('findByExternalRefName', function (bookmakerSlug, sportId, externalName) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
return this.findOne({
|
|
64
|
+
sportId,
|
|
65
|
+
[`externalRefs.${bookmakerSlug}`]: { $elemMatch: { name: externalName } }
|
|
66
|
+
});
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
teamSchema.static('findBySport', function (sportId) {
|
|
@@ -94,7 +94,19 @@ teamSchema.method('deactivate', async function () {
|
|
|
94
94
|
return this.save();
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
// Normalize externalRefs[bookmakerSlug] to array (handles legacy single object)
|
|
98
|
+
function getRefsArray(externalRefs, bookmakerSlug) {
|
|
99
|
+
if (!externalRefs || typeof externalRefs !== 'object') return [];
|
|
100
|
+
const val = externalRefs[bookmakerSlug];
|
|
101
|
+
if (val == null) return [];
|
|
102
|
+
return Array.isArray(val) ? val : [val];
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
teamSchema.method('addExternalRef', async function (bookmakerSlug, externalId, data) {
|
|
106
|
+
if (!this.externalRefs || typeof this.externalRefs !== 'object') {
|
|
107
|
+
this.externalRefs = {};
|
|
108
|
+
}
|
|
109
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
98
110
|
const ref = {
|
|
99
111
|
id: externalId,
|
|
100
112
|
name: data.name,
|
|
@@ -102,40 +114,75 @@ teamSchema.method('addExternalRef', async function (bookmakerSlug, externalId, d
|
|
|
102
114
|
isActive: data.isActive !== undefined ? data.isActive : true,
|
|
103
115
|
metadata: data.metadata || {}
|
|
104
116
|
};
|
|
105
|
-
|
|
117
|
+
const idStr = String(externalId);
|
|
118
|
+
const idx = refs.findIndex((r) => String(r.id) === idStr);
|
|
119
|
+
if (idx >= 0) {
|
|
120
|
+
refs[idx] = ref;
|
|
121
|
+
} else {
|
|
122
|
+
refs.push(ref);
|
|
123
|
+
}
|
|
124
|
+
this.externalRefs[bookmakerSlug] = refs;
|
|
106
125
|
this.markModified('externalRefs');
|
|
107
126
|
return this.save();
|
|
108
127
|
});
|
|
109
128
|
|
|
110
129
|
teamSchema.method('getExternalRef', function (bookmakerSlug) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
130
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
131
|
+
return refs.length > 0 ? refs[0] : null;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
teamSchema.method('getExternalRefByExternalId', function (bookmakerSlug, externalId) {
|
|
135
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
136
|
+
const idStr = String(externalId);
|
|
137
|
+
return refs.find((r) => String(r.id) === idStr) || null;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
teamSchema.method('removeExternalRef', async function (bookmakerSlug, externalId) {
|
|
141
|
+
if (!this.externalRefs?.[bookmakerSlug]) return this;
|
|
142
|
+
if (externalId != null) {
|
|
143
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
144
|
+
const idStr = String(externalId);
|
|
145
|
+
const filtered = refs.filter((r) => String(r.id) !== idStr);
|
|
146
|
+
if (filtered.length === 0) {
|
|
147
|
+
delete this.externalRefs[bookmakerSlug];
|
|
148
|
+
} else {
|
|
149
|
+
this.externalRefs[bookmakerSlug] = filtered;
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
116
152
|
delete this.externalRefs[bookmakerSlug];
|
|
117
|
-
this.markModified('externalRefs');
|
|
118
|
-
return this.save();
|
|
119
153
|
}
|
|
120
|
-
|
|
154
|
+
this.markModified('externalRefs');
|
|
155
|
+
return this.save();
|
|
121
156
|
});
|
|
122
157
|
|
|
123
|
-
teamSchema.method('activateExternalRef', async function (bookmakerSlug) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
158
|
+
teamSchema.method('activateExternalRef', async function (bookmakerSlug, externalId) {
|
|
159
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
160
|
+
if (refs.length === 0) return this;
|
|
161
|
+
if (externalId != null) {
|
|
162
|
+
const idStr = String(externalId);
|
|
163
|
+
const r = refs.find((ref) => String(ref.id) === idStr);
|
|
164
|
+
if (r) r.isActive = true;
|
|
165
|
+
} else {
|
|
166
|
+
refs.forEach((r) => { r.isActive = true; });
|
|
128
167
|
}
|
|
129
|
-
|
|
168
|
+
this.externalRefs[bookmakerSlug] = refs;
|
|
169
|
+
this.markModified('externalRefs');
|
|
170
|
+
return this.save();
|
|
130
171
|
});
|
|
131
172
|
|
|
132
|
-
teamSchema.method('deactivateExternalRef', async function (bookmakerSlug) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
173
|
+
teamSchema.method('deactivateExternalRef', async function (bookmakerSlug, externalId) {
|
|
174
|
+
const refs = getRefsArray(this.externalRefs, bookmakerSlug);
|
|
175
|
+
if (refs.length === 0) return this;
|
|
176
|
+
if (externalId != null) {
|
|
177
|
+
const idStr = String(externalId);
|
|
178
|
+
const r = refs.find((ref) => String(ref.id) === idStr);
|
|
179
|
+
if (r) r.isActive = false;
|
|
180
|
+
} else {
|
|
181
|
+
refs.forEach((r) => { r.isActive = false; });
|
|
137
182
|
}
|
|
138
|
-
|
|
183
|
+
this.externalRefs[bookmakerSlug] = refs;
|
|
184
|
+
this.markModified('externalRefs');
|
|
185
|
+
return this.save();
|
|
139
186
|
});
|
|
140
187
|
|
|
141
188
|
teamSchema.method('addProviderRef', async function (providerSlug, externalId) {
|