From ce15a7b988da55a56398b7d73b470f1aa5cef910 Mon Sep 17 00:00:00 2001 From: erikka-22 Date: Sat, 22 Apr 2023 07:22:32 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fork=E5=85=83=E3=81=A8=E7=8A=B6=E6=85=8B?= =?UTF-8?q?=E3=82=92=E6=8F=83=E3=81=88=E3=82=8B=E3=81=9F=E3=82=81commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/breweriesController.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/controllers/breweriesController.js b/api/controllers/breweriesController.js index 7476147..1db1815 100644 --- a/api/controllers/breweriesController.js +++ b/api/controllers/breweriesController.js @@ -170,11 +170,11 @@ module.exports.create = [ twitter: req.body.twitter, instagram: req.body.instagram, othersns: req.body.othersns, - visit: req.body.hasVisit ? req.body.visit : null, - tasting: req.body.hasTasting ? req.body.tasting : null, - cafe: req.body.hasCafe ? req.body.cafe : null, - shop: req.body.hasShop ? req.body.shop : null, - otherBrewing: req.body.hasOtherBrewing ? req.body.otherBrewing : null, + visit: request.body.hasVisit ? req.body.visit : null, + tasting: request.body.hasTasting ? req.body.tasting : null, + cafe: request.body.hasCafe ? req.body.cafe : null, + shop: request.body.hasShop ? req.body.shop : null, + otherBrewing: request.body.hasOtherBrewing ? req.body.otherBrewing : null, startYear: req.body.startYear, endYear: req.body.endYear, userId: req.user._id, From a94159b5cbdfdff87d910871045e262c890054d6 Mon Sep 17 00:00:00 2001 From: erikka-22 Date: Sat, 22 Apr 2023 14:43:50 +0900 Subject: [PATCH 2/2] =?UTF-8?q?comment=E3=81=ABsortOption=E3=81=AE?= =?UTF-8?q?=E3=83=91=E3=83=A9=E3=83=A1=E3=83=BC=E3=82=BF=E3=82=92=E7=94=A8?= =?UTF-8?q?=E6=84=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/commentsController.js | 5 ++++- api/swagger_output.json | 10 ++++++++++ pages/comments/index.vue | 14 +++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/api/controllers/commentsController.js b/api/controllers/commentsController.js index 40bd6d3..19b4851 100644 --- a/api/controllers/commentsController.js +++ b/api/controllers/commentsController.js @@ -13,6 +13,8 @@ module.exports.all = function (req, res, next) { var brand = req.query.brand; var sake = req.query.sake; var userId = req.query.userId; + var sortField = req.query.sortField; + var sortOrder = req.query.sortOrder; var search = {}; if (brewery) { @@ -34,9 +36,10 @@ module.exports.all = function (req, res, next) { { comment: new RegExp(japanese.kanaToHira(keyword), 'i') }, ]; } + Comment.paginate( search, - { page: req.query.page, limit: req.query.limit }, + { page: req.query.page, limit: req.query.limit, sort: {[sortField]: sortOrder} }, function (err, result) { if (err) { return res.status(500).json({ diff --git a/api/swagger_output.json b/api/swagger_output.json index d8fcd03..fe99903 100644 --- a/api/swagger_output.json +++ b/api/swagger_output.json @@ -918,6 +918,16 @@ "name": "limit", "in": "query", "type": "string" + }, + { + "name": "sortField", + "in": "query", + "type": "string" + }, + { + "name": "sortOrder", + "in": "query", + "type": "string" } ], "responses": { diff --git a/pages/comments/index.vue b/pages/comments/index.vue index 77739b2..bd1b5e5 100644 --- a/pages/comments/index.vue +++ b/pages/comments/index.vue @@ -74,6 +74,8 @@ export default { const sake = context.query.sake != null ? context.query.sake : ''; const limit = context.query.limit != null ? context.query.limit : 10; const page = context.query.page != null ? context.query.page : 1; + const sortField = context.query.sortField != null ? context.query.sortField : 'createdAt'; + const sortOrder = context.query.sortOrder != null ? context.query.sortOrder : 'desc'; const { list, currentPage, count } = await getList( 'comments', { @@ -83,6 +85,8 @@ export default { sake: sake, page: page, limit: limit, + sortField: sortField, + sortOrder: sortOrder, }, context ); @@ -94,6 +98,8 @@ export default { comments: list, page: currentPage, count: count, + sortField: sortField, + sortOrder: sortOrder, }; }, data() { @@ -106,6 +112,8 @@ export default { page: 1, count: 0, limit: 10, + sortField: 'createdAt', + sortOrder: 'desc', }; }, mounted() { @@ -120,6 +128,8 @@ export default { this.limit = this.$route.query.limit != null ? this.$route.query.limit : 10; this.page = this.$route.query.page != null ? this.$route.query.page : 1; + this.sortField = this.$route.query.sortField != null ? this.$route.query.sortField : 'createdAt'; + this.sortOrder = this.$route.query.sortOrder != null ? this.$route.query.sortOrder : 'desc'; this.retrieves(); }); }, @@ -132,6 +142,8 @@ export default { brewery: this.brewery, page: this.page, limit: this.limit, + sortField: this.sortField, + sortOrder: this.sortOrder, }); this.comments = list; this.page = currentPage; @@ -144,7 +156,7 @@ export default { }, setHistories() { const url = window.location.href.replace(/\?.*$/, ''); - const queries = `?keyword=${this.keyword}&page=${this.page}&limit=${this.limit}&brewery=${this.brewery}&brand=${this.brand}&sake=${this.sake}`; + const queries = `?sortField=${this.sortField}&sortOrder=${this.sortOrder}&keyword=${this.keyword}&page=${this.page}&limit=${this.limit}&brewery=${this.brewery}&brand=${this.brand}&sake=${this.sake}`; window.history.pushState(null, null, `${url}${queries}`); }, },