meteor3: REST API async migration COMPLETE — smoke green on Meteor 3.1 + Mongo 7
All 12 Flutter REST endpoints byte-identical to the 1.6.1.1 baseline, running on Meteor 3.1 against dockerized MongoDB 7. The 3.x jump works end-to-end. - Rest.js: every endpoint action -> async; all Mongo calls -> *Async (findOneAsync/countAsync/fetchAsync/upsertAsync/removeAsync). - Helpers to async: countRealFires (accepts array|cursor, forEachAsync->for-of), firesUnion (fetchAsync), fireFromHash/findOrCreateFire (await, dropped Fibers Promise.await), subscriptionsInsert/subscriptionsRemove, upsertFalsePositive, falsePositives.insert, subscriptions.update method, countFiresInRegions. - getFires: countAsync() on a $near cursor throws on the mongodb 6 driver ($near not allowed in the aggregation countDocuments uses) -> fetch once and use array length for total. - Route order: json-routes 3.0 matches in registration order, so mobile/subscriptions/all/:token/:mobileToken is now registered BEFORE :token/:mobileToken/:subsId (else GET .../all/x/y hit the delete-only route).
This commit is contained in:
parent
b37069c3e5
commit
637a749e8d
6 changed files with 124 additions and 117 deletions
|
|
@ -10,7 +10,7 @@ function geo(doc) {
|
|||
};
|
||||
}
|
||||
|
||||
export function subscriptionsInsert(doc, userId, type) {
|
||||
export async function subscriptionsInsert(doc, userId, type) {
|
||||
check(doc, {
|
||||
_id: Match.Maybe(Meteor.Collection.ObjectID),
|
||||
location: Match.ObjectIncluding({ lat: Number, lon: Number }),
|
||||
|
|
@ -23,23 +23,23 @@ export function subscriptionsInsert(doc, userId, type) {
|
|||
...doc
|
||||
};
|
||||
// console.log(newDoc);
|
||||
const already = Subscriptions.findOne(newDoc);
|
||||
const already = await Subscriptions.findOneAsync(newDoc);
|
||||
if (already) {
|
||||
throw new Meteor.Error('on-already-subscribed', 'The user is already subscribed to this area');
|
||||
}
|
||||
try {
|
||||
return Subscriptions.insert(newDoc);
|
||||
return await Subscriptions.insertAsync(newDoc);
|
||||
} catch (exception) {
|
||||
// console.error(exception);
|
||||
throw new Meteor.Error('500', exception);
|
||||
}
|
||||
}
|
||||
|
||||
export function subscriptionsRemove(subscriptionId) {
|
||||
export async function subscriptionsRemove(subscriptionId) {
|
||||
check(subscriptionId, Meteor.Collection.ObjectID);
|
||||
|
||||
try {
|
||||
return Subscriptions.remove(subscriptionId);
|
||||
return await Subscriptions.removeAsync(subscriptionId);
|
||||
} catch (exception) {
|
||||
console.error(exception);
|
||||
throw new Meteor.Error('500', exception);
|
||||
|
|
@ -54,7 +54,7 @@ Meteor.methods({
|
|||
});
|
||||
return subscriptionsInsert(doc, this.userId, 'web');
|
||||
},
|
||||
'subscriptions.update': function subscriptionsUpdate(doc) {
|
||||
'subscriptions.update': async function subscriptionsUpdate(doc) {
|
||||
check(doc, {
|
||||
_id: Meteor.Collection.ObjectID,
|
||||
location: Match.ObjectIncluding({ lat: Number, lon: Number }),
|
||||
|
|
@ -65,7 +65,7 @@ Meteor.methods({
|
|||
const dup = doc;
|
||||
const subscriptionId = doc._id;
|
||||
dup.geo = geo(doc);
|
||||
Subscriptions.update(subscriptionId, { $set: dup });
|
||||
await Subscriptions.updateAsync(subscriptionId, { $set: dup });
|
||||
return subscriptionId; // Return _id so we can redirect to subscription after update.
|
||||
} catch (exception) {
|
||||
throw new Meteor.Error('500', exception);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue