@dhyasama/totem-models 12.21.0 → 12.22.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.
- package/lib/Brief.js +14 -2
- package/package.json +1 -1
package/lib/Brief.js
CHANGED
|
@@ -112,12 +112,24 @@ module.exports = function(mongoose, config) {
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
// Writes the finished html + references and flips status to 'ready'.
|
|
115
|
-
|
|
115
|
+
//
|
|
116
|
+
// `generatedOn` is optional. The caller (the ai-brief Lambda) should pass the
|
|
117
|
+
// date of the most recent source the brief cites, so the stamp reflects how
|
|
118
|
+
// current the underlying material is rather than when the html was rendered.
|
|
119
|
+
// When omitted (or not a valid date) it falls back to now, preserving the
|
|
120
|
+
// previous behavior for older callers.
|
|
121
|
+
Brief.statics.saveResult = async function(customerId, entity, html, references, generatedOn) {
|
|
116
122
|
validateCustomerId(customerId);
|
|
117
123
|
validateEntity(entity);
|
|
118
124
|
if (!html || typeof html !== 'string') throw new Error('html is required');
|
|
119
125
|
if (!Array.isArray(references)) throw new Error('references must be an array');
|
|
120
126
|
|
|
127
|
+
var stamp = new Date();
|
|
128
|
+
if (generatedOn != null) {
|
|
129
|
+
var parsed = (generatedOn instanceof Date) ? generatedOn : new Date(generatedOn);
|
|
130
|
+
if (!isNaN(parsed.getTime())) stamp = parsed;
|
|
131
|
+
}
|
|
132
|
+
|
|
121
133
|
return this.findOneAndUpdate(
|
|
122
134
|
entityFilter(customerId, entity),
|
|
123
135
|
{
|
|
@@ -125,7 +137,7 @@ module.exports = function(mongoose, config) {
|
|
|
125
137
|
status: 'ready',
|
|
126
138
|
html,
|
|
127
139
|
references,
|
|
128
|
-
generatedOn:
|
|
140
|
+
generatedOn: stamp
|
|
129
141
|
},
|
|
130
142
|
$setOnInsert: { customer: customerId, entity: { id: entity.id, model: entity.model } }
|
|
131
143
|
},
|