Skip to content

Commit 0fee0ac

Browse files
committed
update to the new moleculer-db
1 parent 3f25266 commit 0fee0ac

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

blog/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
"dependencies": {
1414
"bluebird": "3.5.0",
1515
"chalk": "2.0.1",
16-
"eslint": "4.1.1",
16+
"eslint": "4.3.0",
1717
"express": "4.15.3",
1818
"fakerator": "0.3.0",
1919
"hashids": "1.1.1",
2020
"ioredis": "3.1.1",
2121
"lodash": "4.17.4",
2222
"moleculer": "0.8.2",
23-
"moleculer-db": "0.3.3",
24-
"moleculer-db-adapter-mongoose": "0.2.0",
25-
"moleculer-fake": "1.0.3",
23+
"moleculer-db": "0.4.1",
24+
"moleculer-db-adapter-mongoose": "0.3.1",
25+
"moleculer-fake": "1.0.4",
2626
"moleculer-repl": "0.1.3",
2727
"moleculer-web": "0.4.0",
2828
"moment": "2.18.1",
@@ -33,6 +33,6 @@
3333
},
3434
"devDependencies": {
3535
"nodemon": "1.11.0",
36-
"npm-check": "5.4.4"
36+
"npm-check": "5.4.5"
3737
}
3838
}

blog/services/posts.service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ module.exports = {
1414
model: Post,
1515

1616
settings: {
17-
fields: "_id title content author likes category coverPhoto createdAt",
17+
fields: ["_id", "title", "content", "author", "likes", "category", "coverPhoto", "createdAt"],
1818
populates: {
1919
"author": {
20-
action: "users.model",
20+
action: "users.get",
2121
params: {
22-
fields: "_id username fullName email avatar"
22+
fields: ["_id", "username", "fullName", "avatar"]
2323
}
2424
}
2525
},

blog/services/users.service.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ module.exports = {
3434
adapter: new MongooseAdapter(process.env.MONGO_URI || "mongodb://localhost/moleculer-blog"),
3535
model: User,
3636

37+
settings: {
38+
fields: ["_id", "username", "fullName", "email", "avatar", "author"]
39+
},
40+
3741
actions: {
3842
authors: {
3943
cache: true,

blog/services/www.service.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141

4242
return Promise.resolve({ page })
4343
.then(data => {
44-
return this.broker.call("posts.list", { page, pageSize }).then(res => {
44+
return this.broker.call("posts.list", { page, pageSize, populate: ["author"] }).then(res => {
4545
data.posts = res.rows;
4646
data.totalPages = res.totalPages;
4747
return data;
@@ -60,7 +60,7 @@ module.exports = {
6060

6161
return Promise.resolve({ page })
6262
.then(data => {
63-
return this.broker.call("posts.list", { query: { category }, page, pageSize }).then(res => {
63+
return this.broker.call("posts.list", { query: { category }, page, pageSize, populate: ["author"] }).then(res => {
6464
data.posts = res.rows;
6565
data.totalPages = res.totalPages;
6666
return data;
@@ -81,7 +81,7 @@ module.exports = {
8181

8282
return Promise.resolve({ page })
8383
.then(data => {
84-
return this.broker.call("posts.list", { query: { author }, page, pageSize }).then(res => {
84+
return this.broker.call("posts.list", { query: { author }, page, pageSize, populate: ["author"] }).then(res => {
8585
data.posts = res.rows;
8686
data.totalPages = res.totalPages;
8787
return data;
@@ -102,7 +102,7 @@ module.exports = {
102102

103103
return Promise.resolve({ page })
104104
.then(data => {
105-
return this.broker.call("posts.list", { search, page, pageSize }).then(res => {
105+
return this.broker.call("posts.list", { search, page, pageSize, populate: ["author"] }).then(res => {
106106
data.query = search;
107107
data.posts = res.rows;
108108
data.totalPages = res.totalPages;
@@ -121,7 +121,7 @@ module.exports = {
121121
return this.handleErr(res)(this.Promise.reject(new MoleculerError("Invalid POST ID", 404, "INVALID_POST_ID", { id: req.params.id })));
122122

123123
return Promise.resolve({ })
124-
.then(data => this.broker.call("posts.get", { id }).then(post => {
124+
.then(data => this.broker.call("posts.get", { id, populate: ["author"] }).then(post => {
125125
if (!post)
126126
return this.Promise.reject(new MoleculerError("Post not found", 404, "NOT_FOUND_POST", { id: req.params.id }));
127127

@@ -136,7 +136,7 @@ module.exports = {
136136
},
137137

138138
appendAdditionalData(data) {
139-
return this.broker.call("posts.find", { limit: 5, sort: "-likes", populate: false }).then(posts => {
139+
return this.broker.call("posts.find", { limit: 5, sort: "-likes" }).then(posts => {
140140
data.bestOfPosts = posts;
141141
return data;
142142
});

0 commit comments

Comments
 (0)