From c5bae2317066794ad2327b78b637f13eae9e4249 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:05:37 -0300
Subject: [PATCH 42/60] fix(step02): added async to main.js
---
src/simple-todos/step02/server/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/simple-todos/step02/server/main.js b/src/simple-todos/step02/server/main.js
index ed90033b..75959502 100644
--- a/src/simple-todos/step02/server/main.js
+++ b/src/simple-todos/step02/server/main.js
@@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { TasksCollection } from '/imports/api/TasksCollection';
const insertTask =
- async (taskText) => TasksCollection.insertAsync({ text: taskText });
+ async (taskText) => await TasksCollection.insertAsync({ text: taskText });
Meteor.startup(async () => {
if (await TasksCollection.find().countAsync() === 0) {
From e2ae6cbd6c3798f9b50f935fa03f42632283e81c Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:05:55 -0300
Subject: [PATCH 43/60] fix(step04): added async to app.jsx
---
src/simple-todos/step04/imports/ui/App.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/simple-todos/step04/imports/ui/App.jsx b/src/simple-todos/step04/imports/ui/App.jsx
index 4b3fa641..3098bea1 100644
--- a/src/simple-todos/step04/imports/ui/App.jsx
+++ b/src/simple-todos/step04/imports/ui/App.jsx
@@ -14,7 +14,7 @@ const toggleChecked =
};
const deleteTask =
- async ({ _id }) => TasksCollection.removeAsync(_id);
+ async ({ _id }) => await TasksCollection.removeAsync(_id);
export const App = () => {
const tasks = useTracker(async () =>
From 8f8235b7dd38a05be0c74fea7138ff8db65ba0d9 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:06:06 -0300
Subject: [PATCH 44/60] fix(step05): added async to app.jsx
---
src/simple-todos/step05/imports/ui/App.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/simple-todos/step05/imports/ui/App.jsx b/src/simple-todos/step05/imports/ui/App.jsx
index ea12d8b0..a7f6fb54 100644
--- a/src/simple-todos/step05/imports/ui/App.jsx
+++ b/src/simple-todos/step05/imports/ui/App.jsx
@@ -14,7 +14,7 @@ const toggleChecked =
};
const deleteTask =
- async ({ _id }) => TasksCollection.removeAsync(_id);
+ async ({ _id }) => await TasksCollection.removeAsync(_id);
export const App = () => {
const tasks = useTracker(async () =>
From 2ff49c0876d886c320bd23d1ab562473332b9492 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:06:15 -0300
Subject: [PATCH 45/60] fix(step06): added async to app.jsx
---
src/simple-todos/step06/imports/ui/App.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/simple-todos/step06/imports/ui/App.jsx b/src/simple-todos/step06/imports/ui/App.jsx
index 51e9b86c..f929df54 100644
--- a/src/simple-todos/step06/imports/ui/App.jsx
+++ b/src/simple-todos/step06/imports/ui/App.jsx
@@ -14,7 +14,7 @@ const toggleChecked =
};
const deleteTask =
- async ({ _id }) => TasksCollection.removeAsync(_id);
+ async ({ _id }) => await TasksCollection.removeAsync(_id);
export const App = () => {
const [hideCompleted, setHideCompleted] = useState(false);
From def3f0d9ab4268ed9cc3aa393130b514bf69095a Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:06:21 -0300
Subject: [PATCH 46/60] fix(step07): added async to app.jsx
---
src/simple-todos/step07/imports/ui/App.jsx | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/simple-todos/step07/imports/ui/App.jsx b/src/simple-todos/step07/imports/ui/App.jsx
index 69130256..85916279 100644
--- a/src/simple-todos/step07/imports/ui/App.jsx
+++ b/src/simple-todos/step07/imports/ui/App.jsx
@@ -16,7 +16,7 @@ const toggleChecked =
};
const deleteTask =
- async ({ _id }) => TasksCollection.removeAsync(_id);
+ async ({ _id }) => await TasksCollection.removeAsync(_id);
export const App = () => {
const user = useTracker(() => Meteor.user());
@@ -34,7 +34,7 @@ export const App = () => {
return [];
}
- return TasksCollection.find(
+ return await TasksCollection.find(
hideCompleted ? pendingOnlyFilter : userFilter,
{
sort: { createdAt: -1 },
@@ -47,7 +47,7 @@ export const App = () => {
return 0;
}
- return TasksCollection.find(pendingOnlyFilter).countAsync();
+ return await TasksCollection.find(pendingOnlyFilter).countAsync();
});
const pendingTasksTitle = `${
From c8340eac068ee2b84211992a3646f032dacc0139 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:06:27 -0300
Subject: [PATCH 47/60] fix(step08): added async to app.jsx
---
src/simple-todos/step08/imports/ui/App.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/simple-todos/step08/imports/ui/App.jsx b/src/simple-todos/step08/imports/ui/App.jsx
index c4278465..cf7c4261 100644
--- a/src/simple-todos/step08/imports/ui/App.jsx
+++ b/src/simple-todos/step08/imports/ui/App.jsx
@@ -16,7 +16,7 @@ const toggleChecked =
};
const deleteTask =
- async ({ _id }) => TasksCollection.removeAsync(_id);
+ async ({ _id }) => await TasksCollection.removeAsync(_id);
export const App = () => {
const user = useTracker(() => Meteor.user());
From b17e31d96e93f37cfaf5a336b93354b6ca0cdcda Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:06:53 -0300
Subject: [PATCH 48/60] fix(step03): converted to async in TaskForm.jsx
---
src/simple-todos/step03/imports/ui/TaskForm.jsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/simple-todos/step03/imports/ui/TaskForm.jsx b/src/simple-todos/step03/imports/ui/TaskForm.jsx
index cf4a4e30..414056a5 100644
--- a/src/simple-todos/step03/imports/ui/TaskForm.jsx
+++ b/src/simple-todos/step03/imports/ui/TaskForm.jsx
@@ -4,12 +4,12 @@ import { TasksCollection } from '/imports/api/TasksCollection';
export const TaskForm = () => {
const [text, setText] = useState('');
- const handleSubmit = e => {
+ const handleSubmit = async (e) => {
e.preventDefault();
if (!text) return;
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: text.trim(),
createdAt: new Date(),
});
From 3721394a6f1b55a59c57abb1aef3cea4802403e4 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:07:00 -0300
Subject: [PATCH 49/60] fix(step04): converted to async in TaskForm.jsx
---
src/simple-todos/step04/imports/ui/TaskForm.jsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/simple-todos/step04/imports/ui/TaskForm.jsx b/src/simple-todos/step04/imports/ui/TaskForm.jsx
index cf4a4e30..414056a5 100644
--- a/src/simple-todos/step04/imports/ui/TaskForm.jsx
+++ b/src/simple-todos/step04/imports/ui/TaskForm.jsx
@@ -4,12 +4,12 @@ import { TasksCollection } from '/imports/api/TasksCollection';
export const TaskForm = () => {
const [text, setText] = useState('');
- const handleSubmit = e => {
+ const handleSubmit = async (e) => {
e.preventDefault();
if (!text) return;
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: text.trim(),
createdAt: new Date(),
});
From a5b1e2272580af699290d6687fe3e360ebb92149 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:07:07 -0300
Subject: [PATCH 50/60] fix(step05): converted to async in TaskForm.jsx
---
src/simple-todos/step05/imports/ui/TaskForm.jsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/simple-todos/step05/imports/ui/TaskForm.jsx b/src/simple-todos/step05/imports/ui/TaskForm.jsx
index cf4a4e30..414056a5 100644
--- a/src/simple-todos/step05/imports/ui/TaskForm.jsx
+++ b/src/simple-todos/step05/imports/ui/TaskForm.jsx
@@ -4,12 +4,12 @@ import { TasksCollection } from '/imports/api/TasksCollection';
export const TaskForm = () => {
const [text, setText] = useState('');
- const handleSubmit = e => {
+ const handleSubmit = async (e) => {
e.preventDefault();
if (!text) return;
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: text.trim(),
createdAt: new Date(),
});
From aedb561bb878580a45384b55ae46765cdcf12f46 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:07:15 -0300
Subject: [PATCH 51/60] fix(step06): converted to async in TaskForm.jsx
---
src/simple-todos/step06/imports/ui/TaskForm.jsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/simple-todos/step06/imports/ui/TaskForm.jsx b/src/simple-todos/step06/imports/ui/TaskForm.jsx
index cf4a4e30..414056a5 100644
--- a/src/simple-todos/step06/imports/ui/TaskForm.jsx
+++ b/src/simple-todos/step06/imports/ui/TaskForm.jsx
@@ -4,12 +4,12 @@ import { TasksCollection } from '/imports/api/TasksCollection';
export const TaskForm = () => {
const [text, setText] = useState('');
- const handleSubmit = e => {
+ const handleSubmit = async (e) => {
e.preventDefault();
if (!text) return;
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: text.trim(),
createdAt: new Date(),
});
From 4261c9dbff0c4d308b99b52c74eaf4ad6766f82d Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:14:24 -0300
Subject: [PATCH 52/60] docs(step02): updated docs to mongo api
---
tutorial/simple-todos/02-collections.md | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tutorial/simple-todos/02-collections.md b/tutorial/simple-todos/02-collections.md
index 45b97d44..a06dc3dc 100644
--- a/tutorial/simple-todos/02-collections.md
+++ b/tutorial/simple-todos/02-collections.md
@@ -40,10 +40,11 @@ You don't need to keep the old content of `server/main.js`.
import { Meteor } from 'meteor/meteor';
import { TasksCollection } from '/imports/api/TasksCollection';
-const insertTask = taskText => TasksCollection.insert({ text: taskText });
+const insertTask =
+ async (taskText) => await TasksCollection.insertAsync({ text: taskText });
-Meteor.startup(() => {
- if (TasksCollection.find().count() === 0) {
+Meteor.startup(async () => {
+ if (await TasksCollection.find().countAsync() === 0) {
[
'First Task',
'Second Task',
@@ -85,7 +86,7 @@ import { TasksCollection } from '/imports/api/TasksCollection';
import { Task } from './Task';
export const App = () => {
- const tasks = useTracker(() => TasksCollection.find({}).fetch());
+ const tasks = useTracker(async () => await TasksCollection.find({}).fetchAsync());
return (
From b7199306519fef35c686f44124610f78c6fc32d5 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:45:56 -0300
Subject: [PATCH 53/60] fix(step07): missing params in main.js
---
src/simple-todos/step07/server/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/simple-todos/step07/server/main.js b/src/simple-todos/step07/server/main.js
index b6025985..a99b1d4e 100644
--- a/src/simple-todos/step07/server/main.js
+++ b/src/simple-todos/step07/server/main.js
@@ -30,6 +30,6 @@ Meteor.startup( async () => {
'Fifth Task',
'Sixth Task',
'Seventh Task',
- ].forEach(insertTask);
+ ].forEach(taskText => insertTask(taskText, user));
}
});
From d6277736f303201f99b20b41b3f3438845cf15ea Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:46:15 -0300
Subject: [PATCH 54/60] docs(step03): updated docs to async mongo api
---
tutorial/simple-todos/03-forms-and-events.md | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/tutorial/simple-todos/03-forms-and-events.md b/tutorial/simple-todos/03-forms-and-events.md
index 77caed4a..43388631 100644
--- a/tutorial/simple-todos/03-forms-and-events.md
+++ b/tutorial/simple-todos/03-forms-and-events.md
@@ -47,7 +47,7 @@ import { TasksCollection } from '/imports/api/TasksCollection';
import { TaskForm } from './TaskForm';
export const App = () => {
- const tasks = useTracker(() => TasksCollection.find({}).fetch());
+ const tasks = useTracker(async () => await TasksCollection.find({}).fetchAsync());
return (
@@ -90,17 +90,17 @@ import { TasksCollection } from '/imports/api/TasksCollection';
export const TaskForm = () => {
const [text, setText] = useState("");
- const handleSubmit = e => {
+ const handleSubmit = async (e) => {
e.preventDefault();
if (!text) return;
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: text.trim(),
- createdAt: new Date()
+ createdAt: new Date(),
});
- setText("");
+ setText('');
};
return (
@@ -129,7 +129,9 @@ Now you just need to make a change that will make users happy: we need to show t
..
export const App = () => {
- const tasks = useTracker(() => TasksCollection.find({}, { sort: { createdAt: -1 } }).fetch());
+ const tasks = useTracker(async () =>
+ await TasksCollection.find({}, { sort: { createdAt: -1 } }).fetchAsync()
+ );
..
```
From 8b2ad9e7cb4a20b7e1b2eb9a2cd137fd03dba44c Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:46:27 -0300
Subject: [PATCH 55/60] docs(step04): updated docs to async mongo api
---
tutorial/simple-todos/04-update-and-remove.md | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/tutorial/simple-todos/04-update-and-remove.md b/tutorial/simple-todos/04-update-and-remove.md
index 3bae2f07..ab45a48b 100644
--- a/tutorial/simple-todos/04-update-and-remove.md
+++ b/tutorial/simple-todos/04-update-and-remove.md
@@ -45,13 +45,14 @@ Create a function to change your document and pass it along to your `Task` compo
`imports/ui/App.jsx`
```js
-const toggleChecked = ({ _id, isChecked }) => {
- TasksCollection.update(_id, {
- $set: {
- isChecked: !isChecked
- }
- })
-};
+const toggleChecked =
+ async ({ _id, isChecked }) => {
+ await TasksCollection.updateAsync(_id, {
+ $set: {
+ isChecked: !isChecked,
+ },
+ });
+ };
export const App = () => {
..
@@ -89,7 +90,8 @@ Now add the removal logic in the `App`, you need to have a function to delete th
`imports/ui/App.jsx`
```js
-const deleteTask = ({ _id }) => TasksCollection.remove(_id);
+const deleteTask =
+ async ({ _id }) => await TasksCollection.removeAsync(_id);
export const App = () => {
..
From 5e07dee687ba32faa285f523cface8c6dd1bf90e Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:46:45 -0300
Subject: [PATCH 56/60] docs(step06): updated docs to async mongo api
---
tutorial/simple-todos/06-filter-tasks.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tutorial/simple-todos/06-filter-tasks.md b/tutorial/simple-todos/06-filter-tasks.md
index 3d9d5de8..46b5f81f 100644
--- a/tutorial/simple-todos/06-filter-tasks.md
+++ b/tutorial/simple-todos/06-filter-tasks.md
@@ -62,10 +62,10 @@ Now, if the user wants to see only pending tasks you can add a filter to your se
..
const hideCompletedFilter = { isChecked: { $ne: true } };
- const tasks = useTracker(() =>
- TasksCollection.find(hideCompleted ? hideCompletedFilter : {}, {
+ const tasks = useTracker(async () =>
+ await TasksCollection.find(hideCompleted ? hideCompletedFilter : {}, {
sort: { createdAt: -1 },
- }).fetch()
+ }).fetchAsync()
);
..
```
@@ -93,8 +93,8 @@ You should avoid adding zero to your app bar when there are no pending tasks.
`imports/ui/App.jsx`
```js
..
- const pendingTasksCount = useTracker(() =>
- TasksCollection.find(hideCompletedFilter).count()
+ const pendingTasksCount = useTracker(async () =>
+ await TasksCollection.find(hideCompletedFilter).countAsync()
);
const pendingTasksTitle = `${
From a59128e72bb288d8720eb054b87e29d701f455ae Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:46:59 -0300
Subject: [PATCH 57/60] docs(step07): updated docs to async mongo api
---
.../simple-todos/07-adding-user-accounts.md | 28 +++++++++----------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/tutorial/simple-todos/07-adding-user-accounts.md b/tutorial/simple-todos/07-adding-user-accounts.md
index 584cfc8c..d0be016e 100644
--- a/tutorial/simple-todos/07-adding-user-accounts.md
+++ b/tutorial/simple-todos/07-adding-user-accounts.md
@@ -263,8 +263,8 @@ import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { TasksCollection } from '/imports/api/TasksCollection';
-const insertTask = (taskText, user) =>
- TasksCollection.insert({
+const insertTask = async (taskText, user) =>
+ await TasksCollection.insertAsync({
text: taskText,
userId: user._id,
createdAt: new Date(),
@@ -273,7 +273,7 @@ const insertTask = (taskText, user) =>
const SEED_USERNAME = 'meteorite';
const SEED_PASSWORD = 'password';
-Meteor.startup(() => {
+Meteor.startup( async () => {
if (!Accounts.findUserByUsername(SEED_USERNAME)) {
Accounts.createUser({
username: SEED_USERNAME,
@@ -283,7 +283,7 @@ Meteor.startup(() => {
const user = Accounts.findUserByUsername(SEED_USERNAME);
- if (TasksCollection.find().count() === 0) {
+ if (await TasksCollection.find().countAsync() === 0) {
[
'First Task',
'Second Task',
@@ -313,25 +313,25 @@ Now you can filter the tasks in the UI by the authenticated user. Use the user `
const pendingOnlyFilter = { ...hideCompletedFilter, ...userFilter };
- const tasks = useTracker(() => {
+ const tasks = useTracker(async () => {
if (!user) {
return [];
}
-
- return TasksCollection.find(
+
+ return await TasksCollection.find(
hideCompleted ? pendingOnlyFilter : userFilter,
{
sort: { createdAt: -1 },
}
- ).fetch();
+ ).fetchAsync();
});
-
- const pendingTasksCount = useTracker(() => {
+
+ const pendingTasksCount = useTracker(async () => {
if (!user) {
return 0;
}
-
- return TasksCollection.find(pendingOnlyFilter).count();
+
+ return await TasksCollection.find(pendingOnlyFilter).countAsync();
});
..
@@ -347,12 +347,12 @@ Also, update the `insert` call to include the field `userId` in the `TaskForm`.
export const TaskForm = ({ user }) => {
const [text, setText] = useState('');
- const handleSubmit = e => {
+ const handleSubmit = async (e) => {
e.preventDefault();
if (!text) return;
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text: text.trim(),
createdAt: new Date(),
userId: user._id
From 6cd15f7944dad86331d06923b69332566495044c Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:47:16 -0300
Subject: [PATCH 58/60] docs(step09): updated docs to async mongo api
---
tutorial/simple-todos/09-methods.md | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/tutorial/simple-todos/09-methods.md b/tutorial/simple-todos/09-methods.md
index fd77d4b4..f9bae095 100644
--- a/tutorial/simple-todos/09-methods.md
+++ b/tutorial/simple-todos/09-methods.md
@@ -58,44 +58,44 @@ import { check } from 'meteor/check';
import { TasksCollection } from './TasksCollection';
Meteor.methods({
- 'tasks.insert'(text) {
+ async 'tasks.insert'(text) {
check(text, String);
if (!this.userId) {
throw new Meteor.Error('Not authorized.');
}
- TasksCollection.insert({
+ await TasksCollection.insertAsync({
text,
- createdAt: new Date,
+ createdAt: new Date(),
userId: this.userId,
- })
+ });
},
- 'tasks.remove'(taskId) {
+ async 'tasks.remove'(taskId) {
check(taskId, String);
if (!this.userId) {
throw new Meteor.Error('Not authorized.');
}
- TasksCollection.remove(taskId);
+ await TasksCollection.removeAsync(taskId);
},
- 'tasks.setIsChecked'(taskId, isChecked) {
+ async 'tasks.setIsChecked'(taskId, isChecked) {
check(taskId, String);
check(isChecked, Boolean);
-
+
if (!this.userId) {
throw new Meteor.Error('Not authorized.');
}
- TasksCollection.update(taskId, {
+ await TasksCollection.updateAsync(taskId, {
$set: {
- isChecked
- }
+ isChecked,
+ },
});
- }
+ },
});
```
@@ -128,7 +128,7 @@ import React, { useState } from 'react';
export const TaskForm = () => {
const [text, setText] = useState('');
- const handleSubmit = e => {
+ const handleSubmit = async (e) => {
e.preventDefault();
if (!text) return;
From 2f608a9c6918fb1dbba5d62a066f398b7c58a063 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:47:37 -0300
Subject: [PATCH 59/60] docs(step10): updated docs to async mongo api
---
tutorial/simple-todos/10-publications.md | 113 ++++++++++++-----------
1 file changed, 57 insertions(+), 56 deletions(-)
diff --git a/tutorial/simple-todos/10-publications.md b/tutorial/simple-todos/10-publications.md
index 5e0b75f3..9360d31c 100644
--- a/tutorial/simple-todos/10-publications.md
+++ b/tutorial/simple-todos/10-publications.md
@@ -60,27 +60,28 @@ It's also a good moment for us to refactor our code to use a single `useTracker`
```js
..
- const { tasks, pendingTasksCount, isLoading } = useTracker(() => {
- const noDataAvailable = { tasks: [], pendingTasksCount: 0 };
- if (!Meteor.user()) {
- return noDataAvailable;
- }
- const handler = Meteor.subscribe('tasks');
-
- if (!handler.ready()) {
- return { ...noDataAvailable, isLoading: true };
- }
-
- const tasks = TasksCollection.find(
- hideCompleted ? pendingOnlyFilter : userFilter,
- {
- sort: { createdAt: -1 },
+ const { tasks, pendingTasksCount, isLoading } = useTracker(async () => {
+ const noDataAvailable = { tasks: [], pendingTasksCount: 0 };
+ if (!Meteor.user()) {
+ return noDataAvailable;
}
- ).fetch();
- const pendingTasksCount = TasksCollection.find(pendingOnlyFilter).count();
-
- return { tasks, pendingTasksCount };
- });
+ const handler = Meteor.subscribe('tasks');
+
+ if (!handler.ready()) {
+ return { ...noDataAvailable, isLoading: true };
+ }
+
+ const tasks = await TasksCollection.find(
+ hideCompleted ? pendingOnlyFilter : userFilter,
+ {
+ sort: { createdAt: -1 },
+ }
+ ).fetchAsync();
+ const pendingTasksCount = await TasksCollection.find(pendingOnlyFilter)
+ .countAsync();
+
+ return { tasks, pendingTasksCount };
+ });
..
```
@@ -133,42 +134,42 @@ Only the owner of a task should be able to change certain things. You should cha
```js
..
- 'tasks.remove'(taskId) {
- check(taskId, String);
-
- if (!this.userId) {
- throw new Meteor.Error('Not authorized.');
- }
-
- const task = TasksCollection.findOne({ _id: taskId, userId: this.userId });
-
- if (!task) {
- throw new Meteor.Error('Access denied.');
- }
-
- TasksCollection.remove(taskId);
- },
-
- 'tasks.setIsChecked'(taskId, isChecked) {
- check(taskId, String);
- check(isChecked, Boolean);
-
- if (!this.userId) {
- throw new Meteor.Error('Not authorized.');
- }
-
- const task = TasksCollection.findOne({ _id: taskId, userId: this.userId });
-
- if (!task) {
- throw new Meteor.Error('Access denied.');
- }
-
- TasksCollection.update(taskId, {
- $set: {
- isChecked,
- },
- });
- },
+ async 'tasks.remove'(taskId) {
+ check(taskId, String);
+
+ if (!this.userId) {
+ throw new Meteor.Error('Not authorized.');
+ }
+
+ const task = await TasksCollection.findOneAsync({ _id: taskId, userId: this.userId });
+
+ if (!task) {
+ throw new Meteor.Error('Access denied.');
+ }
+
+ await TasksCollection.removeAsync(taskId);
+ },
+
+ async 'tasks.setIsChecked'(taskId, isChecked) {
+ check(taskId, String);
+ check(isChecked, Boolean);
+
+ if (!this.userId) {
+ throw new Meteor.Error('Not authorized.');
+ }
+
+ const task = await TasksCollection.findOneAsync({ _id: taskId, userId: this.userId });
+
+ if (!task) {
+ throw new Meteor.Error('Access denied.');
+ }
+
+ await TasksCollection.updateAsync(taskId, {
+ $set: {
+ isChecked,
+ },
+ });
+ },
..
```
From 2bb7f9f11724bb627f0bdc8d4134731f438e5b74 Mon Sep 17 00:00:00 2001
From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com>
Date: Thu, 1 Sep 2022 17:47:48 -0300
Subject: [PATCH 60/60] docs(step12): updated docs to async mongo api
---
tutorial/simple-todos/12-testing.md | 44 ++++++++++++++---------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/tutorial/simple-todos/12-testing.md b/tutorial/simple-todos/12-testing.md
index c9d606f9..f2ac3bc1 100644
--- a/tutorial/simple-todos/12-testing.md
+++ b/tutorial/simple-todos/12-testing.md
@@ -82,9 +82,9 @@ if (Meteor.isServer) {
const userId = Random.id();
let taskId;
- beforeEach(() => {
- TasksCollection.remove({});
- taskId = TasksCollection.insert({
+ beforeEach(async () => {
+ await TasksCollection.removeAsync({});
+ taskId = await TasksCollection.insertAsync({
text: 'Test Task',
createdAt: new Date(),
userId,
@@ -121,19 +121,19 @@ if (Meteor.isServer) {
const userId = Random.id();
let taskId;
- beforeEach(() => {
- TasksCollection.remove({});
- taskId = TasksCollection.insert({
+ beforeEach(async () => {
+ await TasksCollection.removeAsync({});
+ taskId = await TasksCollection.insertAsync({
text: 'Test Task',
createdAt: new Date(),
userId,
});
});
- it('can delete owned task', () => {
+ it('can delete owned task', async () => {
mockMethodCall('tasks.remove', taskId, { context: { userId } });
- assert.equal(TasksCollection.find().count(), 0);
+ assert.equal(await TasksCollection.find().countAsync(), 0);
});
});
});
@@ -162,53 +162,53 @@ if (Meteor.isServer) {
const userId = Random.id();
let taskId;
- beforeEach(() => {
- TasksCollection.remove({});
- taskId = TasksCollection.insert({
+ beforeEach(async () => {
+ await TasksCollection.removeAsync({});
+ taskId = await TasksCollection.insertAsync({
text: 'Test Task',
createdAt: new Date(),
userId,
});
});
- it('can delete owned task', () => {
+ it('can delete owned task', async () => {
mockMethodCall('tasks.remove', taskId, { context: { userId } });
- assert.equal(TasksCollection.find().count(), 0);
+ assert.equal(await TasksCollection.find().countAsync(), 0);
});
- it(`can't delete task without an user authenticated`, () => {
+ it('can\'t delete task without an user authenticated', async () => {
const fn = () => mockMethodCall('tasks.remove', taskId);
assert.throw(fn, /Not authorized/);
- assert.equal(TasksCollection.find().count(), 1);
+ assert.equal(await TasksCollection.find().countAsync(), 1);
});
- it(`can't delete task from another owner`, () => {
+ it('can\'t delete task from another owner', async () => {
const fn = () =>
mockMethodCall('tasks.remove', taskId, {
context: { userId: 'somebody-else-id' },
});
assert.throw(fn, /Access denied/);
- assert.equal(TasksCollection.find().count(), 1);
+ assert.equal(await TasksCollection.find().countAsync(), 1);
});
- it('can change the status of a task', () => {
- const originalTask = TasksCollection.findOne(taskId);
+ it('can change the status of a task', async () => {
+ const originalTask = await TasksCollection.findOneAsync(taskId);
mockMethodCall('tasks.setIsChecked', taskId, !originalTask.isChecked, {
context: { userId },
});
- const updatedTask = TasksCollection.findOne(taskId);
+ const updatedTask = await TasksCollection.findOneAsync(taskId);
assert.notEqual(updatedTask.isChecked, originalTask.isChecked);
});
- it('can insert new tasks', () => {
+ it('can insert new tasks', async () => {
const text = 'New Task';
mockMethodCall('tasks.insert', text, {
context: { userId },
});
- const tasks = TasksCollection.find({}).fetch();
+ const tasks = await TasksCollection.find({}).fetchAsync();
assert.equal(tasks.length, 2);
assert.isTrue(tasks.some(task => task.text === text));
});