Skip to content

Commit e3913a8

Browse files
author
James Cori
committed
Merge branch 'dev'
2 parents 2982bf0 + 39cdfee commit e3913a8

File tree

6 files changed

+161
-8
lines changed

6 files changed

+161
-8
lines changed

docs/swagger.yaml

+84-2
Original file line numberDiff line numberDiff line change
@@ -1252,10 +1252,10 @@ paths:
12521252
application/json:
12531253
schema:
12541254
$ref: '#/components/schemas/Error'
1255-
/terms/type:
1255+
/terms/types:
12561256
get:
12571257
tags:
1258-
- TermsType
1258+
- Types
12591259
description: |
12601260
List all types of terms of uses.
12611261
security:
@@ -1286,6 +1286,86 @@ paths:
12861286
application/json:
12871287
schema:
12881288
$ref: '#/components/schemas/Error'
1289+
/terms/agreeability-types:
1290+
get:
1291+
tags:
1292+
- Agreeability Types
1293+
description: |
1294+
List all agreeability types for terms of uses.
1295+
security:
1296+
- bearerAuth: []
1297+
responses:
1298+
200:
1299+
description: OK
1300+
content:
1301+
application/json:
1302+
schema:
1303+
type: array
1304+
items:
1305+
type: object
1306+
properties:
1307+
id:
1308+
type: string
1309+
legacyId:
1310+
type: number
1311+
name:
1312+
type: string
1313+
description:
1314+
type: string
1315+
401:
1316+
description: Not authenticated
1317+
content:
1318+
application/json:
1319+
schema:
1320+
$ref: '#/components/schemas/Error'
1321+
403:
1322+
description: Forbidden
1323+
content:
1324+
application/json:
1325+
schema:
1326+
$ref: '#/components/schemas/Error'
1327+
/terms/agreeability-types/:id:
1328+
get:
1329+
tags:
1330+
- Agreeability Types
1331+
description: |
1332+
Get One agreeability types by ID
1333+
security:
1334+
- bearerAuth: []
1335+
responses:
1336+
200:
1337+
description: OK
1338+
content:
1339+
application/json:
1340+
schema:
1341+
type: object
1342+
properties:
1343+
id:
1344+
type: string
1345+
legacyId:
1346+
type: number
1347+
name:
1348+
type: string
1349+
description:
1350+
type: string
1351+
401:
1352+
description: Not authenticated
1353+
content:
1354+
application/json:
1355+
schema:
1356+
$ref: '#/components/schemas/Error'
1357+
403:
1358+
description: Forbidden
1359+
content:
1360+
application/json:
1361+
schema:
1362+
$ref: '#/components/schemas/Error'
1363+
404:
1364+
description: Not Found
1365+
content:
1366+
application/json:
1367+
schema:
1368+
$ref: '#/components/schemas/Error'
12891369

12901370
components:
12911371
securitySchemes:
@@ -1355,6 +1435,8 @@ components:
13551435
type: string
13561436
typeId:
13571437
type: integer
1438+
legacyId:
1439+
type: integer
13581440
title:
13591441
type: string
13601442
url:

src/controllers/TermsOfUseController.js

+20
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ async function getTermsOfUseTypes (req, res) {
118118
res.send(await service.getTermsOfUseTypes())
119119
}
120120

121+
/**
122+
* Get all term of use types
123+
* @param req the request
124+
* @param res the response
125+
*/
126+
async function getTermsOfUseAgreeabilityTypes (req, res) {
127+
res.send(await service.getTermsOfUseAgreeabilityTypes())
128+
}
129+
130+
/**
131+
* Get all term of use types
132+
* @param req the request
133+
* @param res the response
134+
*/
135+
async function getTermsOfUseAgreeabilityType (req, res) {
136+
res.send(await service.getTermsOfUseAgreeabilityType(req.params.id))
137+
}
138+
121139
module.exports = {
122140
getTermsOfUse,
123141
agreeTermsOfUse,
@@ -130,5 +148,7 @@ module.exports = {
130148
getTermsOfUseUsers,
131149
signTermsOfUseUser,
132150
unsignTermsOfUseUser,
151+
getTermsOfUseAgreeabilityType,
152+
getTermsOfUseAgreeabilityTypes,
133153
getTermsOfUseTypes
134154
}

src/routes.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
scopes: [constants.Scopes.Terms.Read]
2828
}
2929
},
30-
'/terms/type': {
30+
'/terms/types': {
3131
get: {
3232
controller: 'TermsOfUseController',
3333
method: 'getTermsOfUseTypes',
@@ -36,6 +36,24 @@ module.exports = {
3636
scopes: [constants.Scopes.Terms.Read]
3737
}
3838
},
39+
'/terms/agreeability-types': {
40+
get: {
41+
controller: 'TermsOfUseController',
42+
method: 'getTermsOfUseAgreeabilityTypes',
43+
auth: 'jwt',
44+
access: [constants.UserRoles.Admin],
45+
scopes: [constants.Scopes.Terms.Read]
46+
}
47+
},
48+
'/terms/agreeability-types/:id': {
49+
get: {
50+
controller: 'TermsOfUseController',
51+
method: 'getTermsOfUseAgreeabilityType',
52+
auth: 'jwt',
53+
access: [constants.UserRoles.Admin],
54+
scopes: [constants.Scopes.Terms.Read]
55+
}
56+
},
3957
'/terms': {
4058
post: {
4159
controller: 'TermsOfUseController',

src/services/DocusignService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@ module.exports = {
153153
generateDocusignViewURL
154154
}
155155

156-
logger.buildService(module.exports)
156+
// logger.buildService(module.exports)

src/services/TermsForResourceService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,4 @@ module.exports = {
265265
searchTermsForResources
266266
}
267267

268-
logger.buildService(module.exports)
268+
// logger.buildService(module.exports)

src/services/TermsOfUseService.js

+36-3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function convertRawData (termsOfUse, throwError = true) {
8484
delete termsOfUse['TermsOfUseDocusignTemplateXref.docusignTemplateId']
8585
termsOfUse.agreeabilityType = termsOfUse['TermsOfUseAgreeabilityType.agreeabilityType']
8686
delete termsOfUse['TermsOfUseAgreeabilityType.agreeabilityType']
87+
termsOfUse.type = termsOfUse['TermsOfUseType.type']
88+
delete termsOfUse['TermsOfUseType.type']
8789
if (termsOfUse.agreeabilityTypeId === AGREE_FOR_DOCUSIGN_TEMPLATE) {
8890
// check whether this is for docusign template and that template exists
8991
if (throwError && _.isNull(termsOfUse.docusignTemplateId)) {
@@ -267,6 +269,7 @@ async function createTermsOfUse (currentUser, termsOfUse) {
267269
termsOfUse.createdBy = currentUser.handle || currentUser.sub
268270

269271
let created = await TermsOfUse.create(_.omit(termsOfUse, 'docusignTemplateId'))
272+
termsOfUse.id = created.id
270273

271274
if (termsOfUse.docusignTemplateId) {
272275
await TermsOfUseDocusignTemplateXref.create({
@@ -305,7 +308,7 @@ createTermsOfUse.schema = {
305308
* @returns {Object} the updated terms of use
306309
*/
307310
async function updateTermsOfUse (currentUser, termsOfUseId, data, isFull) {
308-
await validateTermsOfUse(data, false)
311+
await validateTermsOfUse(data)
309312

310313
const termsOfUse = await helper.ensureExists(TermsOfUse, { id: termsOfUseId, deletedAt: null }, false)
311314
const docusignTemplateXref = await termsOfUse.getTermsOfUseDocusignTemplateXref()
@@ -366,6 +369,7 @@ partiallyUpdateTermsOfUse.schema = {
366369
data: Joi.object().keys({
367370
text: Joi.string(),
368371
typeId: Joi.optionalNumberId(),
372+
legacyId: Joi.numberId().optional(),
369373
title: Joi.string(),
370374
url: Joi.string(),
371375
agreeabilityTypeId: Joi.string().uuid().optional(),
@@ -430,6 +434,10 @@ async function searchTermsOfUses (criteria) {
430434
model: TermsOfUseAgreeabilityType,
431435
attributes: [['name', 'agreeabilityType']]
432436
},
437+
{
438+
model: TermsOfUseType,
439+
attributes: [['name', 'type']]
440+
},
433441
{
434442
model: models.TermsOfUseDocusignTemplateXref,
435443
attributes: ['docusignTemplateId']
@@ -495,7 +503,8 @@ searchTermsOfUses.schema = {
495503
* @returns {Object} Return the search result containing the result array and pagination info
496504
*/
497505
async function getTermsOfUseUsers (termsOfUseId, query) {
498-
const { page, perPage } = query
506+
const page = query.page > 0 ? query.page : 1
507+
const perPage = query.perPage > 0 ? query.perPage : 20
499508

500509
let where = {}
501510
if (query.userId) {
@@ -595,6 +604,28 @@ async function getTermsOfUseTypes () {
595604
return TermsOfUseType.findAll({ raw: true })
596605
}
597606

607+
/**
608+
* List all terms of use agreeability types
609+
* @returns {Array} Return an array of term types
610+
*/
611+
async function getTermsOfUseAgreeabilityTypes () {
612+
return TermsOfUseAgreeabilityType.findAll({ raw: true })
613+
}
614+
615+
/**
616+
* Fetch one agreeability type
617+
* @returns {Object} Return an array of term types
618+
*/
619+
async function getTermsOfUseAgreeabilityType (id) {
620+
const obj = await TermsOfUseAgreeabilityType.findOne({ where: { id }, raw: true })
621+
622+
if (!obj) {
623+
throw new errors.NotFoundError(`Agreeability Type id: ${id} doesn't exist.`)
624+
}
625+
626+
return obj
627+
}
628+
598629
module.exports = {
599630
getTermsOfUse,
600631
agreeTermsOfUse,
@@ -607,7 +638,9 @@ module.exports = {
607638
getTermsOfUseUsers,
608639
signTermsOfUseUser,
609640
unsignTermsOfUseUser,
641+
getTermsOfUseAgreeabilityType,
642+
getTermsOfUseAgreeabilityTypes,
610643
getTermsOfUseTypes
611644
}
612645

613-
logger.buildService(module.exports)
646+
// logger.buildService(module.exports)

0 commit comments

Comments
 (0)