fix email sender all flow
This commit is contained in:
@@ -13,6 +13,7 @@ import { auditLog } from "@/server/services/audit-log.service";
|
||||
import { emailService } from "@/lib/email/send";
|
||||
import { organizerRepo } from "@/server/repositories/organizer.repo";
|
||||
import { userRepo } from "@/server/repositories/user.repo";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { submitVerificationSchema, reviewVerificationSchema } from "./schemas";
|
||||
|
||||
export async function submitVerificationAction(formData: FormData) {
|
||||
@@ -43,6 +44,7 @@ export async function submitVerificationAction(formData: FormData) {
|
||||
...result.data,
|
||||
birthDate: new Date(result.data.birthDate),
|
||||
});
|
||||
void notifyKycSubmitted(session.user.id);
|
||||
revalidatePath("/verify");
|
||||
revalidatePath("/profile");
|
||||
revalidatePath("/admin/verifications");
|
||||
@@ -137,6 +139,54 @@ async function notifyVerificationDecision(
|
||||
}
|
||||
}
|
||||
|
||||
/** E3.9 — kabari user kalau pengajuan verifikasi-nya sudah masuk antrian. */
|
||||
async function notifyKycSubmitted(userId: string) {
|
||||
const verification = await prisma.organizerVerification.findUnique({
|
||||
where: { userId },
|
||||
select: { submissionCount: true },
|
||||
});
|
||||
const user = await userRepo.findById(userId);
|
||||
if (!verification || !user) return;
|
||||
await emailService.send({
|
||||
to: user.email,
|
||||
idempotencyKey: `kyc_submitted-${userId}-${verification.submissionCount}`,
|
||||
template: {
|
||||
template: "kyc_submitted",
|
||||
data: { userName: user.name },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** E3.11 — kabari user kalau pengajuan verifikasi-nya dibuka kembali admin. */
|
||||
async function notifyKycReopened(verificationId: string) {
|
||||
const verification = await organizerRepo.findById(verificationId);
|
||||
if (!verification) return;
|
||||
const user = await userRepo.findById(verification.userId);
|
||||
if (!user) return;
|
||||
await emailService.send({
|
||||
to: user.email,
|
||||
idempotencyKey: `kyc_reopened-${verificationId}-${verification.submissionCount}`,
|
||||
template: {
|
||||
template: "kyc_reopened",
|
||||
data: { userName: user.name },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** E3.10 — kabari user kalau admin verifikasi dia secara manual override. */
|
||||
async function notifyKycManualOverride(userId: string, verificationId: string) {
|
||||
const user = await userRepo.findById(userId);
|
||||
if (!user) return;
|
||||
await emailService.send({
|
||||
to: user.email,
|
||||
idempotencyKey: `kyc_manual_override-${verificationId}`,
|
||||
template: {
|
||||
template: "kyc_manual_override",
|
||||
data: { userName: user.name },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin reopen pengajuan REJECTED ke PENDING — supaya organizer bisa
|
||||
* di-review ulang tanpa drop & recreate row. Note wajib min 10 char untuk audit.
|
||||
@@ -156,6 +206,7 @@ export async function reopenVerificationAction(
|
||||
adminId: session.user.id,
|
||||
note,
|
||||
});
|
||||
void notifyKycReopened(verificationId);
|
||||
await auditLog.record({
|
||||
admin: { id: session.user.id, email: session.user.email },
|
||||
action: "VERIFICATION_REOPEN",
|
||||
@@ -262,6 +313,7 @@ export async function manualOverrideVerificationAction(input: {
|
||||
bankAccountNumber: input.bankAccountNumber,
|
||||
bankAccountName: input.bankAccountName,
|
||||
});
|
||||
void notifyKycManualOverride(input.userId, result.id);
|
||||
await auditLog.record({
|
||||
admin: { id: session.user.id, email: session.user.email },
|
||||
action: "VERIFICATION_MANUAL_OVERRIDE",
|
||||
|
||||
Reference in New Issue
Block a user