Skip to content

Commit 343a975

Browse files
authored
Merge pull request #10 from which-ecosystem/circleci
Configure CI
2 parents 32e9cd6 + 7bf3e50 commit 343a975

File tree

10 files changed

+56
-18
lines changed

10 files changed

+56
-18
lines changed

.circleci/config.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: 2
2+
3+
defaults: &defaults
4+
working_directory: ~/repo
5+
docker:
6+
- image: circleci/node:12-stretch
7+
8+
jobs:
9+
checkout_and_test:
10+
<<: *defaults
11+
steps:
12+
- checkout
13+
- restore_cache:
14+
keys:
15+
- v1-dependencies-{{ checksum "package.json" }}
16+
# fallback to using the latest cache if no exact match is found
17+
- v1-dependencies-
18+
19+
- run:
20+
name: Install NPM dependencies
21+
command: npm install
22+
23+
- save_cache:
24+
paths:
25+
- node_modules
26+
key: v1-dependencies-{{ checksum "package.json" }}
27+
28+
- run:
29+
name: Test syntax and perform type checking
30+
command: npm test
31+
32+
workflows:
33+
version: 2
34+
35+
test:
36+
jobs:
37+
- checkout_and_test
38+

hooks/convertPoll.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HookContext } from '@feathersjs/feathers';
22
import { Types } from 'mongoose';
33
import bluebird from 'bluebird';
44
import _ from 'lodash';
5-
import { Poll, User, Vote } from 'which-types';
5+
import { Poll } from 'which-types';
66

77
import { PollSchema } from '../models/polls/poll.schema';
88
import VoteModel from '../models/votes/vote.model';
@@ -18,7 +18,7 @@ export default async (context: HookContext): Promise<HookContext> => {
1818
{ $match: { pollId: Types.ObjectId(poll._id) } },
1919
{ $group: { _id: '$which', total: { $sum: 1 } } }
2020
]).then(groups => groups.reduce(
21-
(acc, group) => _.set(acc, group._id + '.votes', group.total),
21+
(acc, group) => _.set(acc, `${group._id}.votes`, group.total),
2222
{ left: { votes: 0 }, right: { votes: 0 } }
2323
));
2424

models/polls/poll.model.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Model, model } from 'mongoose';
2-
import { PollSchema, pollSchema } from './poll.schema';
3-
import { Types } from 'mongoose';
1+
import { Model, model, Types } from 'mongoose';
42
import { Which } from 'which-types';
3+
import { PollSchema, pollSchema } from './poll.schema';
4+
55

6-
pollSchema.methods.vote = function(userId: string, which: Which): PollSchema {
6+
pollSchema.methods.vote = function vote(userId: string, which: Which): PollSchema {
77
const participants: Types.ObjectId[] = ['left', 'right'].reduce((acc, option) => {
88
const { votes } = this.contents[option];
99
return acc.concat(votes);
@@ -14,7 +14,7 @@ pollSchema.methods.vote = function(userId: string, which: Which): PollSchema {
1414
}
1515

1616
return this.save();
17-
}
17+
};
1818

1919
export default model<PollSchema, Model<PollSchema>>('Poll', pollSchema);
2020

models/polls/poll.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface PollSchema extends Document {
1515
}
1616

1717
export const imageDataSchema = {
18-
url: String,
18+
url: String
1919
};
2020

2121
export const pollSchema = new Schema({

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"cors": "^2.8.5",
2222
"feathers-mongoose": "^8.3.0",
2323
"lodash": "^4.17.15",
24-
"mongoose": "^5.9.18"
24+
"mongoose": "^5.9.18",
25+
"which-types": "^1.4.0"
2526
},
2627
"repository": {
2728
"type": "git",
@@ -42,7 +43,6 @@
4243
"eslint": "^7.2.0",
4344
"eslint-config-airbnb-typescript": "^8.0.2",
4445
"eslint-plugin-import": "^2.21.2",
45-
"typescript": "^3.9.5",
46-
"which-types": "^1.4.0"
46+
"typescript": "^3.9.5"
4747
}
4848
}

populateDb.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const choices = [
3636

3737
const createPoll = (authorId: string): Promise<Poll> => {
3838
const generateImageData = () => ({
39-
url: _.sample(imageUrls) || '',
39+
url: _.sample(imageUrls) || ''
4040
});
4141

4242
return app.service('polls').create({
@@ -61,7 +61,7 @@ const createVote = (userId: string, pollId: string): Promise<Vote> => {
6161
pollId,
6262
which: _.sample(choices)
6363
}, { user: { _id: userId } });
64-
}
64+
};
6565

6666

6767
const populate = async () => {
@@ -72,7 +72,7 @@ const populate = async () => {
7272
return createPoll(user?._id || '');
7373
});
7474

75-
const votes = await bluebird.map(users, user => {
75+
await bluebird.map(users, user => {
7676
const pollsToVote = _.sampleSize(polls, _.random(0, POLLS_AMOUNT));
7777
return bluebird.map(pollsToVote, poll => createVote(user?._id || '', poll?._id || ''));
7878
});

services/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export default (app: Application): void => {
1818
before: {
1919
all: tryAuthenticate
2020
}
21-
})
21+
});
2222
};
2323

services/polls/polls.hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import convertPoll from '../../hooks/convertPoll';
22

33
export default {
44
after: {
5-
all: [convertPoll],
5+
all: [convertPoll]
66
}
77
};
88

services/users/users.hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const hashPassword = hooks.hashPassword('password');
66
const localDispatch = async (context: HookContext): Promise<HookContext> => {
77
context.result = context.dispatch;
88
return context;
9-
}
9+
};
1010

1111
export default {
1212
after: {

services/votes/votes.hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HookContext } from '@feathersjs/feathers';
22
import requireAuth from '../../hooks/requireAuth';
33

44
const addUserId = async (context: HookContext): Promise<HookContext> => {
5-
const { params: { user} } = context;
5+
const { params: { user } } = context;
66
context.data.userId = user._id;
77
return context;
88
};

0 commit comments

Comments
 (0)