From d64e3d3e5ca462e95ce1eafbe93d989dc5c360fe Mon Sep 17 00:00:00 2001 From: Adam Buckingham Date: Fri, 26 Jul 2024 08:12:57 -0400 Subject: [PATCH 1/2] Adding ArtLanguage DB model and post ability --- server/app.js | 83 +++++++++++++++++++++++- server/models/art_language.js | 43 ++++++++++++ server/models/index.js | 9 +++ server/routes/solicitation.routes.js | 36 ++++++++++ server/tests/solicitation.routes.test.js | 23 +++++++ 5 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 server/models/art_language.js diff --git a/server/app.js b/server/app.js index b888fec..22b2183 100644 --- a/server/app.js +++ b/server/app.js @@ -252,6 +252,7 @@ module.exports = { app.post('/api/solicitation', token(), solicitationRoutes.postSolicitation) app.get('/api/solicitation/:id', token(), solicitationRoutes.get) app.post('/api/solicitation/:id', token(), solicitationRoutes.update) + app.post('/api/solicitation/art/:id', token(), solicitationRoutes.postArtLanguage) app.post('/api/feedback', token(), solicitationRoutes.solicitationFeedback) app.get('/api/surveys', token(), surveyRoutes.getSurveyQuestions) app.get('/api/surveys/:solNum', token(), surveyRoutes.get) @@ -272,7 +273,87 @@ module.exports = { app.get('/api/reports/predictionMetrics', token(), admin_only(), adminReportRoutes.predictionReport) app.get('/api/reports/noticeTypeChangeReport', token(), admin_only(), adminReportRoutes.noticeTypeChangeReport) - + //TODO: Remove once ART integration + app.post('/art/v1/get508Languages', token(), (req, res) => { + let rspJson = [ + { + "code": "E201", + "title": "", + "text": "", + "sections": [ + { + "code": "E201.1", + "title": "E201.1 Scope", + "text": "ICT that is procured, developed, maintained, or used by agencies shall conform to the Revised 508 Standards.", + "sections": [] + } + ] + }, + { + "code": "E202", + "title": "", + "text": "", + "sections": [ + { + "code": "E202.1", + "title": "E202.1 General", + "text": "ICT shall be exempt from compliance with the Revised 508 Standards to the extent specified by E202.", + "sections": [] + }, + { + "code": "E202.2", + "title": "E202.2 Legacy ICT", + "text": "Any component or portion of existing ICT that complies with an earlier standard issued pursuant to Section 508 of the Rehabilitation Act of 1973, as amended (as republished in Appendix D), and that has not been altered on or after January 18, 2018, shall not be required to be modified to conform to the Revised 508 Standards.", + "sections": [] + }, + { + "code": "E202.3", + "title": "E202.3 National Security", + "text": "The Revised 508 Standards do not apply to ICT operated by agencies as part of a national security system, as defined by 40 U.S.C. 1103(a).", + "sections": [] + }, + { + "code": "E202.4", + "title": "E202.4 Federal Contracts", + "text": "ICT acquired by a contractor incidental to a contract shall not be required to conform to the Revised 508 Standards.", + "sections": [] + }, + { + "code": "E202.5", + "title": "E202.5 ICT Functions Located in Maintenance or Monitoring Spaces", + "text": "Where status indicators and operable parts for ICT functions are located in spaces that are frequented only by service personnel for maintenance, repair, or occasional monitoring of equipment, such status indicators and operable parts shall not be required to conform to the Revised 508 Standards.", + "sections": [] + }, + { + "code": "E202.6", + "title": "E202.6 Undue Burden or Fundamental Alteration", + "text": "Where an agency determines in accordance with E202.5 that conformance to requirements in the Revised 508 Standards would impose an undue burden or would result in a fundamental alteration in the nature of the ICT, conformance shall be required only to the extent that it does not impose an undue burden, or result in a fundamental alteration in the nature of the ICT.", + "sections": [] + }, + { + "code": "E202.7", + "title": "E202.7 Best Meets", + "text": "Where ICT conforming to one or more requirements in the Revised 508 Standards is not commercially available, the agency shall procure the ICT that best meets the Revised 508 Standards consistent with the agency’s business needs.\nRequired Documentation. The responsible agency official shall document in writing: (a) the non-availability of conforming ICT, including a description of market research performed and which provisions cannot be met, and (b) the basis for determining that the ICT to be procured best meets the requirements in the Revised 508 Standards consistent with the agency’s business needs.\nAlternative Means. Where ICT that fully conforms to the Revised 508 Standards is not commercially available, the agency shall provide individuals with disabilities access to and use of information and data by an alternative means that meets identified needs.", + "sections": [ + { + "code": "E202.7.1", + "title": "E202.7.1 Required Documentation", + "text": "The responsible agency official shall document in writing: (a) the non-availability of conforming ICT, including a description of market research performed and which provisions cannot be met, and (b) the basis for determining that the ICT to be procured best meets the requirements in the Revised 508 Standards consistent with the agency’s business needs.", + "sections": [] + }, + { + "code": "E202.7.2", + "title": "E202.7.2 Alternative Means", + "text": "Where ICT that fully conforms to the Revised 508 Standards is not commercially available, the agency shall provide individuals with disabilities access to and use of information and data by an alternative means that meets identified needs.", + "sections": [] + } + ] + } + ] + }, + ] + return res.status(200).send(rspJson) + }); app.use(expressWinston.errorLogger({ diff --git a/server/models/art_language.js b/server/models/art_language.js new file mode 100644 index 0000000..580ef60 --- /dev/null +++ b/server/models/art_language.js @@ -0,0 +1,43 @@ + +module.exports = (sequelize, DataTypes) => { + const ArtLanguage = sequelize.define('ArtLanguage', + { + id: { + type: DataTypes.INTEGER, + allowNull: false, + primaryKey: true, + autoIncrement:true + }, + solicitation_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: 'Solicitation', // Name of the referenced table + key: 'id', // Key in the referenced table + } + }, + + language: { + type: DataTypes.JSONB, + allowNull: false + }, + createdAt: { type: DataTypes.DATE, allowNull: false }, + updatedAt: { type: DataTypes.DATE }, + },{ + tableName: 'art_language', + timestamps: true + } + ) + + ArtLanguage.associate = function(models) { + // associations can be defined here + ArtLanguage.belongsTo(models.Solicitation, { + foreignKey: 'solicitation_id', + targetKey: 'id', + as: 'solicitation' + }) + + } + + return ArtLanguage; +}; \ No newline at end of file diff --git a/server/models/index.js b/server/models/index.js index 3d26231..b20053f 100644 --- a/server/models/index.js +++ b/server/models/index.js @@ -108,6 +108,15 @@ * */ +/** + * @type {Model} ArtLanguage + * @property {number} id: DataTypes.INTEGER, + * @property {number} solicitation_id: DataTypes.INTEGER, + * @property {Object} language: DataTypes.JSONB, + * @property {date} createdAt: DataTypes.DATE, + * @property {date} updatedAt: DataTypes.DATE + */ + const fs = require('fs') const path = require('path') const {Sequelize, Model} = require('sequelize') diff --git a/server/routes/solicitation.routes.js b/server/routes/solicitation.routes.js index 23ca975..8c1995c 100644 --- a/server/routes/solicitation.routes.js +++ b/server/routes/solicitation.routes.js @@ -4,6 +4,7 @@ const logger = require('../config/winston') // noinspection JSUnresolvedVariable const Notice = require('../models').notice const Solicitation = require('../models').Solicitation +const ArtLanguage = require('../models').ArtLanguage const predictionRoute = require('../routes/prediction.routes') const authRoutes = require('../routes/auth.routes') const surveyRoutes = require('../routes/survey.routes') @@ -308,7 +309,42 @@ module.exports = function (db, userRoutes) { // logger.log('error', 'error in: solicitationFeedback', { error:e, tag: 'solicitationFeedback' }) // res.status(400).send(e) // }) + }, + + postArtLanguage: async (req, res) => { + const solicitationId = req.params.id; // Assuming solicitation ID is passed as a URL parameter + const artLanguageData = req.body; // Assuming the new ArtLanguage data is in the request body + + let art_db_form = { + solicitation_id: solicitationId, + language: artLanguageData, + } + + try { + // Optionally, validate solicitationId and artLanguageData here + + // Find or create ArtLanguage record + console.log('art_db_form:', art_db_form); + + let artLanguage = await ArtLanguage.findOne({ where: { solicitation_id: solicitationId } }); + + if (artLanguage) { + // If exists, update the record + await artLanguage.update(art_db_form); + } else { + // If doesn't exist, create a new record with solicitation ID + artLanguage = await ArtLanguage.create(art_db_form); + } + // Send success response + res.json({ + message: 'ArtLanguage updated successfully', + artLanguage + }); + } catch (error) { + console.error('Error updating ArtLanguage:', error); + res.status(500).json({ message: 'Failed to update ArtLanguage' }); } + }, } } diff --git a/server/tests/solicitation.routes.test.js b/server/tests/solicitation.routes.test.js index 0253aef..752f32d 100644 --- a/server/tests/solicitation.routes.test.js +++ b/server/tests/solicitation.routes.test.js @@ -368,5 +368,28 @@ describe('solicitation tests', () => { }) + test('creates a new ArtLanguage if not exists', async () => { + const req = { + params: { solicitationId: '1' }, + body: { language: 'English', proficiency: 'Native' }, + }; + const res = { + json: jest.fn(), + status: jest.fn().mockReturnThis(), + }; + ArtLanguage.findOne.mockResolvedValue(null); + ArtLanguage.create.mockResolvedValue({ id: '1', ...req.body }); + + await putArtLanguage(req, res); + + expect(ArtLanguage.create).toHaveBeenCalledWith({ + solicitation_id: '1', + language: 'English', + proficiency: 'Native', + }); + expect(res.json).toHaveBeenCalledWith(expect.objectContaining({ + message: 'ArtLanguage updated successfully', + })); + }); }) // end describe From da3bc78152ecffaec7af590181a641a39735f93f Mon Sep 17 00:00:00 2001 From: Adam Buckingham <48027257+BuckinghamAJ@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:47:41 -0400 Subject: [PATCH 2/2] Remove testing art placehold json --- server/app.js | 83 --------------------------------------------------- 1 file changed, 83 deletions(-) diff --git a/server/app.js b/server/app.js index 22b2183..01184db 100644 --- a/server/app.js +++ b/server/app.js @@ -273,89 +273,6 @@ module.exports = { app.get('/api/reports/predictionMetrics', token(), admin_only(), adminReportRoutes.predictionReport) app.get('/api/reports/noticeTypeChangeReport', token(), admin_only(), adminReportRoutes.noticeTypeChangeReport) - //TODO: Remove once ART integration - app.post('/art/v1/get508Languages', token(), (req, res) => { - let rspJson = [ - { - "code": "E201", - "title": "", - "text": "", - "sections": [ - { - "code": "E201.1", - "title": "E201.1 Scope", - "text": "ICT that is procured, developed, maintained, or used by agencies shall conform to the Revised 508 Standards.", - "sections": [] - } - ] - }, - { - "code": "E202", - "title": "", - "text": "", - "sections": [ - { - "code": "E202.1", - "title": "E202.1 General", - "text": "ICT shall be exempt from compliance with the Revised 508 Standards to the extent specified by E202.", - "sections": [] - }, - { - "code": "E202.2", - "title": "E202.2 Legacy ICT", - "text": "Any component or portion of existing ICT that complies with an earlier standard issued pursuant to Section 508 of the Rehabilitation Act of 1973, as amended (as republished in Appendix D), and that has not been altered on or after January 18, 2018, shall not be required to be modified to conform to the Revised 508 Standards.", - "sections": [] - }, - { - "code": "E202.3", - "title": "E202.3 National Security", - "text": "The Revised 508 Standards do not apply to ICT operated by agencies as part of a national security system, as defined by 40 U.S.C. 1103(a).", - "sections": [] - }, - { - "code": "E202.4", - "title": "E202.4 Federal Contracts", - "text": "ICT acquired by a contractor incidental to a contract shall not be required to conform to the Revised 508 Standards.", - "sections": [] - }, - { - "code": "E202.5", - "title": "E202.5 ICT Functions Located in Maintenance or Monitoring Spaces", - "text": "Where status indicators and operable parts for ICT functions are located in spaces that are frequented only by service personnel for maintenance, repair, or occasional monitoring of equipment, such status indicators and operable parts shall not be required to conform to the Revised 508 Standards.", - "sections": [] - }, - { - "code": "E202.6", - "title": "E202.6 Undue Burden or Fundamental Alteration", - "text": "Where an agency determines in accordance with E202.5 that conformance to requirements in the Revised 508 Standards would impose an undue burden or would result in a fundamental alteration in the nature of the ICT, conformance shall be required only to the extent that it does not impose an undue burden, or result in a fundamental alteration in the nature of the ICT.", - "sections": [] - }, - { - "code": "E202.7", - "title": "E202.7 Best Meets", - "text": "Where ICT conforming to one or more requirements in the Revised 508 Standards is not commercially available, the agency shall procure the ICT that best meets the Revised 508 Standards consistent with the agency’s business needs.\nRequired Documentation. The responsible agency official shall document in writing: (a) the non-availability of conforming ICT, including a description of market research performed and which provisions cannot be met, and (b) the basis for determining that the ICT to be procured best meets the requirements in the Revised 508 Standards consistent with the agency’s business needs.\nAlternative Means. Where ICT that fully conforms to the Revised 508 Standards is not commercially available, the agency shall provide individuals with disabilities access to and use of information and data by an alternative means that meets identified needs.", - "sections": [ - { - "code": "E202.7.1", - "title": "E202.7.1 Required Documentation", - "text": "The responsible agency official shall document in writing: (a) the non-availability of conforming ICT, including a description of market research performed and which provisions cannot be met, and (b) the basis for determining that the ICT to be procured best meets the requirements in the Revised 508 Standards consistent with the agency’s business needs.", - "sections": [] - }, - { - "code": "E202.7.2", - "title": "E202.7.2 Alternative Means", - "text": "Where ICT that fully conforms to the Revised 508 Standards is not commercially available, the agency shall provide individuals with disabilities access to and use of information and data by an alternative means that meets identified needs.", - "sections": [] - } - ] - } - ] - }, - ] - return res.status(200).send(rspJson) - }); - - app.use(expressWinston.errorLogger({ transports: transports, format: winston.format.combine(