Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Standardize phone number identifiers [CHI-2623] (#613) #617

Open
wants to merge 1 commit into
base: v1.15-rc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions hrm-domain/hrm-core/profile/profileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ import { ITask } from 'pg-promise';
export {
Identifier,
Profile,
getIdentifierWithProfiles,
ProfileListConfiguration,
SearchParameters,
} from './profileDataAccess';

const sanitizeIdentifier = (i: string) => i.replace(' ', '');

export const getProfile =
(task?) =>
async (
Expand All @@ -57,15 +58,18 @@ export const createIdentifierAndProfile =
(task?) =>
async (
accountSid: string,
payload: { identifier: NewIdentifierRecord; profile: NewProfileRecord },
payload: {
identifier: NewIdentifierRecord;
profile: NewProfileRecord;
},
{ user }: { user: TwilioUser },
): Promise<Result<DatabaseErrorResult, profileDB.IdentifierWithProfiles>> => {
const { identifier, profile } = payload;

return txIfNotInOne(task, async t => {
try {
const newIdentifier = await profileDB.createIdentifier(t)(accountSid, {
identifier: identifier.identifier,
identifier: sanitizeIdentifier(identifier.identifier),
createdBy: user.workerSid,
});
const newProfile = await profileDB.createProfile(t)(accountSid, {
Expand Down Expand Up @@ -112,7 +116,7 @@ export const getOrCreateProfileWithIdentifier =

const profileResult = await profileDB.getIdentifierWithProfiles(task)({
accountSid,
identifier: identifier.identifier,
identifier: sanitizeIdentifier(identifier.identifier),
});

if (profileResult) {
Expand Down Expand Up @@ -181,7 +185,7 @@ export const getIdentifierByIdentifier = async (
): Promise<profileDB.IdentifierWithProfiles> =>
profileDB.getIdentifierWithProfiles()({
accountSid,
identifier,
identifier: sanitizeIdentifier(identifier),
});

export const listProfiles = profileDB.listProfiles;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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/.
*/
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async queryInterface => {
await queryInterface.sequelize.query(`
DO $$
DECLARE idx public."Identifiers";
BEGIN
-- For each identifier in Identifier with spaces
FOR idx IN (SELECT * FROM "Identifiers" WHERE "identifier" LIKE '% %') LOOP
-- Remove any blank spaces that the identifiers might have
UPDATE "Identifiers" SET "identifier" = replace(idx."identifier", ' ', '') WHERE id = idx.id;
END LOOP;
END$$
`);
console.log('Sequence "Profiles_id_seq" created');
},

down: async () => {},
};
Loading