Skip to content

Commit

Permalink
Merge pull request #601 from techmatters/CHI-2559-full_first_contact_…
Browse files Browse the repository at this point in the history
…case

CHI-2559: Return full first contacts with cases
  • Loading branch information
stephenhand authored Mar 25, 2024
2 parents 64d9808 + 9a7b952 commit 1c1952f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
14 changes: 1 addition & 13 deletions hrm-domain/hrm-core/case/caseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,6 @@ const mapEssentialData =

const { summary, followUpDate, definitionVersion } = info;

const firstChildRawJson = connectedContacts[0]?.rawJson;
const { firstName, lastName } = firstChildRawJson?.childInformation ?? {};

const firstChildEssentialData = {
rawJson: {
childInformation: {
firstName,
lastName,
},
},
};

const infoEssentialData = {
summary,
followUpDate,
Expand All @@ -322,7 +310,7 @@ const mapEssentialData =
return {
id,
status,
connectedContacts: connectedContacts.length > 0 ? [firstChildEssentialData] : [],
connectedContacts: connectedContacts.slice(0, 1),
twilioWorkerId,
categories,
createdAt,
Expand Down
13 changes: 12 additions & 1 deletion hrm-domain/hrm-core/case/sql/caseGetSql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,23 @@ const leftJoinLateralContacts = (
userIsSupervisor,
'c',
)}
AND c."timeOfContact" = (
SELECT MIN("timeOfContact")
FROM "Contacts" c2
WHERE c2."caseId" = cases.id AND c2."accountSid" = cases."accountSid"
AND ${listContactsPermissionWhereClause(
viewPermissions as ContactListCondition[][],
userIsSupervisor,
'c2',
)}
)
) "contacts" ON true`;
}

return `
LEFT JOIN LATERAL (
SELECT COALESCE(jsonb_agg(to_jsonb(c) || to_jsonb("joinedReports") || to_jsonb("joinedReferrals") || to_jsonb("joinedConversationMedia")), '[]') AS "connectedContacts"
SELECT COALESCE(jsonb_agg(to_jsonb(c) || to_jsonb("joinedReports") || to_jsonb("joinedReferrals") || to_jsonb("joinedConversationMedia") ORDER BY c."timeOfContact"), '[]') AS "connectedContacts"
FROM "Contacts" c
LEFT JOIN LATERAL (
${selectCoalesceCsamReportsByContactId('c')}
Expand All @@ -69,6 +79,7 @@ const leftJoinLateralContacts = (
userIsSupervisor,
'c',
)}
) "contacts" ON true`;
};

Expand Down
24 changes: 24 additions & 0 deletions hrm-domain/hrm-service/src/defaultConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2021-2023 Technology Matters
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

switch (process.env.NODE_ENV) {
case 'development': {
if (!process.env.INCLUDE_ERROR_IN_RESPONSE) {
console.log('INCLUDE_ERROR_IN_RESPONSE not set, setting to true');
process.env.INCLUDE_ERROR_IN_RESPONSE = 'true';
}
}
}
14 changes: 7 additions & 7 deletions hrm-domain/hrm-service/src/www.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import express from 'express';

import './defaultConfiguration';
/**
* Module dependencies.
*/
Expand All @@ -40,7 +40,7 @@ const debug = debugFactory('hrm:server');
*/

function normalizePort(val) {
var port = parseInt(val, 10);
const port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
Expand All @@ -62,7 +62,7 @@ const appWithResourcesService = configureResourcesService({
});
const app = configureDefaultPostMiddlewares(
appWithResourcesService,
Boolean(process.env.INCLUDE_ERROR_IN_RESPONSE),
process.env.INCLUDE_ERROR_IN_RESPONSE?.toString()?.toLowerCase() === 'true',
);

const internalAppWithoutServices = configureDefaultPreMiddlewares(express());
Expand All @@ -74,7 +74,7 @@ const internalAppWithResourcesService = configureInternalResourcesService({
});
const internalApp = configureDefaultPostMiddlewares(
internalAppWithResourcesService,
Boolean(process.env.INCLUDE_ERROR_IN_RESPONSE),
process.env.INCLUDE_ERROR_IN_RESPONSE?.toString()?.toLowerCase() === 'true',
);
/**
* Create HTTP server.
Expand Down Expand Up @@ -104,7 +104,7 @@ function onError(error) {
throw error;
}

var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
Expand All @@ -126,8 +126,8 @@ function onError(error) {
*/

const onListening = listenServer => () => {
var addr = listenServer.address();
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
const addr = listenServer.address();
const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
debug('Listening on ' + bind);
console.log('Log listening on ' + bind);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/http/webServerConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const configureDefaultPostMiddlewares = (
includeErrorInResponse: boolean,
) => {
webServer.use((req, res, next) => {
next(createError(404));
next(createError(404, `No handler configured for url: ${req.url}`));
});
const errorHandler: ErrorRequestHandler = (err, req, res, next) => {
console.log(err);
Expand Down

0 comments on commit 1c1952f

Please sign in to comment.