Skip to content

Commit

Permalink
Merge pull request #102 from adhocteam/sj-activity-report
Browse files Browse the repository at this point in the history
Save an Activity Report
  • Loading branch information
jasalisbury authored Jan 15, 2021
2 parents d110b59 + ef0cfba commit 270b8b2
Show file tree
Hide file tree
Showing 25 changed files with 1,089 additions and 62 deletions.
89 changes: 80 additions & 9 deletions docs/openapi/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,93 @@ paths:
$ref: "./paths/index.yaml"
components:
schemas:
activityReport:
type: object
properties:
id:
type: number
userId:
type: number
lastUpdatedById:
type: number
resourcesUsed:
type: string
additionalNotes:
type: string
numberOfParticipants:
type: number
deliveryMethod:
type: string
duration:
type: number
endDate:
type: string
startDate:
type: string
participantType:
type: string
requester:
type: string
programTypes:
type: array
items:
type: string
targetPopulations:
type: array
items:
type: string
reason:
type: array
items:
type: string
participants:
type: array
items:
type: string
topics:
type: array
items:
type: string
pageState:
type: object
properties:
1:
type: string
2:
type: string
3:
type: string
4:
type: string
status:
type: string
ttaType:
type: array
items:
type: string
approvingUser:
type: object
properties:
id:
type: number
name:
type: string
participant:
type: object
properties:
participantId:
type: number
name:
type: string
permission:
type: object
properties:
userId:
type: number
scopeId:
type: number
regionId:
type: number
user:
type: object
properties:
Expand All @@ -44,12 +124,3 @@ components:
type: array
items:
$ref: '#/components/schemas/permission'
permission:
type: object
properties:
userId:
type: number
scopeId:
type: number
regionId:
type: number
41 changes: 41 additions & 0 deletions docs/openapi/paths/activity-reports/activity-reports-id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
get:
tags:
- activity-reports
summary: Retrieve an activity report
parameters:
- in: path
name: activityReportId
required: true
schema:
type: number
responses:
200:
description: The activity report with an Id of {activityReportId}
content:
application/json:
schema:
$ref: '../../index.yaml#/components/schemas/activityReport'
put:
tags:
- activity-reports
summary: Update an activity report
requestBody:
description: A new activity report
required: true
content:
application/json:
schema:
$ref: '../../index.yaml#/components/schemas/activityReport'
parameters:
- in: path
name: activityReportId
required: true
schema:
type: number
responses:
200:
description: The updated activity report
content:
application/json:
schema:
$ref: '../../index.yaml#/components/schemas/activityReport'
18 changes: 18 additions & 0 deletions docs/openapi/paths/activity-reports/activity-reports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
post:
tags:
- activity-reports
summary: Create a new activity report
requestBody:
description: A new activity report
required: true
content:
application/json:
schema:
$ref: '../../index.yaml#/components/schemas/activityReport'
responses:
200:
description: Successfully created activity report
content:
application/json:
schema:
$ref: '../../index.yaml#/components/schemas/activityReport'
23 changes: 23 additions & 0 deletions docs/openapi/paths/activity-reports/participants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
get:
tags:
- activity-reports
summary: >
Get possible participants for an activity report
description: >
A participant is either a grant or nonGrantee.
responses:
200:
description: The possible participants
content:
application/json:
schema:
type: object
properties:
grants:
type: array
items:
$ref: '../../index.yaml#/components/schemas/participant'
nonGrantees:
type: array
items:
$ref: '../../index.yaml#/components/schemas/participant'
8 changes: 7 additions & 1 deletion docs/openapi/paths/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
$ref: './admin.yaml'
'/admin/users':
$ref: './adminAllUsers.yaml'
'/activity-reports':
$ref: './activity-reports/activity-reports.yaml'
'/activity-reports/approvers':
$ref: './activity-reports/approvers.yaml'
$ref: './activity-reports/approvers.yaml'
'/activity-reports/participants':
$ref: './activity-reports/participants.yaml'
'/activity-reports/{activityReportId}':
$ref: './activity-reports/activity-reports-id.yaml'
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"server:debug": "nodemon src/index.js --exec babel-node --inspect",
"client": "yarn --cwd frontend start",
"test": "jest src",
"test:ci": "cross-env JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=unit.xml POSTGRES_USERNAME=postgres POSTGRES_DB=ttasmarthub CURRENT_USER_ID=5 CI=true jest src tools --coverage --reporters=default --reporters=jest-junit",
"test:ci": "cross-env JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=unit.xml POSTGRES_USERNAME=postgres POSTGRES_DB=ttasmarthub CURRENT_USER_ID=5 CI=true jest src tools --runInBand --coverage --reporters=default --reporters=jest-junit",
"test:all": "yarn test:ci && yarn --cwd frontend test:ci",
"lint": "eslint src",
"lint:ci": "eslint -f eslint-formatter-multiple src",
Expand Down Expand Up @@ -148,6 +148,7 @@
"http-codes": "^1.0.0",
"lodash": "^4.17.20",
"memorystore": "^1.6.2",
"moment": "^2.29.1",
"mz": "^2.7.0",
"newrelic": "^7.0.1",
"pg": "^8.3.3",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/apiErrorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function handleSequelizeError(req, res, error, logContext) {
responseBody: { ...error, errorStack: error.stack },
responseCode: INTERNAL_SERVER_ERROR,
});
logger.error(`${logContext.namespace} id: ${requestErrorId} Sequelize error`);
logger.error(`${logContext.namespace} id: ${requestErrorId} Sequelize error ${error.stack}`);
} catch (err) {
logger.error(`${logContext.namespace} - Sequelize error - unable to save to db - ${error}`);
}
Expand All @@ -35,7 +35,7 @@ export const handleError = async (req, res, error, logContext) => {
if (error instanceof Sequelize.Error) {
await handleSequelizeError(req, res, error, logContext);
} else {
logger.error(`${logContext.namespace} - UNEXPECTED ERROR - ${error}`);
logger.error(`${logContext.namespace} - UNEXPECTED ERROR - ${error.stack}`);
res.status(INTERNAL_SERVER_ERROR).end();
}
};
Expand Down
30 changes: 30 additions & 0 deletions src/migrations/20210106152317-create-non-grantee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
queryInterface.createTable('NonGrantees', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn('NOW'),
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn('NOW'),
},
});
},

down: async (queryInterface) => {
queryInterface.dropTable('NonGrantees');
},
};
114 changes: 114 additions & 0 deletions src/migrations/20210106160931-create-activity-reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
queryInterface.createTable('ActivityReports', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
resourcesUsed: {
allowNull: true,
type: Sequelize.STRING,
},
additionalNotes: {
allowNull: true,
type: Sequelize.STRING,
},
numberOfParticipants: {
allowNull: true,
type: Sequelize.INTEGER,
},
deliveryMethod: {
allowNull: true,
type: Sequelize.STRING,
},
duration: {
allowNull: true,
type: Sequelize.DECIMAL(3, 1),
},
endDate: {
allowNull: true,
type: Sequelize.DATEONLY,
},
startDate: {
allowNull: true,
type: Sequelize.DATEONLY,
},
participantType: {
allowNull: true,
type: Sequelize.STRING,
},
requester: {
allowNull: true,
type: Sequelize.STRING,
},
status: {
allowNull: false,
type: Sequelize.STRING,
},
programTypes: {
allowNull: true,
type: Sequelize.ARRAY(Sequelize.STRING),
},
targetPopulations: {
allowNull: true,
type: Sequelize.ARRAY(Sequelize.STRING),
},
reason: {
allowNull: true,
type: Sequelize.ARRAY(Sequelize.STRING),
},
participants: {
allowNull: true,
type: Sequelize.ARRAY(Sequelize.STRING),
},
topics: {
allowNull: true,
type: Sequelize.ARRAY(Sequelize.STRING),
},
ttaType: {
allowNull: true,
type: Sequelize.ARRAY(Sequelize.STRING),
},
pageState: {
allowNull: true,
type: Sequelize.JSON,
},
userId: {
allowNull: false,
type: Sequelize.INTEGER,
references: {
model: {
tableName: 'Users',
},
key: 'id',
},
},
lastUpdatedById: {
allowNull: false,
type: Sequelize.INTEGER,
references: {
model: {
tableName: 'Users',
},
key: 'id',
},
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn('NOW'),
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn('NOW'),
},
});
},

down: async (queryInterface) => {
queryInterface.dropTable('ActivityReports');
},
};
Loading

0 comments on commit 270b8b2

Please sign in to comment.