import filterParser from './filterParser';

// ?$skip=10
// ->
// query.skip(10)
export default (mongooseModel, $count, $filter) => new Promise((resolve, reject) => {
  if ($count === undefined) {
    return resolve();
  }

  switch ($count) {
    case 'true': {
      const query = mongooseModel.find();
      filterParser(query, $filter);
      query.count((err, count) => resolve(count));
      break;
    }
    case 'false':
      return resolve();
    default:
      return reject('Unknown $count option, only "true" and "false" are supported.');
  }
  return resolve();
});

@@ -42,20 +42,21 @@
 ;%0A%0A// ?$
-skip
+count
 =10%0A// -
@@ -70,12 +70,13 @@
 ery.
-skip
+count
 (10)
@@ -369,16 +369,26 @@
 ount) =%3E
+ %7B%0A       
  resolve
@@ -394,16 +394,25 @@
 e(count)
+;%0A      %7D
 );%0A     
@@ -445,31 +445,24 @@
 lse':%0A      
-return 
 resolve();%0A 
@@ -456,24 +456,37 @@
  resolve();%0A
+      break;%0A
     default:
@@ -492,23 +492,16 @@
 :%0A      
-return 
 reject('
@@ -565,16 +565,29 @@
 ted.');%0A
+      break;%0A
   %7D%0A  re
@@ -591,23 +591,23 @@
  return 
-resolve()
+undefined
 ;%0A%7D);%0A

fix $count not work.