aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-06-25 18:56:55 +0300
committerGitHub <noreply@github.com>2020-06-25 18:56:55 +0300
commit343a975413d8d3ce8194507017fb4ca01a4faf54 (patch)
treebdf1ebf9113739bfb08cd61239c117d02e273fe7
parent32e9cd6eec8f45fd9b53c8ab3af5907c8d4064bc (diff)
parent7bf3e5020bf456b1450bb19bea43df7862cfb08e (diff)
downloadwhich-api-343a975413d8d3ce8194507017fb4ca01a4faf54.tar.gz
Merge pull request #10 from which-ecosystem/circleci
Configure CI
-rw-r--r--.circleci/config.yml38
-rw-r--r--hooks/convertPoll.ts4
-rw-r--r--models/polls/poll.model.ts10
-rw-r--r--models/polls/poll.schema.ts2
-rw-r--r--package.json6
-rw-r--r--populateDb.ts6
-rw-r--r--services/index.ts2
-rw-r--r--services/polls/polls.hooks.ts2
-rw-r--r--services/users/users.hooks.ts2
-rw-r--r--services/votes/votes.hooks.ts2
10 files changed, 56 insertions, 18 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 0000000..a6876ba
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,38 @@
+version: 2
+
+defaults: &defaults
+ working_directory: ~/repo
+ docker:
+ - image: circleci/node:12-stretch
+
+jobs:
+ checkout_and_test:
+ <<: *defaults
+ steps:
+ - checkout
+ - restore_cache:
+ keys:
+ - v1-dependencies-{{ checksum "package.json" }}
+ # fallback to using the latest cache if no exact match is found
+ - v1-dependencies-
+
+ - run:
+ name: Install NPM dependencies
+ command: npm install
+
+ - save_cache:
+ paths:
+ - node_modules
+ key: v1-dependencies-{{ checksum "package.json" }}
+
+ - run:
+ name: Test syntax and perform type checking
+ command: npm test
+
+workflows:
+ version: 2
+
+ test:
+ jobs:
+ - checkout_and_test
+
diff --git a/hooks/convertPoll.ts b/hooks/convertPoll.ts
index 1c32851..5e6f9f4 100644
--- a/hooks/convertPoll.ts
+++ b/hooks/convertPoll.ts
@@ -2,7 +2,7 @@ import { HookContext } from '@feathersjs/feathers';
import { Types } from 'mongoose';
import bluebird from 'bluebird';
import _ from 'lodash';
-import { Poll, User, Vote } from 'which-types';
+import { Poll } from 'which-types';
import { PollSchema } from '../models/polls/poll.schema';
import VoteModel from '../models/votes/vote.model';
@@ -18,7 +18,7 @@ export default async (context: HookContext): Promise<HookContext> => {
{ $match: { pollId: Types.ObjectId(poll._id) } },
{ $group: { _id: '$which', total: { $sum: 1 } } }
]).then(groups => groups.reduce(
- (acc, group) => _.set(acc, group._id + '.votes', group.total),
+ (acc, group) => _.set(acc, `${group._id}.votes`, group.total),
{ left: { votes: 0 }, right: { votes: 0 } }
));
diff --git a/models/polls/poll.model.ts b/models/polls/poll.model.ts
index 6749e5c..ed05cc7 100644
--- a/models/polls/poll.model.ts
+++ b/models/polls/poll.model.ts
@@ -1,9 +1,9 @@
-import { Model, model } from 'mongoose';
-import { PollSchema, pollSchema } from './poll.schema';
-import { Types } from 'mongoose';
+import { Model, model, Types } from 'mongoose';
import { Which } from 'which-types';
+import { PollSchema, pollSchema } from './poll.schema';
+
-pollSchema.methods.vote = function(userId: string, which: Which): PollSchema {
+pollSchema.methods.vote = function vote(userId: string, which: Which): PollSchema {
const participants: Types.ObjectId[] = ['left', 'right'].reduce((acc, option) => {
const { votes } = this.contents[option];
return acc.concat(votes);
@@ -14,7 +14,7 @@ pollSchema.methods.vote = function(userId: string, which: Which): PollSchema {
}
return this.save();
-}
+};
export default model<PollSchema, Model<PollSchema>>('Poll', pollSchema);
diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts
index 4d1d762..3a57c28 100644
--- a/models/polls/poll.schema.ts
+++ b/models/polls/poll.schema.ts
@@ -15,7 +15,7 @@ export interface PollSchema extends Document {
}
export const imageDataSchema = {
- url: String,
+ url: String
};
export const pollSchema = new Schema({
diff --git a/package.json b/package.json
index ecdd31d..1a21fcf 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,8 @@
"cors": "^2.8.5",
"feathers-mongoose": "^8.3.0",
"lodash": "^4.17.15",
- "mongoose": "^5.9.18"
+ "mongoose": "^5.9.18",
+ "which-types": "^1.4.0"
},
"repository": {
"type": "git",
@@ -42,7 +43,6 @@
"eslint": "^7.2.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.21.2",
- "typescript": "^3.9.5",
- "which-types": "^1.4.0"
+ "typescript": "^3.9.5"
}
}
diff --git a/populateDb.ts b/populateDb.ts
index 757280a..6daa2f8 100644
--- a/populateDb.ts
+++ b/populateDb.ts
@@ -36,7 +36,7 @@ const choices = [
const createPoll = (authorId: string): Promise<Poll> => {
const generateImageData = () => ({
- url: _.sample(imageUrls) || '',
+ url: _.sample(imageUrls) || ''
});
return app.service('polls').create({
@@ -61,7 +61,7 @@ const createVote = (userId: string, pollId: string): Promise<Vote> => {
pollId,
which: _.sample(choices)
}, { user: { _id: userId } });
-}
+};
const populate = async () => {
@@ -72,7 +72,7 @@ const populate = async () => {
return createPoll(user?._id || '');
});
- const votes = await bluebird.map(users, user => {
+ await bluebird.map(users, user => {
const pollsToVote = _.sampleSize(polls, _.random(0, POLLS_AMOUNT));
return bluebird.map(pollsToVote, poll => createVote(user?._id || '', poll?._id || ''));
});
diff --git a/services/index.ts b/services/index.ts
index fe5ffdc..ce20901 100644
--- a/services/index.ts
+++ b/services/index.ts
@@ -18,6 +18,6 @@ export default (app: Application): void => {
before: {
all: tryAuthenticate
}
- })
+ });
};
diff --git a/services/polls/polls.hooks.ts b/services/polls/polls.hooks.ts
index eba3e63..13d6f63 100644
--- a/services/polls/polls.hooks.ts
+++ b/services/polls/polls.hooks.ts
@@ -2,7 +2,7 @@ import convertPoll from '../../hooks/convertPoll';
export default {
after: {
- all: [convertPoll],
+ all: [convertPoll]
}
};
diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts
index 8eecca3..ee1ae1c 100644
--- a/services/users/users.hooks.ts
+++ b/services/users/users.hooks.ts
@@ -6,7 +6,7 @@ const hashPassword = hooks.hashPassword('password');
const localDispatch = async (context: HookContext): Promise<HookContext> => {
context.result = context.dispatch;
return context;
-}
+};
export default {
after: {
diff --git a/services/votes/votes.hooks.ts b/services/votes/votes.hooks.ts
index 1cf7261..7d0b3ba 100644
--- a/services/votes/votes.hooks.ts
+++ b/services/votes/votes.hooks.ts
@@ -2,7 +2,7 @@ import { HookContext } from '@feathersjs/feathers';
import requireAuth from '../../hooks/requireAuth';
const addUserId = async (context: HookContext): Promise<HookContext> => {
- const { params: { user} } = context;
+ const { params: { user } } = context;
context.data.userId = user._id;
return context;
};