Skip to content

Commit

Permalink
Merge pull request #379 from flexion/113_lambdas
Browse files Browse the repository at this point in the history
113 Lambdas and Interactor Skeletons
  • Loading branch information
codyseibert authored Dec 14, 2018
2 parents 4194ae1 + e92c0e3 commit d6435e2
Show file tree
Hide file tree
Showing 13 changed files with 336 additions and 13 deletions.
1 change: 1 addition & 0 deletions efcms-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"src/cases",
"src/documents",
"src/swagger",
"src/workitems",
"src/applicationContext.js"
],
"reporter": [
Expand Down
104 changes: 96 additions & 8 deletions efcms-service/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ custom:
createdAt:
type: string
description: date case created
- name: 'rawDocument'
description: 'a rawDocument response'
- name: 'document'
description: 'a document response'
contentType: 'application/json'
schema:
type: object
Expand All @@ -108,13 +108,41 @@ custom:
description: id of rawDocument
userId:
type: string
description: id of user who created the rawDocument
description: id of user who created the document
documentType:
type: string
description: type of this rawDocument
description: type of this document
createdAt:
type: string
description: date rawDocument created
description: date document created
- name: 'workItem'
description: 'a workItem response'
contentType: 'application/json'
schema:
type: object
properties:
workItemId:
type: string
description: id of work item
assigneeId:
type: string
description: id of user currently assigned the work item
messages:
type: array
items:
type: object
properties:
messageId:
type: string
messageType:
type: string
description: array of messages associated with the workitem
createdAt:
type: string
description: date workItem created
updatedAt:
type: string
description: date workItem created
- name: 'policyUrl'
description: 'a policy url response'
contentType: 'application/json'
Expand Down Expand Up @@ -301,7 +329,7 @@ functions:
tags:
- documents
description: >
Create a pre-signed url for rawDocument uploads to S3.
Create a pre-signed url for document uploads to S3.
methodResponses:
- statusCode: '200'
responseBody:
Expand All @@ -321,7 +349,7 @@ functions:
tags:
- documents
description: >
Create a pre-signed url for rawDocument downloads from S3.
Create a pre-signed url for document downloads from S3.
methodResponses:
- statusCode: '200'
responseBody:
Expand Down Expand Up @@ -370,7 +398,7 @@ functions:
- name: documents
in: body
required: true
description: rawDocument metadata
description: document metadata
schema:
type: array
items:
Expand Down Expand Up @@ -449,6 +477,66 @@ functions:
responseModels:
'application/json': 'unprocessableEntityError'

getWorkItem:
handler: src/workitems/getWorkItemLambda.get
events:
- http:
path: v1/workitems/{workItemId}
method: get
cors: true
documentation:
summary: get a workitem by workItemId
tags:
- workitems
description: >
Get a workitem.
methodResponses:
- statusCode: '200'
responseBody:
description: 'workitem'
responseModels:
'application/json': workItem

updateWorkItem:
handler: src/workitems/updateWorkItemLambda.put
events:
- http:
path: v1/workitems/{workItemId}
method: put
cors: true
documentation:
summary: update a workitem by workItemId
tags:
- workitems
description: >
Update a workitem.
methodResponses:
- statusCode: '200'
responseBody:
description: 'workitem'
responseModels:
'application/json': workItem

getWorkItems:
handler: src/workitems/getWorkItemsLambda.get
events:
- http:
path: v1/workitems
method: get
cors: true
documentation:
summary: get all workitems for a user
tags:
- workitems
description: >
Get all workitems for a user.
methodResponses:
- statusCode: '200'
responseBody:
description: 'array of workitems'
responseModels:
'application/json': workItem

swagger:
handler: src/swagger/swaggerLambda.handler
events:
Expand Down
6 changes: 6 additions & 0 deletions efcms-service/src/applicationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const { sendPetitionToIRS } = require('ef-cms-shared/src/business/useCases/sendP
const { updateCase } = require('ef-cms-shared/src/business/useCases/updateCase.interactor');
const { uploadCasePdfs } = require('ef-cms-shared/src/business/useCases/uploadCasePdfs.interactor');
const { getCasesForRespondent: getCasesForRespondentUC } = require('ef-cms-shared/src/business/useCases/respondent/getCasesForRespondent.interactor');
const { getWorkItem } = require('ef-cms-shared/src/business/useCases/workitems/getWorkItem.interactor');
const { getWorkItems } = require('ef-cms-shared/src/business/useCases/workitems/getWorkItems.interactor');
const { updateWorkItem } = require('ef-cms-shared/src/business/useCases/workitems/updateWorkItem.interactor');

module.exports = {
getPersistenceGateway: () => {
Expand Down Expand Up @@ -65,6 +68,9 @@ module.exports = {
updateCase,
uploadCasePdfs,
getCasesForRespondent: getCasesForRespondentUC,
getWorkItem,
getWorkItems,
updateWorkItem,
};
},
};
3 changes: 1 addition & 2 deletions efcms-service/src/cases/getCaseLambda.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { getAuthHeader } = require('../middleware/apiGatewayHelper');
const { handle } = require('../middleware/apiGatewayHelper');
const { getCase } = require('ef-cms-shared/src/business/useCases/getCase.interactor');
const applicationContext = require('../applicationContext');

/**
Expand All @@ -11,7 +10,7 @@ const applicationContext = require('../applicationContext');
*/
exports.get = event =>
handle(() =>
getCase({
applicationContext.getUseCases().getCase({
userId: getAuthHeader(event),
caseId: event.pathParameters.caseId,
applicationContext,
Expand Down
3 changes: 1 addition & 2 deletions efcms-service/src/cases/updateCaseLambda.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { updateCase } = require('ef-cms-shared/src/business/useCases/updateCase.interactor');
const { handle, getAuthHeader } = require('../middleware/apiGatewayHelper');
const applicationContext = require('../applicationContext');

Expand All @@ -11,7 +10,7 @@ const applicationContext = require('../applicationContext');
exports.put = event =>
handle(() => {
const userId = getAuthHeader(event);
return updateCase({
return applicationContext.getUseCases().updateCase({
caseId: event.pathParameters.caseId,
caseToUpdate: JSON.parse(event.body),
userId,
Expand Down
18 changes: 18 additions & 0 deletions efcms-service/src/workitems/getWorkItemLambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { getAuthHeader } = require('../middleware/apiGatewayHelper');
const { handle } = require('../middleware/apiGatewayHelper');
const applicationContext = require('../applicationContext');

/**
* getWorkItem
*
* @param event
* @returns {Promise<*|undefined>}
*/
exports.get = event =>
handle(() =>
applicationContext.getUseCases().getWorkItem({
userId: getAuthHeader(event),
workItemId: event.pathParameters.workItemId,
applicationContext,
}),
);
16 changes: 16 additions & 0 deletions efcms-service/src/workitems/getWorkItemsLambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { getAuthHeader, handle } = require('../middleware/apiGatewayHelper');
const applicationContext = require('../applicationContext');

/**
* GET WorkItems API Lambda
*
* @param event
* @param context
* @param callback
*/

exports.get = event =>
handle(() => {
const userId = getAuthHeader(event);
return applicationContext.getUseCases().getWorkItems({ userId: userId, applicationContext});
});
19 changes: 19 additions & 0 deletions efcms-service/src/workitems/updateWorkItemLambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { handle, getAuthHeader } = require('../middleware/apiGatewayHelper');
const applicationContext = require('../applicationContext');

/**
* updateCase
*
* @param event
* @returns {Promise<*|undefined>}
*/
exports.put = event =>
handle(() => {
const userId = getAuthHeader(event);
return applicationContext.getUseCases().updateWorkItem({
workItemId: event.pathParameters.workItemId,
workItemToUpdate: JSON.parse(event.body),
userId,
applicationContext,
});
});
13 changes: 12 additions & 1 deletion shared/src/authorization/authorizationClientService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
exports.GET_CASES_BY_STATUS = 'getCasesByStatus';
exports.UPDATE_CASE = 'updateCase';
exports.GET_CASE = 'getCase';
exports.WORKITEM = 'workItem';

/**
* isAuthorized
Expand All @@ -15,11 +16,21 @@ exports.isAuthorized = (user, action, owner) => {
if (user && user === owner) {
return true;
}
if (action === exports.WORKITEM) {
return (
user === 'petitionsclerk' ||
user === 'intakeclerk' ||
user === 'srattorney' ||
user === 'docketclerk'
);
}

return (
(user === 'respondent' ||
user === 'petitionsclerk' ||
user === 'intakeclerk') &&
user === 'intakeclerk' ||
user === 'srattorney' ||
user === 'docketclerk') &&
(action === exports.GET_CASES_BY_STATUS ||
action === exports.UPDATE_CASE ||
action === exports.GET_CASE)
Expand Down
13 changes: 13 additions & 0 deletions shared/src/authorization/authorizationClientService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const expect = require('chai').expect;
const {
GET_CASES_BY_STATUS,
GET_CASE,
WORKITEM,
isAuthorized,
} = require('./authorizationClientService');
const chai = require('chai');
Expand All @@ -27,4 +28,16 @@ describe('Authorization client service', () => {
it('should return false when a user doesnt have a petitionsclerk role', () => {
expect(isAuthorized('notapetitionsclerk', GET_CASES_BY_STATUS)).to.be.false;
});

it('should authorize a petitions clerk for workitems', () => {
expect(isAuthorized('petitionsclerk', WORKITEM)).to.be.true;
});

it('should authorize a docket clerk for workitems', () => {
expect(isAuthorized('docketclerk', WORKITEM)).to.be.true;
});

it('should authorize a srattorney for workitems', () => {
expect(isAuthorized('srattorney', WORKITEM)).to.be.true;
});
});
39 changes: 39 additions & 0 deletions shared/src/business/useCases/workitems/getWorkItem.interactor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// const {
// isAuthorized,
// WORKITEM,
// } = require('../../authorization/authorizationClientService');
// const { NotFoundError, UnauthorizedError } = require('../../errors/errors');
// const WorkItem = require('../entities/WorkItem');

/**
* getWorkItem
*
* @param userId
* @param workItemId
* @param applicationContext
* @returns {Promise<*>}
*/
exports.getWorkItem = async ({ userId, workItemId, applicationContext }) => {
// const workItem = await applicationContext
// .getPersistenceGateway()
// .getWorkItemById({
// workItemId,
// applicationContext,
// });
//
// if (!workItem) {
// throw new NotFoundError(`WorkItem ${workItemId} was not found.`);
// }
//

//
// return new WorkItem(workItem).validate().toJSON();
//MOCK REMOVE WHEN IMPLEMENTED
let ctx = applicationContext;
return {
workItemId: workItemId,
assigneeId: userId,
docketNumber: '101-18',
ctx: ctx.getUseCases().getWorkItem !== undefined,
};
};
Loading

0 comments on commit d6435e2

Please sign in to comment.