Skip to content

Commit

Permalink
fix: eslint cleanup
Browse files Browse the repository at this point in the history
Automated changes.
  • Loading branch information
Eli Skeggs committed Feb 3, 2020
1 parent 83e117d commit 3c3c913
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions spec/mongoosePluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const { describe } = require('ava-spec');
const test = require('ava');
const mongooseCursorPaginate = require('../src/mongoose.plugin');

let MONGO_URI = 'mongodb://127.0.0.1/mongoose_paginate';
const MONGO_URI = 'mongodb://127.0.0.1/mongoose_paginate';

let AuthorSchema = new mongoose.Schema({ name: String });
const AuthorSchema = new mongoose.Schema({ name: String });

AuthorSchema.plugin(mongooseCursorPaginate, { name: 'paginateFN' });

let Author = mongoose.model('Author', AuthorSchema);
const Author = mongoose.model('Author', AuthorSchema);

let PostSchema = new mongoose.Schema({
const PostSchema = new mongoose.Schema({
title: String,
date: Date,
body: String,
Expand All @@ -24,7 +24,7 @@ let PostSchema = new mongoose.Schema({

PostSchema.plugin(mongooseCursorPaginate);

let Post = mongoose.model('Post', PostSchema);
const Post = mongoose.model('Post', PostSchema);

test.before('start mongoose connection and add data into collection', async () => {
await mongoose.connect(MONGO_URI);
Expand All @@ -33,7 +33,7 @@ test.before('start mongoose connection and add data into collection', async () =

let post,
posts = [];
let date = new Date();
const date = new Date();

for (let i = 1; i <= 100; i++) {
post = new Post({
Expand All @@ -50,17 +50,17 @@ test.before('start mongoose connection and add data into collection', async () =

describe('mongoose plugin', (it) => {
it('paginate function should initialized by provided name', function(t) {
let promise = Author.paginateFN();
const promise = Author.paginateFN();
t.is(promise.then instanceof Function, true);
});

it('return promise', function(t) {
let promise = Post.paginate();
const promise = Post.paginate();
t.is(promise.then instanceof Function, true);
});

it('should return data in expected format', async function(t) {
let data = await Post.paginate();
const data = await Post.paginate();
t.is(data.hasOwnProperty('results'), true);
t.is(data.hasOwnProperty('previous'), true);
t.is(data.hasOwnProperty('hasPrevious'), true);
Expand Down
8 changes: 4 additions & 4 deletions src/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const config = require('./config');
*/
module.exports = async function aggregate(collection, params) {
params = _.defaults(await sanitizeParams(collection, params), { aggregation: [] });
let cursorQuery = generateCursorQuery(params);
let $sort = generateSort(params);
const cursorQuery = generateCursorQuery(params);
const $sort = generateSort(params);

let index = _.findIndex(params.aggregation, (step) => !_.isEmpty(step.$match));

Expand All @@ -57,13 +57,13 @@ module.exports = async function aggregate(collection, params) {
params.aggregation.splice(index + 1, 0, { $sort });
params.aggregation.splice(index + 2, 0, { $limit: params.limit + 1 });

let options = config.COLLATION ? { collation: config.COLLATION } : undefined;
const options = config.COLLATION ? { collation: config.COLLATION } : undefined;

// Support both the native 'mongodb' driver and 'mongoist'. See:
// https://www.npmjs.com/package/mongoist#cursor-operations
const aggregateMethod = collection.aggregateAsCursor ? 'aggregateAsCursor' : 'aggregate';

let results = await collection[aggregateMethod](params.aggregation, options).toArray();
const results = await collection[aggregateMethod](params.aggregation, options).toArray();

return prepareResponse(results, params);
};

0 comments on commit 3c3c913

Please # to comment.