From e13b3806a981e3dc12dde442b7518f8aafcb3ae9 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 4 Dec 2024 19:43:19 +0100 Subject: [PATCH] Fix/verification project form email verification --- .../projectVerificationRepository.ts | 30 +++++++++++++++---- .../projectVerificationFormResolver.ts | 4 +++ .../projectVerificationFormService.ts | 8 ++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/repositories/projectVerificationRepository.ts b/src/repositories/projectVerificationRepository.ts index aef5510e0..b29694d8b 100644 --- a/src/repositories/projectVerificationRepository.ts +++ b/src/repositories/projectVerificationRepository.ts @@ -204,8 +204,9 @@ export const updateProjectPersonalInfoOfProjectVerification = async (params: { export const updateProjectRegistryOfProjectVerification = async (params: { projectVerificationId: number; projectRegistry: ProjectRegistry; + email?: string; }): Promise => { - const { projectRegistry, projectVerificationId } = params; + const { projectRegistry, projectVerificationId, email } = params; const projectVerificationForm = await findProjectVerificationFormById( projectVerificationId, ); @@ -216,6 +217,9 @@ export const updateProjectRegistryOfProjectVerification = async (params: { } await ProjectVerificationForm.update(projectVerificationId, { projectRegistry, + emailConfirmedAt: new Date(), + emailConfirmed: true, + email, }); projectVerificationForm.projectRegistry = projectRegistry; return projectVerificationForm; @@ -264,8 +268,9 @@ export const updateProjectVerificationLastStep = async (params: { export const updateProjectContactsOfProjectVerification = async (params: { projectVerificationId: number; projectContacts: ProjectContacts[]; + email?: string; }): Promise => { - const { projectContacts, projectVerificationId } = params; + const { projectContacts, projectVerificationId, email } = params; const projectVerificationForm = await findProjectVerificationFormById( projectVerificationId, ); @@ -278,6 +283,9 @@ export const updateProjectContactsOfProjectVerification = async (params: { // projectContacts2.linkedin = projectContacts.linkedin await ProjectVerificationForm.update(projectVerificationId, { projectContacts, + emailConfirmedAt: new Date(), + emailConfirmed: true, + email, }); projectVerificationForm.projectContacts = projectContacts; return projectVerificationForm; @@ -285,8 +293,9 @@ export const updateProjectContactsOfProjectVerification = async (params: { export const updateMilestonesOfProjectVerification = async (params: { projectVerificationId: number; milestones: Milestones; + email?: string; }): Promise => { - const { milestones, projectVerificationId } = params; + const { milestones, projectVerificationId, email } = params; const projectVerificationForm = await findProjectVerificationFormById( projectVerificationId, ); @@ -297,6 +306,9 @@ export const updateMilestonesOfProjectVerification = async (params: { } await ProjectVerificationForm.update(projectVerificationId, { milestones, + emailConfirmedAt: new Date(), + emailConfirmed: true, + email: email, }); projectVerificationForm.milestones = milestones; return projectVerificationForm; @@ -304,8 +316,9 @@ export const updateMilestonesOfProjectVerification = async (params: { export const updateTermsAndConditionsOfProjectVerification = async (params: { projectVerificationId: number; isTermAndConditionsAccepted: boolean; + email?: string; }): Promise => { - const { isTermAndConditionsAccepted, projectVerificationId } = params; + const { isTermAndConditionsAccepted, projectVerificationId, email } = params; const projectVerificationForm = await findProjectVerificationFormById( projectVerificationId, ); @@ -318,6 +331,9 @@ export const updateTermsAndConditionsOfProjectVerification = async (params: { isTermAndConditionsAccepted; await ProjectVerificationForm.update(projectVerificationId, { isTermAndConditionsAccepted, + emailConfirmedAt: new Date(), + emailConfirmed: true, + email, }); return projectVerificationForm; }; @@ -325,8 +341,9 @@ export const updateTermsAndConditionsOfProjectVerification = async (params: { export const updateManagingFundsOfProjectVerification = async (params: { projectVerificationId: number; managingFunds: ManagingFunds; + email?: string; }): Promise => { - const { managingFunds, projectVerificationId } = params; + const { managingFunds, projectVerificationId, email } = params; const projectVerificationForm = await findProjectVerificationFormById( projectVerificationId, ); @@ -350,6 +367,9 @@ export const updateManagingFundsOfProjectVerification = async (params: { projectVerificationForm.managingFunds = managingFunds; await ProjectVerificationForm.update(projectVerificationId, { managingFunds, + emailConfirmedAt: new Date(), + emailConfirmed: true, + email, }); return projectVerificationForm; }; diff --git a/src/resolvers/projectVerificationFormResolver.ts b/src/resolvers/projectVerificationFormResolver.ts index 2217bc99c..a440552c9 100644 --- a/src/resolvers/projectVerificationFormResolver.ts +++ b/src/resolvers/projectVerificationFormResolver.ts @@ -34,6 +34,7 @@ import config from '../config'; import { countriesList } from '../utils/utils'; import { Country } from '../entities/Country'; import { getNotificationAdapter } from '../adapters/adaptersFactory'; +import { findUserById } from '../repositories/userRepository'; @Resolver(_of => ProjectVerificationForm) export class ProjectVerificationFormResolver { @@ -256,6 +257,7 @@ export class ProjectVerificationFormResolver { ): Promise { try { const userId = user?.userId; + const userData = await findUserById(userId); const { projectVerificationId } = projectVerificationUpdateInput; if (!userId) { throw new Error(i18n.__(translationErrorMessagesKeys.UN_AUTHORIZED)); @@ -285,9 +287,11 @@ export class ProjectVerificationFormResolver { i18n.__(translationErrorMessagesKeys.PROJECT_IS_ALREADY_VERIFIED), ); } + const email = userData?.email || ''; const verificationForm = await updateProjectVerificationFormByUser({ projectVerificationForm, projectVerificationUpdateInput, + email, }); return verificationForm; diff --git a/src/services/projectVerificationFormService.ts b/src/services/projectVerificationFormService.ts index db6c8f07a..93e527b61 100644 --- a/src/services/projectVerificationFormService.ts +++ b/src/services/projectVerificationFormService.ts @@ -61,8 +61,9 @@ const updateLastStep = async (params: { export const updateProjectVerificationFormByUser = async (params: { projectVerificationForm: ProjectVerificationForm; projectVerificationUpdateInput: ProjectVerificationUpdateInput; + email?: string; }): Promise => { - const { projectVerificationUpdateInput } = params; + const { projectVerificationUpdateInput, email } = params; const { projectVerificationId, step } = projectVerificationUpdateInput; const personalInfo = projectVerificationUpdateInput.personalInfo as PersonalInfo; @@ -101,6 +102,7 @@ export const updateProjectVerificationFormByUser = async (params: { await updateProjectContactsOfProjectVerification({ projectVerificationId, projectContacts, + email, }); break; case PROJECT_VERIFICATION_STEPS.PROJECT_REGISTRY: @@ -114,6 +116,7 @@ export const updateProjectVerificationFormByUser = async (params: { await updateProjectRegistryOfProjectVerification({ projectVerificationId, projectRegistry, + email, }); break; case PROJECT_VERIFICATION_STEPS.MANAGING_FUNDS: @@ -127,6 +130,7 @@ export const updateProjectVerificationFormByUser = async (params: { await updateManagingFundsOfProjectVerification({ projectVerificationId, managingFunds, + email, }); break; case PROJECT_VERIFICATION_STEPS.MILESTONES: @@ -140,6 +144,7 @@ export const updateProjectVerificationFormByUser = async (params: { await updateMilestonesOfProjectVerification({ projectVerificationId, milestones, + email, }); break; case PROJECT_VERIFICATION_STEPS.TERM_AND_CONDITION: { @@ -153,6 +158,7 @@ export const updateProjectVerificationFormByUser = async (params: { await updateTermsAndConditionsOfProjectVerification({ projectVerificationId, isTermAndConditionsAccepted, + email, }); break;