Skip to content

Commit 422dd63

Browse files
committed
fix: ts build errors and remove unused code
1 parent 3ecbbe9 commit 422dd63

File tree

12 files changed

+13
-1446
lines changed

12 files changed

+13
-1446
lines changed

src/app/modules/form/admin-form/admin-form.controller.ts

Lines changed: 2 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
ErrorDto,
2323
FieldCreateDto,
2424
FieldUpdateDto,
25-
FormAuthType,
2625
FormColorTheme,
2726
FormDto,
2827
FormFeedbackMetaDto,
@@ -54,15 +53,10 @@ import {
5453
encryptStringsMessage,
5554
} from '../../../../../shared/utils/crypto'
5655
import { IFormDocument, IPopulatedForm } from '../../../../types'
57-
import {
58-
EncryptSubmissionDto,
59-
FormUpdateParams,
60-
ParsedEmailModeSubmissionBody,
61-
} from '../../../../types/api'
56+
import { EncryptSubmissionDto, FormUpdateParams } from '../../../../types/api'
6257
import { goGovConfig } from '../../../config/features/gogov.config'
6358
import { smsConfig } from '../../../config/features/sms.config'
6459
import { createLoggerWithLabel } from '../../../config/logger'
65-
import MailService from '../../../services/mail/mail.service'
6660
import * as SmsService from '../../../services/sms/sms.service'
6761
import { createReqMeta } from '../../../utils/request'
6862
import * as AuthService from '../../auth/auth.service'
@@ -74,32 +68,16 @@ import {
7468
} from '../../core/core.errors'
7569
import { ControllerHandler } from '../../core/core.types'
7670
import * as FeedbackService from '../../feedback/feedback.service'
77-
import * as EmailSubmissionMiddleware from '../../submission/email-submission/email-submission.middleware'
7871
import * as EmailSubmissionService from '../../submission/email-submission/email-submission.service'
79-
import {
80-
mapRouteError as mapEmailSubmissionError,
81-
SubmissionEmailObj,
82-
} from '../../submission/email-submission/email-submission.util'
8372
import * as EncryptSubmissionService from '../../submission/encrypt-submission/encrypt-submission.service'
84-
import ParsedResponsesObject from '../../submission/ParsedResponsesObject.class'
85-
import * as ReceiverMiddleware from '../../submission/receiver/receiver.middleware'
8673
import * as SubmissionService from '../../submission/submission.service'
87-
import {
88-
extractEmailConfirmationData,
89-
mapAttachmentsFromResponses,
90-
mapRouteError as mapSubmissionError,
91-
} from '../../submission/submission.utils'
74+
import { mapRouteError as mapSubmissionError } from '../../submission/submission.utils'
9275
import * as UserService from '../../user/user.service'
9376
import { removeFormsFromAllWorkspaces } from '../../workspace/workspace.service'
9477
import { PrivateFormError } from '../form.errors'
9578
import * as FormService from '../form.service'
9679
import { getSubmissionType } from '../form.utils'
9780

98-
import {
99-
PREVIEW_CORPPASS_UID,
100-
PREVIEW_CORPPASS_UINFIN,
101-
PREVIEW_SINGPASS_UINFIN,
102-
} from './admin-form.constants'
10381
import { EditFieldError, GoGovServerError } from './admin-form.errors'
10482
import {
10583
createWorkflowStepValidator,
@@ -2106,158 +2084,6 @@ export const handleEncryptPreviewSubmission = [
21062084
submitEncryptPreview,
21072085
] as ControllerHandler[]
21082086

2109-
/**
2110-
* Handler for POST /v2/submissions/email/preview/:formId.
2111-
* @security session
2112-
*
2113-
* @returns 200 with a mock submission ID
2114-
* @returns 400 when body is malformed; e.g. invalid responses, or when admin email fails to be sent
2115-
* @returns 403 when current user does not have read permissions to given form
2116-
* @returns 404 when given form ID does not exist
2117-
* @returns 410 when given form has been deleted
2118-
* @returns 422 when user ID in session is not found in database
2119-
* @returns 500 when database error occurs
2120-
*/
2121-
export const submitEmailPreview: ControllerHandler<
2122-
{ formId: string },
2123-
{ message: string; submissionId?: string },
2124-
ParsedEmailModeSubmissionBody,
2125-
{ captchaResponse?: unknown }
2126-
> = async (req, res) => {
2127-
const { formId } = req.params
2128-
const sessionUserId = (req.session as AuthedSessionData).user._id
2129-
// No need to process attachments as we don't do anything with them
2130-
const { responses } = req.body
2131-
const logMeta = {
2132-
action: 'submitEmailPreview',
2133-
formId,
2134-
...createReqMeta(req),
2135-
}
2136-
2137-
const formResult = await UserService.getPopulatedUserById(sessionUserId)
2138-
.andThen((user) =>
2139-
AuthService.getFormAfterPermissionChecks({
2140-
user,
2141-
formId,
2142-
level: PermissionLevel.Read,
2143-
}),
2144-
)
2145-
.andThen(EmailSubmissionService.checkFormIsEmailMode)
2146-
if (formResult.isErr()) {
2147-
logger.error({
2148-
message: 'Error while retrieving form for preview submission',
2149-
meta: logMeta,
2150-
error: formResult.error,
2151-
})
2152-
const { errorMessage, statusCode } = mapEmailSubmissionError(
2153-
formResult.error,
2154-
)
2155-
return res.status(statusCode).json({ message: errorMessage })
2156-
}
2157-
const form = formResult.value
2158-
2159-
const parsedResponsesResult = await SubmissionService.validateAttachments(
2160-
responses,
2161-
form.responseMode,
2162-
).andThen(() => ParsedResponsesObject.parseResponses(form, responses))
2163-
if (parsedResponsesResult.isErr()) {
2164-
logger.error({
2165-
message: 'Error while parsing responses for preview submission',
2166-
meta: logMeta,
2167-
error: parsedResponsesResult.error,
2168-
})
2169-
const { errorMessage, statusCode } = mapEmailSubmissionError(
2170-
parsedResponsesResult.error,
2171-
)
2172-
return res.status(statusCode).json({ message: errorMessage })
2173-
}
2174-
const parsedResponses = parsedResponsesResult.value
2175-
const attachments = mapAttachmentsFromResponses(req.body.responses)
2176-
2177-
// Handle SingPass, CorpPass and MyInfo authentication and validation
2178-
const { authType } = form
2179-
if (authType === FormAuthType.SP || authType === FormAuthType.MyInfo) {
2180-
parsedResponses.addNdiResponses({
2181-
authType,
2182-
uinFin: PREVIEW_SINGPASS_UINFIN,
2183-
})
2184-
} else if (authType === FormAuthType.CP) {
2185-
parsedResponses.addNdiResponses({
2186-
authType,
2187-
uinFin: PREVIEW_CORPPASS_UINFIN,
2188-
userInfo: PREVIEW_CORPPASS_UID,
2189-
})
2190-
}
2191-
2192-
const emailData = new SubmissionEmailObj(
2193-
parsedResponses.getAllResponses(),
2194-
// All MyInfo fields are verified in preview
2195-
new Set(AdminFormService.extractMyInfoFieldIds(form.form_fields)),
2196-
form.authType,
2197-
)
2198-
const submission = EmailSubmissionService.createEmailSubmissionWithoutSave(
2199-
form,
2200-
// Don't need to care about response hash or salt
2201-
'',
2202-
'',
2203-
)
2204-
2205-
const sendAdminEmailResult = await MailService.sendSubmissionToAdmin({
2206-
replyToEmails: EmailSubmissionService.extractEmailAnswers(
2207-
parsedResponses.getAllResponses(),
2208-
),
2209-
form,
2210-
submission,
2211-
attachments,
2212-
dataCollationData: emailData.dataCollationData,
2213-
formData: emailData.formData,
2214-
})
2215-
if (sendAdminEmailResult.isErr()) {
2216-
logger.error({
2217-
message: 'Error sending submission to admin',
2218-
meta: logMeta,
2219-
error: sendAdminEmailResult.error,
2220-
})
2221-
const { statusCode, errorMessage } = mapEmailSubmissionError(
2222-
sendAdminEmailResult.error,
2223-
)
2224-
return res.status(statusCode).json({
2225-
message: errorMessage,
2226-
})
2227-
}
2228-
2229-
// Don't await on email confirmations, so submission is successful even if
2230-
// this fails
2231-
void SubmissionService.sendEmailConfirmations({
2232-
form,
2233-
submission,
2234-
attachments,
2235-
responsesData: emailData.autoReplyData,
2236-
recipientData: extractEmailConfirmationData(
2237-
parsedResponses.getAllResponses(),
2238-
form.form_fields,
2239-
),
2240-
isUseLambdaOutput: false, // TODO: [PDF-LAMBDA-GENERATION]: To remove once pdf lambda rollout is complete. Currently set to false since v2 api is not being used.
2241-
}).mapErr((error) => {
2242-
logger.error({
2243-
message: 'Error while sending email confirmations',
2244-
meta: logMeta,
2245-
error,
2246-
})
2247-
})
2248-
2249-
return res.json({
2250-
message: 'Form submission successful.',
2251-
submissionId: submission.id,
2252-
})
2253-
}
2254-
2255-
export const handleEmailPreviewSubmission = [
2256-
ReceiverMiddleware.receiveEmailSubmission,
2257-
EmailSubmissionMiddleware.validateResponseParams,
2258-
submitEmailPreview,
2259-
] as ControllerHandler[]
2260-
22612087
/**
22622088
* Handler for PUT /forms/:formId/fields/:fieldId
22632089
* @security session

src/app/modules/payments/payments.service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { GrowthBook } from '@growthbook/growthbook'
21
import { isEqual, omit } from 'lodash'
32
import moment from 'moment-timezone'
43
import mongoose, { Types } from 'mongoose'
@@ -209,7 +208,6 @@ export const confirmPaymentPendingSubmission = (
209208
*/
210209
export const performPaymentPostSubmissionActions = (
211210
paymentId: IPaymentSchema['_id'],
212-
growthbook: GrowthBook | undefined,
213211
): ResultAsync<
214212
void,
215213
| PaymentNotFoundError
@@ -244,7 +242,7 @@ export const performPaymentPostSubmissionActions = (
244242
performEncryptPostSubmissionActions({
245243
submission,
246244
responses: payment.responses,
247-
growthbook,
245+
emailFields: [], // No email confirmation emails sent for payment forms - same as existing behavior
248246
})
249247
.andThen(() =>
250248
// If successfully sent email confirmations, delete response data from payment document.

src/app/modules/payments/stripe.controller.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,7 @@ export const reconcileAccount: ControllerHandler<
304304
meta: { ...logMeta, event },
305305
})
306306

307-
await StripeService.handleStripeEvent(
308-
event as Stripe.DiscriminatedEvent,
309-
req.growthbook,
310-
)
307+
await StripeService.handleStripeEvent(event as Stripe.DiscriminatedEvent)
311308
.andThen(() => {
312309
logger.warn({
313310
message:

src/app/modules/payments/stripe.events.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const _handleStripeEventUpdates: ControllerHandler<
8989

9090
// Step 3: Process the event
9191
return (
92-
StripeService.handleStripeEvent(event, req.growthbook)
92+
StripeService.handleStripeEvent(event)
9393
// Step 4: Return response to Stripe based on result
9494
.match(
9595
() => res.sendStatus(StatusCodes.OK),

src/app/modules/payments/stripe.service.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Use 'stripe-event-types' for better type discrimination.
22
/// <reference types="stripe-event-types" />
3-
import { GrowthBook } from '@growthbook/growthbook'
43
import cuid from 'cuid'
54
import mongoose from 'mongoose'
65
import { errAsync, ok, okAsync, ResultAsync } from 'neverthrow'
@@ -451,7 +450,6 @@ type HandleStripeEventResultError =
451450
*/
452451
export const handleStripeEvent = (
453452
event: Stripe.DiscriminatedEvent,
454-
growthbook: GrowthBook | undefined,
455453
): ResultAsync<void, HandleStripeEventResultError> => {
456454
const logMeta = {
457455
action: 'handleStripeEvent',
@@ -498,7 +496,6 @@ export const handleStripeEvent = (
498496

499497
return PaymentsService.performPaymentPostSubmissionActions(
500498
paymentId,
501-
growthbook,
502499
)
503500
.andThen(() => okAsync(undefined))
504501
.orElse((e) => {

src/app/modules/submission/__tests__/submission.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,13 +833,13 @@ describe('submission.service', () => {
833833
expect(result._unsafeUnwrap()).toBe(true)
834834
})
835835

836-
it('should generate pdfAttachment when form summary for respondent is enabled', async () => { })
836+
it('should generate pdfAttachment when form summary for respondent is enabled', async () => {})
837837

838-
it('should not generate pdfAttachment for payment form', () => { })
838+
it('should not generate pdfAttachment for payment form', () => {})
839839

840-
it('should generate pdfAttachment for admin email notification', () => { })
840+
it('should generate pdfAttachment for admin email notification', () => {})
841841

842-
it('should return pdf generation error when pdf generation fails', () => { })
842+
it('should return pdf generation error when pdf generation fails', () => {})
843843

844844
it('should return SendEmailConfirmationError when mail service errors', async () => {
845845
const mockForm = {

0 commit comments

Comments
 (0)