Skip to content

Commit 8a2e586

Browse files
committed
Terms API part2 challenge output
Resource terms CRUDL endpoints
1 parent d92cfb4 commit 8a2e586

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4738
-360
lines changed

ReadMe.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ run `npm run test` under docusign_callback folder
5555
- Install dependencies `npm install`
5656
- Run lint `npm run lint`
5757
- Run lint fix `npm run lint:fix`
58-
- Start app `npm start`
59-
- App is running at `http://localhost:3000`
58+
- Setup process environment `source env.sh`
6059
- Clear and init db `npm run init-db`
6160
- Insert test data `npm run test-data`
61+
- Start app `npm start`
62+
- App is running at `http://localhost:3000`
6263

6364
## Testing
64-
#### You need to `stop` the app before running unit or e2e tests.
65+
#### You need to `stop` the app and run command `source env.sh` before running unit or e2e tests.
6566
- Run `npm run test` to execute unit tests and generate coverage report.
6667
- RUN `npm run e2e` to execute e2e tests and generate coverage report.
6768

app-bootstrap.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
global.Promise = require('bluebird')
66
const Joi = require('joi')
77

8-
Joi.numberId = () => Joi.number().integer().min(1).max(2147483647).required()
8+
Joi.optionalNumberId = () => Joi.number().integer().min(1).max(2147483647)
9+
Joi.numberId = () => Joi.optionalNumberId().required()
910
Joi.uuid = () => Joi.string().uuid().required()
11+
Joi.page = () => Joi.number().integer().min(1).default(1)
12+
Joi.perPage = () => Joi.number().integer().min(1).max(100).default(20)

app-constants.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ const Templates = [{
7272
handlers: []
7373
}]
7474

75+
const UserRoles = {
76+
Admin: 'Administrator'
77+
}
78+
7579
module.exports = {
7680
Templates,
7781
AGREE_FOR_DOCUSIGN_TEMPLATE: 4,
7882
ELECT_AGREEABLE: 'Electronically-agreeable',
79-
TEMPLATE_ID_INVALID: 'TEMPLATE_ID_INVALID'
83+
TEMPLATE_ID_INVALID: 'TEMPLATE_ID_INVALID',
84+
UserRoles
8085
}

app-routes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ module.exports = (app) => {
4444
if (def.auth || (def.optionalAuth && req.headers.authorization)) {
4545
if (req.authUser.isMachine) {
4646
next(new errors.ForbiddenError('M2M token is not supported'))
47+
} else {
48+
if (def.access && (!req.authUser.roles || !helper.checkIfExists(def.access, req.authUser.roles))) {
49+
next(new errors.ForbiddenError('You are not allowed to perform this action!'))
50+
}
4751
}
4852
}
4953
next()

app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const logger = require('./src/common/logger')
1414
const interceptor = require('express-interceptor')
1515
const healthcheck = require('topcoder-healthcheck-dropin')
1616

17-
1817
// setup express app
1918
const app = express()
2019

@@ -53,7 +52,7 @@ app.use(interceptor((req, res) => {
5352
// check if api is started
5453
// TODO: check db connection, docusign callback
5554
function check () {
56-
return true;
55+
return true
5756
}
5857

5958
app.use(healthcheck.middleware([check]))

build.sh

100755100644
File mode changed.

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ module.exports = {
77
PORT: process.env.PORT || 3000,
88

99
AUTH_SECRET: process.env.AUTH_SECRET || 'mysecret',
10-
VALID_ISSUERS: process.env.VALID_ISSUERS || '["https://api.topcoder-dev.com", "https://api.topcoder.com", "https://topcoder-dev.auth0.com/"]',
10+
VALID_ISSUERS: process.env.VALID_ISSUERS || '["https://api.topcoder-dev.com", "https://api.topcoder.com", "https://topcoder-dev.auth0.com"]',
1111

1212
POSTGRES_URL: process.env.POSTGRES_URL || 'postgres://postgres:password@localhost:5432/postgres',
13+
DB_SCHEMA_NAME: process.env.DB_SCHEMA_NAME || 'termsdb',
1314

1415
AUTH0_URL: process.env.AUTH0_URL,
1516
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',

config/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
module.exports = {
66
WAIT_TIME: 1500,
77
DOCUSIGN: {
8-
ASSIGNMENT_TERMS_OF_USE_ID: process.env.ASSIGNMENT_TERMS_OF_USE_ID || 20754
8+
ASSIGNMENT_TERMS_OF_USE_ID: 20754
99
}
1010
}

0 commit comments

Comments
 (0)