Skip to content

Commit

Permalink
fix 2nd approver flow
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Apr 2, 2024
1 parent 8354022 commit 3ce1f70
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
6 changes: 5 additions & 1 deletion media_commons_booking_app/src/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export const OLD_SAFETY_TRAINING_SHEET_NAME = 'Sheet1';

/********** CONTACTS ************/

export const SECOND_APPROVER_EMAIL = '[email protected]';
// TODO configure this via admin UI
export const getSecondApproverEmail = (branchName: string) =>
branchName === 'development'
? '[email protected]'
: '[email protected]'; // Jhanele

/********** ROOMS ************/

Expand Down
49 changes: 23 additions & 26 deletions media_commons_booking_app/src/server/admin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ActiveSheetBookingStatusColumns,
SECOND_APPROVER_EMAIL,
TableNames,
getSecondApproverEmail,
} from '../policy';
import { approvalUrl, rejectUrl } from './ui';
import {
Expand All @@ -22,58 +22,55 @@ export const bookingContents = (id: string) => {
return bookingObj;
};

export const approveInstantBooking = (id: string) => {
const firstApprove = (id: string) =>
updateActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.FIRST_APPROVED_DATE,
new Date()
);

const secondApprove = (id: string) =>
updateActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.SECOND_APPROVED_DATE,
new Date()
);

export const approveInstantBooking = (id: string) => {
firstApprove(id);
approveEvent(id);
};

// both first approve and second approve flows hit here
export const approveBooking = (id: string) => {
const firstApproveDateRange = updateActiveSheetValueById(
const firstApproveDateRange = getActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.FIRST_APPROVED_DATE,
new Date()
ActiveSheetBookingStatusColumns.FIRST_APPROVED_DATE
);
console.log('first approve date', firstApproveDateRange.getValue());

//COMPLETE ALL APPROVAL
if (firstApproveDateRange.getValue() !== '') {
// second approve
console.log('first approve date', firstApproveDateRange);

// if already first approved, then this is a second approve
if (firstApproveDateRange !== '') {
secondApprove(id);
approveEvent(id);
} else {
// TODO fix logic here? why are we trying to do this twice?
// first approve
updateActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.FIRST_APPROVED_DATE,
new Date()
);
firstApprove(id);

//TODO: send email to user
updateEventPrefix(id, 'PRE-APPROVED');

const subject = 'Second Approval Request';
const contents = bookingContents(id);
const recipient = SECOND_APPROVER_EMAIL;
const recipient = getSecondApproverEmail(process.env.BRANCH_NAME);
sendHTMLEmail('approval_email', contents, recipient, subject, '');
}
};

export const approveEvent = (id: string) => {
// add 2nd approval timestamp
updateActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
ActiveSheetBookingStatusColumns.SECOND_APPROVED_DATE,
new Date()
);

const guestEmail = getActiveSheetValueById(
TableNames.BOOKING_STATUS,
id,
Expand Down
3 changes: 3 additions & 0 deletions media_commons_booking_app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ const serverConfig = {
// removes need for assigning public server functions to "global"
autoGlobalExportsFiles: [serverEntry],
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(envVars),
}),
],
};

Expand Down

1 comment on commit 3ce1f70

@lucia-gomez
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.