Closed seanttaylor closed 6 years ago
We also need ensure the updateAttributes
method is refactored. The loopback-connector-firestore
package was calling set
on the document instead of update
which caused updates to existing documents to be toasted when the intent was to update a single field witihin a document.
updateAttributes(model, id, data, options, callback) {
const self = this;
this.exists(model, id, null, (err, res) => {
if (err) callback(err);
if (res) {
self.db.collection(model).doc(id).update(data).then(() => {
// Document updated successfully.
callback(null, []);
});
} else {
callback('Document not found');
}
});
}
We also need to modify the replaceById
method as follows.
replaceById(model, id, data, options, callback) {
const self = this;
/*For whatever reason this method does not do string conversion on the id with the result that Firestore cannot find the document even though the id reference is valid. This method also includes an id property with throws an error on the "before save" and "loaded" hooks. The id prorperty is deleted here. -- STT 03.25.2018 */
const __id = id.toString();
delete data.id;
this.exists(model, __id, null, (err, res) => {
if (err) callback(err);
if (res) {
self.db.collection(model).doc(__id).update(data).then(() => {
// Document updated successfully.
callback(null, []);
});
} else {
callback('Document not found');
}
});
}
Forking loopback-firestore
was unnecessary. Migrated data persistence to Google Firestore instead.
Some modifications to
loopback-connector-firestore
were required to in order to manually set the documentid
ofoffers
pushed to firestore. Specifically this refactor of theFirestore.create
method:We'll need to fork
loopback-connector-firestore
and publish separately in order to continue using Loopback's datasources interface with this module.