Skip to content

Commit

Permalink
Fix/verification project form email verification
Browse files Browse the repository at this point in the history
  • Loading branch information
kkatusic committed Dec 4, 2024
1 parent 795e035 commit e13b380
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
30 changes: 25 additions & 5 deletions src/repositories/projectVerificationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ export const updateProjectPersonalInfoOfProjectVerification = async (params: {
export const updateProjectRegistryOfProjectVerification = async (params: {
projectVerificationId: number;
projectRegistry: ProjectRegistry;
email?: string;
}): Promise<ProjectVerificationForm> => {
const { projectRegistry, projectVerificationId } = params;
const { projectRegistry, projectVerificationId, email } = params;
const projectVerificationForm = await findProjectVerificationFormById(
projectVerificationId,
);
Expand All @@ -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;
Expand Down Expand Up @@ -264,8 +268,9 @@ export const updateProjectVerificationLastStep = async (params: {
export const updateProjectContactsOfProjectVerification = async (params: {
projectVerificationId: number;
projectContacts: ProjectContacts[];
email?: string;
}): Promise<ProjectVerificationForm> => {
const { projectContacts, projectVerificationId } = params;
const { projectContacts, projectVerificationId, email } = params;
const projectVerificationForm = await findProjectVerificationFormById(
projectVerificationId,
);
Expand All @@ -278,15 +283,19 @@ 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;
};
export const updateMilestonesOfProjectVerification = async (params: {
projectVerificationId: number;
milestones: Milestones;
email?: string;
}): Promise<ProjectVerificationForm> => {
const { milestones, projectVerificationId } = params;
const { milestones, projectVerificationId, email } = params;
const projectVerificationForm = await findProjectVerificationFormById(
projectVerificationId,
);
Expand All @@ -297,15 +306,19 @@ export const updateMilestonesOfProjectVerification = async (params: {
}
await ProjectVerificationForm.update(projectVerificationId, {
milestones,
emailConfirmedAt: new Date(),
emailConfirmed: true,
email: email,
});
projectVerificationForm.milestones = milestones;
return projectVerificationForm;
};
export const updateTermsAndConditionsOfProjectVerification = async (params: {
projectVerificationId: number;
isTermAndConditionsAccepted: boolean;
email?: string;
}): Promise<ProjectVerificationForm> => {
const { isTermAndConditionsAccepted, projectVerificationId } = params;
const { isTermAndConditionsAccepted, projectVerificationId, email } = params;
const projectVerificationForm = await findProjectVerificationFormById(
projectVerificationId,
);
Expand All @@ -318,15 +331,19 @@ export const updateTermsAndConditionsOfProjectVerification = async (params: {
isTermAndConditionsAccepted;
await ProjectVerificationForm.update(projectVerificationId, {
isTermAndConditionsAccepted,
emailConfirmedAt: new Date(),
emailConfirmed: true,
email,
});
return projectVerificationForm;
};

export const updateManagingFundsOfProjectVerification = async (params: {
projectVerificationId: number;
managingFunds: ManagingFunds;
email?: string;
}): Promise<ProjectVerificationForm> => {
const { managingFunds, projectVerificationId } = params;
const { managingFunds, projectVerificationId, email } = params;
const projectVerificationForm = await findProjectVerificationFormById(
projectVerificationId,
);
Expand All @@ -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;
};
Expand Down
4 changes: 4 additions & 0 deletions src/resolvers/projectVerificationFormResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -256,6 +257,7 @@ export class ProjectVerificationFormResolver {
): Promise<ProjectVerificationForm> {
try {
const userId = user?.userId;
const userData = await findUserById(userId);
const { projectVerificationId } = projectVerificationUpdateInput;
if (!userId) {
throw new Error(i18n.__(translationErrorMessagesKeys.UN_AUTHORIZED));
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/services/projectVerificationFormService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ const updateLastStep = async (params: {
export const updateProjectVerificationFormByUser = async (params: {
projectVerificationForm: ProjectVerificationForm;
projectVerificationUpdateInput: ProjectVerificationUpdateInput;
email?: string;
}): Promise<ProjectVerificationForm> => {
const { projectVerificationUpdateInput } = params;
const { projectVerificationUpdateInput, email } = params;
const { projectVerificationId, step } = projectVerificationUpdateInput;
const personalInfo =
projectVerificationUpdateInput.personalInfo as PersonalInfo;
Expand Down Expand Up @@ -101,6 +102,7 @@ export const updateProjectVerificationFormByUser = async (params: {
await updateProjectContactsOfProjectVerification({
projectVerificationId,
projectContacts,
email,
});
break;
case PROJECT_VERIFICATION_STEPS.PROJECT_REGISTRY:
Expand All @@ -114,6 +116,7 @@ export const updateProjectVerificationFormByUser = async (params: {
await updateProjectRegistryOfProjectVerification({
projectVerificationId,
projectRegistry,
email,
});
break;
case PROJECT_VERIFICATION_STEPS.MANAGING_FUNDS:
Expand All @@ -127,6 +130,7 @@ export const updateProjectVerificationFormByUser = async (params: {
await updateManagingFundsOfProjectVerification({
projectVerificationId,
managingFunds,
email,
});
break;
case PROJECT_VERIFICATION_STEPS.MILESTONES:
Expand All @@ -140,6 +144,7 @@ export const updateProjectVerificationFormByUser = async (params: {
await updateMilestonesOfProjectVerification({
projectVerificationId,
milestones,
email,
});
break;
case PROJECT_VERIFICATION_STEPS.TERM_AND_CONDITION: {
Expand All @@ -153,6 +158,7 @@ export const updateProjectVerificationFormByUser = async (params: {
await updateTermsAndConditionsOfProjectVerification({
projectVerificationId,
isTermAndConditionsAccepted,
email,
});

break;
Expand Down

0 comments on commit e13b380

Please sign in to comment.