Skip to content

Commit

Permalink
chore: convert mongoose doc to obj for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
tshuli committed Feb 13, 2024
1 parent b196823 commit 5c78ed8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/app/modules/payments/payments.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEqual } from 'lodash'
import { isEqual, omit } from 'lodash'
import moment from 'moment-timezone'
import mongoose, { Types } from 'mongoose'
import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow'
Expand Down Expand Up @@ -411,7 +411,11 @@ export const validatePaymentProducts = (
const productDefinition = formProductsDefinition.find(
(product) => String(product._id) === String(productIdSubmitted),
)
if (!productDefinition || !isEqual(productDefinition, product.data)) {

if (
!productDefinition ||
!isEqual(omit(productDefinition, '_id'), omit(product.data, '_id'))
) {
logger.error({
message: 'Invalid payment product selected.',
meta: logMeta,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FormResponseMode,
isPaymentsProducts,
} from '../../../../../shared/types'
import { IPopulatedForm } from '../../../../types'
import {
EncryptAttachmentResponse,
EncryptFormFieldResponse,
Expand Down Expand Up @@ -284,11 +285,13 @@ export const validatePaymentSubmission = async (
res: Parameters<EncryptSubmissionMiddlewareHandlerType>[1],
next: NextFunction,
) => {
const formDef = req.formsg.formDef
const formDefDoc = req.formsg.formDef as IPopulatedForm

const formDef = formDefDoc.toObject() // Convert to POJO

const logMeta = {
action: 'validatePaymentSubmission',
formId: formDef._id.toString(),
formId: String(formDef._id),
...createReqMeta(req),
}

Expand Down

0 comments on commit 5c78ed8

Please sign in to comment.