feat: include recordedAt and numEvents in script/reconstruct...
This commit is contained in:
parent
2ffb9b7851
commit
460c114301
|
@ -52,8 +52,25 @@ async function main() {
|
|||
console.log('Rebuilding', track.title, 'with', track.trackData.points.length, 'data points.');
|
||||
|
||||
track.body = buildObsver1(track.trackData.points);
|
||||
await track.save();
|
||||
}
|
||||
|
||||
if (!track.recordedAt) {
|
||||
const firstPointWithDate = track.trackData.points.find((p) => p.date && p.time);
|
||||
if (firstPointWithDate) {
|
||||
const [day, month, year] = firstPointWithDate.date.split('.');
|
||||
const combinedString = `${year}-${month}-${day} ${firstPointWithDate.time}.000+2000`;
|
||||
const parsedDate = new Date(combinedString);
|
||||
if (!isNaN(parsedDate.getDate())) {
|
||||
track.recordedAt = parsedDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!track.numEvents) {
|
||||
track.numEvents = track.trackData.points.filter((p) => p.flag).length;
|
||||
}
|
||||
|
||||
await track.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ const schema = new mongoose.Schema(
|
|||
body: String,
|
||||
visible: Boolean,
|
||||
uploadedByUserAgent: String,
|
||||
recordedAt: Date,
|
||||
numEvents: { type: Number, default: 0 },
|
||||
comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }],
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
||||
|
@ -50,6 +51,7 @@ class Track extends mongoose.Model {
|
|||
}
|
||||
|
||||
toJSONFor(user, include) {
|
||||
const seePrivateFields = user && user._id.equals(this.author._id);
|
||||
return {
|
||||
slug: this.slug,
|
||||
title: this.title,
|
||||
|
@ -60,6 +62,13 @@ class Track extends mongoose.Model {
|
|||
visible: this.visible,
|
||||
author: this.author.toProfileJSONFor(user),
|
||||
...(include && include.body ? { body: this.body } : {}),
|
||||
...(seePrivateFields
|
||||
? {
|
||||
uploadedByUserAgent: this.uploadedByUserAgent,
|
||||
recordedAt: this.recordedAt,
|
||||
numEvents: this.numEvents,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue