Skip to content

Commit

Permalink
chore: upgrade to [email protected]
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Nov 2, 2018
1 parent 5ea5913 commit 7d95e09
Show file tree
Hide file tree
Showing 10 changed files with 1,216 additions and 2,375 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

const application = require('@loopback/dist-util').loadDist(__dirname);
const application = require('./dist');

module.exports = application;

Expand Down
3,437 changes: 1,116 additions & 2,321 deletions package-lock.json

Large diffs are not rendered by default.

61 changes: 31 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
"node": ">=8"
},
"scripts": {
"build:all-dist": "npm run build:dist8 && npm run build:dist10",
"build:apidocs": "lb-apidocs",
"build": "lb-tsc",
"build:dist8": "lb-tsc es2017",
"build:dist10": "lb-tsc es2018",
"build:watch": "lb-tsc --watch",
"build": "lb-tsc es2017 --outDir dist --copy-resources",
"build:watch": "lb-tsc es2017 --outDir dist --watch",
"clean": "lb-clean dist*",
"commit": "git-cz",
"commitmsg": "commitlint -E GIT_PARAMS",
Expand All @@ -31,10 +28,10 @@
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build && npm run docker:start",
"pretest:ci": "npm run build",
"test": "lb-mocha --allow-console-logs \"DIST/test\"",
"test:ci": "lb-mocha --allow-console-logs \"DIST/test\"",
"test": "lb-mocha --allow-console-logs \"dist/test\"",
"test:ci": "lb-mocha --allow-console-logs \"dist/test\"",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs DIST/test/**/*.js && npm run posttest",
"test:dev": "lb-mocha --allow-console-logs dist/test/**/*.js && npm run posttest",
"prestart": "npm run build",
"start": "concurrently --kill-others \"npm run start:app\" \"npm run start:recommender\"",
"start:app": "node .",
Expand All @@ -54,39 +51,38 @@
"src"
],
"dependencies": {
"@loopback/boot": "^0.14.1",
"@loopback/context": "^0.12.11",
"@loopback/core": "^0.11.12",
"@loopback/dist-util": "^0.3.7",
"@loopback/openapi-v3": "^0.15.0",
"@loopback/repository": "^0.18.0",
"@loopback/rest": "^0.25.0",
"@loopback/service-proxy": "^0.8.6",
"@loopback/boot": "^1.0.2",
"@loopback/context": "^1.0.0",
"@loopback/core": "^1.0.0",
"@loopback/openapi-v3": "^1.0.2",
"@loopback/repository": "^1.0.2",
"@loopback/rest": "^1.1.0",
"@loopback/service-proxy": "^1.0.0",
"bcryptjs": "^2.4.3",
"debug": "^4.0.1",
"express": "^4.16.3",
"isemail": "^3.1.3",
"debug": "^4.1.0",
"express": "^4.16.4",
"isemail": "^3.2.0",
"lodash": "^4.17.11",
"loopback-connector-kv-redis": "^3.0.0",
"loopback-connector-mongodb": "^3.8.0",
"loopback-connector-rest": "^3.3.0"
"loopback-connector-mongodb": "^3.9.1",
"loopback-connector-rest": "^3.4.1"
},
"devDependencies": {
"@commitlint/cli": "^7.1.2",
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@commitlint/travis-cli": "^7.1.2",
"@loopback/build": "^0.7.3",
"@loopback/testlab": "^0.14.0",
"@commitlint/travis-cli": "^7.2.1",
"@loopback/build": "^1.0.0",
"@loopback/testlab": "^1.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/debug": "^0.0.30",
"@types/debug": "0.0.31",
"@types/express": "^4.16.0",
"@types/lodash": "^4.14.116",
"@types/lodash": "^4.14.117",
"@types/mocha": "^5.0.0",
"@types/node": "^10.11.0",
"commitizen": "^2.10.1",
"@types/node": "^10.12.2",
"commitizen": "^3.0.4",
"concurrently": "^4.0.1",
"cz-conventional-changelog": "^2.1.0",
"husky": "^0.14.3",
"husky": "^1.1.3",
"mocha": "^5.2.0",
"source-map-support": "^0.5.9"
},
Expand All @@ -95,5 +91,10 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
7 changes: 1 addition & 6 deletions recommender.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

const distUtil = require('@loopback/dist-util');
const path = require('path');

const app = require(path.join(
__dirname,
distUtil.getDist(__dirname),
'/recommender',
));
const app = require('./dist/recommender');

module.exports = app.createRecommendationServer();
28 changes: 23 additions & 5 deletions src/controllers/user-order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {repository, Filter, Where} from '@loopback/repository';
import {repository, Filter, Where, Count} from '@loopback/repository';
import {UserRepository} from '../repositories';
import {
post,
Expand Down Expand Up @@ -74,15 +74,24 @@ export class UserOrderController {
responses: {
'200': {
description: 'User.Order PATCH success count',
content: {'application/json': {'x-ts-type': Number}},
content: {
'application/json': {
schema: {
type: 'object',
properties: {
count: 'number',
},
},
},
},
},
},
})
async patchOrders(
@param.path.string('userId') userId: string,
@requestBody() order: Partial<Order>,
@param.query.string('where') where?: Where,
): Promise<number> {
): Promise<Count> {
return await this.userRepo
.orders(userId)
.patch(order, where, {strictObjectIDCoercion: true});
Expand All @@ -92,14 +101,23 @@ export class UserOrderController {
responses: {
'200': {
description: 'User.Order DELETE success count',
content: {'application/json': {'x-ts-type': Number}},
content: {
'application/json': {
schema: {
type: 'object',
properties: {
count: 'number',
},
},
},
},
},
},
})
async deleteOrders(
@param.path.string('userId') userId: string,
@param.query.string('where') where?: Where,
): Promise<number> {
): Promise<Count> {
return await this.userRepo
.orders(userId)
.delete(where, {strictObjectIDCoercion: true});
Expand Down
41 changes: 35 additions & 6 deletions src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,46 @@ export class UserController {
return savedUser;
}

@get('/users/{id}')
async findById(@param.path.string('id') id: string): Promise<User> {
return this.userRepository.findById(id, {
@get('/users/{userId}', {
responses: {
'200': {
description: 'User',
content: {
'application/json': {
schema: {
'x-ts-type': User,
},
},
},
},
},
})
async findById(@param.path.string('userId') userId: string): Promise<User> {
return this.userRepository.findById(userId, {
fields: {password: false},
});
}

@get('/users/{id}/recommend')
@get('/users/{userId}/recommend', {
responses: {
'200': {
description: 'Products',
content: {
'application/json': {
schema: {
type: 'array',
items: {
'x-ts-type': Product,
},
},
},
},
},
},
})
async productRecommendations(
@param.path.string('id') id: string,
@param.path.string('userId') userId: string,
): Promise<Product[]> {
return this.recommender.getProductRecommendations(id);
return this.recommender.getProductRecommendations(userId);
}
}
2 changes: 1 addition & 1 deletion src/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class User extends Entity {
})
surname?: string;

@hasMany(Order)
@hasMany(() => Order)
orders: Order[];

constructor(data?: Partial<User>) {
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class UserRepository extends DefaultCrudRepository<
super(User, datasource);
this.orders = this._createHasManyRepositoryFactoryFor(
'orders',
orderRepository,
async () => orderRepository,
);
}
}
4 changes: 2 additions & 2 deletions test/acceptance/user-order.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ describe('UserOrderController acceptance tests', () => {
await client
.patch(`/users/${userId}/orders`)
.send({total: 9.99})
.expect(200, '2');
.expect(200, {count: 2});
});

// TODO(virkt25): Implement after issue below is fixed.
// https://github.com/strongloop/loopback-next/issues/100
it.skip('patches orders matching filter for a given user');

it('deletes all orders for a given user', async () => {
await client.del(`/users/${userId}/orders`).expect(200, '2');
await client.del(`/users/${userId}/orders`).expect(200, {count: 2});
});

// TODO(virkt25): Implement after issue below is fixed.
Expand Down
7 changes: 5 additions & 2 deletions test/acceptance/user.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('UserController', () => {
.expect(415);
});

it('returns a user with given id when GET /user/{id} is invoked', async () => {
it('returns a user with given id when GET /users/{id} is invoked', async () => {
const newUser = await userRepo.create(user);
delete newUser.password;
delete newUser.orders;
Expand All @@ -123,7 +123,10 @@ describe('UserController', () => {
});

it('returns product recommendations for a user', async () => {
await client.get(`/users/userid/recommend`).expect(200, recommendations);
const newUser = await userRepo.create(user);
await client
.get(`/users/${newUser.id}/recommend`)
.expect(200, recommendations);
});
});

Expand Down

0 comments on commit 7d95e09

Please sign in to comment.