@waline/vercel 1.19.4 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/vercel",
3
- "version": "1.19.4",
3
+ "version": "1.20.0",
4
4
  "description": "vercel server for waline comment system",
5
5
  "keywords": [
6
6
  "waline",
@@ -247,7 +247,7 @@ module.exports = class extends BaseRest {
247
247
  }
248
248
 
249
249
  default: {
250
- const { path: url, page, pageSize } = this.get();
250
+ const { path: url, page, pageSize, sortBy } = this.get();
251
251
  const where = { url };
252
252
 
253
253
  if (think.isEmpty(userInfo) || this.config('storage') === 'deta') {
@@ -266,7 +266,6 @@ module.exports = class extends BaseRest {
266
266
  let rootComments = [];
267
267
  let rootCount = 0;
268
268
  const selectOptions = {
269
- desc: 'insertedAt',
270
269
  field: [
271
270
  'status',
272
271
  'comment',
@@ -284,6 +283,16 @@ module.exports = class extends BaseRest {
284
283
  ],
285
284
  };
286
285
 
286
+ if (sortBy) {
287
+ const [field, order] = sortBy.split('_');
288
+
289
+ if (order === 'desc') {
290
+ selectOptions.desc = field;
291
+ } else if (order === 'asc') {
292
+ // do nothing because of ascending order is default behaviour
293
+ }
294
+ }
295
+
287
296
  /**
288
297
  * most of case we have just little comments
289
298
  * while if we want get rootComments, rootCount, childComments with pagination
@@ -32,6 +32,7 @@ module.exports = class extends Base {
32
32
  * @apiParam {String} path comment url path
33
33
  * @apiParam {String} page page
34
34
  * @apiParam {String} pagesize page size
35
+ * @apiParam {String} sortBy comment sort type, one of 'insertedAt_desc', 'insertedAt_asc', 'like_desc'
35
36
  *
36
37
  * @apiSuccess (200) {Number} page return current comments list page
37
38
  * @apiSuccess (200) {Number} pageSize to return error message if error
@@ -168,6 +169,10 @@ module.exports = class extends Base {
168
169
  int: { max: 100 },
169
170
  default: 10,
170
171
  },
172
+ sortBy: {
173
+ in: ['insertedAt_desc', 'insertedAt_asc', 'like_desc'],
174
+ default: 'insertedAt_desc',
175
+ },
171
176
  };
172
177
  break;
173
178
  }
@@ -44,7 +44,7 @@ module.exports = class extends Base {
44
44
 
45
45
  instance.where(this.parseWhere(where));
46
46
  if (desc) {
47
- instance.order(`${desc} DESC`);
47
+ instance.order(`\`${desc}\` DESC`);
48
48
  }
49
49
  if (limit || offset) {
50
50
  instance.limit(offset || 0, limit);