Skip to content

Commit

Permalink
Merge pull request #506 from masslight/fix-cancel-appointment
Browse files Browse the repository at this point in the history
Fix cancel appointment
  • Loading branch information
GiladSchneider authored Oct 22, 2024
2 parents 13a239e + 1dbc663 commit 7a3cba5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getPatientResource } from '../../shared';
import { DATETIME_FULL_NO_YEAR } from 'ottehr-utils';
import { DateTime } from 'luxon';
import { sendCancellationEmail } from '../../shared';
import { getAccessToken } from 'ottehr-utils';
import { getAuth0Token } from 'ottehr-utils';
// import { sendMessage } from '../../shared';
// import { getConversationSIDForRelatedPersons } from '../create-appointment';
import { getRelatedPersonForPatient } from '../../shared';
Expand Down Expand Up @@ -87,7 +87,7 @@ export const index = async (input: ZambdaInput): Promise<APIGatewayProxyResult>

if (!zapehrToken) {
console.log('getting token');
zapehrToken = await getAccessToken(secrets);
zapehrToken = await getAccessToken(secrets, 'regular');
} else {
console.log('already have token');
}
Expand Down Expand Up @@ -289,3 +289,21 @@ const getCancellationEmailDetails = async (
throw new Error(`error getting cancellation email details: ${error}, ${JSON.stringify(error)}`);
}
};

export type AuthType = 'regular' | 'messaging';

export async function getAccessToken(secrets: Secrets | null, type: AuthType = 'regular'): Promise<string> {
let clientIdKey: SecretsKeys.TELEMED_CLIENT_ID | SecretsKeys.MESSAGING_M2M_CLIENT;
let secretIdKey: SecretsKeys.TELEMED_CLIENT_SECRET | SecretsKeys.MESSAGING_M2M_SECRET;
if (type === 'regular') {
clientIdKey = SecretsKeys.TELEMED_CLIENT_ID;
secretIdKey = SecretsKeys.TELEMED_CLIENT_SECRET;
} else if (type === 'messaging') {
clientIdKey = SecretsKeys.MESSAGING_M2M_CLIENT;
secretIdKey = SecretsKeys.MESSAGING_M2M_SECRET;
} else {
console.log('unknown m2m token type');
throw Error('unknown m2m token type');
}
return getAuth0Token({ secretIdKey, clientIdKey, secrets });
}
20 changes: 0 additions & 20 deletions packages/utils/lib/auth/getAccessToken.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/utils/lib/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './getAuth0Token';
export * from './getAccessToken';
export * from './getAuth0Token';
4 changes: 3 additions & 1 deletion packages/utils/lib/secrets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export enum SecretsKeys {
URGENT_CARE_ONLINE_VISIT_TYPE = 'URGENT_CARE_ONLINE_VISIT_TYPE',
URGENT_CARE_TESTING_VISIT_TYPE = 'URGENT_CARE_TESTING_VISIT_TYPE',
URGENT_CARE_MESSAGING_DEVICE_ID = 'URGENT_CARE_MESSAGING_DEVICE_ID',
URGENT_CARE_MESSAGING_M2M_CLIENT = 'URGENT_CARE_MESSAGING_M2M_CLIENT',
MESSAGING_M2M_CLIENT = 'MESSAGING_M2M_CLIENT',
MESSAGING_M2M_SECRET = 'MESSAGING_M2M_SECRET',
URGENT_CARE_MESSAGING_M2M_CLIENT= 'URGENT_CARE_MESSAGING_M2M_CLIENT',
URGENT_CARE_MESSAGING_M2M_SECRET = 'URGENT_CARE_MESSAGING_M2M_SECRET',
ORGANIZATION_ID = 'ORGANIZATION_ID',
WEBSITE_URL = 'WEBSITE_URL',
Expand Down

0 comments on commit 7a3cba5

Please sign in to comment.