Adjusted SMTP
This commit is contained in:
@@ -2,11 +2,12 @@ import { NextResponse } from "next/server";
|
||||
import { requirePlatformRole } from "@/lib/session";
|
||||
import { getTenantRequestById, updateTenantRequestStatus } from "@/lib/db";
|
||||
import { createTenant } from "@/lib/k8s";
|
||||
import { sendApprovalEmail } from "@/lib/email";
|
||||
|
||||
/**
|
||||
* POST /api/admin/requests/[id]/approve
|
||||
* Approve a tenant request: create the PiecedTenant CR and update status.
|
||||
* Also supports re-approving a previously rejected request.
|
||||
* Approve a tenant request: create the PiecedTenant CR, update status, notify customer.
|
||||
* Also supports re-approving a previously rejected request (clears admin notes).
|
||||
*/
|
||||
export async function POST(
|
||||
request: Request,
|
||||
@@ -37,6 +38,8 @@ export async function POST(
|
||||
);
|
||||
}
|
||||
|
||||
const isReApproval = tenantRequest.status === "rejected";
|
||||
|
||||
// Derive tenant name from company name: lowercase, alphanumeric + hyphens
|
||||
const tenantName = tenantRequest.companyName
|
||||
.toLowerCase()
|
||||
@@ -61,12 +64,20 @@ export async function POST(
|
||||
}
|
||||
);
|
||||
|
||||
// Update request status
|
||||
// Update request status — clear admin notes on re-approval
|
||||
const updated = await updateTenantRequestStatus(id, "provisioning", {
|
||||
adminNotes,
|
||||
adminNotes: isReApproval ? null : adminNotes,
|
||||
tenantName,
|
||||
clearAdminNotes: isReApproval,
|
||||
});
|
||||
|
||||
// Notify customer
|
||||
await sendApprovalEmail(
|
||||
tenantRequest.contactEmail,
|
||||
tenantRequest.contactName,
|
||||
tenantRequest.companyName
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
message: "Tenant approved and provisioning started.",
|
||||
request: updated,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { requirePlatformRole } from "@/lib/session";
|
||||
import { getTenantRequestById, updateTenantRequestStatus } from "@/lib/db";
|
||||
import { sendRejectionEmail } from "@/lib/email";
|
||||
|
||||
/**
|
||||
* POST /api/admin/requests/[id]/reject
|
||||
* Reject a tenant request.
|
||||
* Reject a tenant request and notify the customer.
|
||||
*/
|
||||
export async function POST(
|
||||
request: Request,
|
||||
@@ -36,6 +37,14 @@ export async function POST(
|
||||
adminNotes,
|
||||
});
|
||||
|
||||
// Notify customer
|
||||
await sendRejectionEmail(
|
||||
tenantRequest.contactEmail,
|
||||
tenantRequest.contactName,
|
||||
tenantRequest.companyName,
|
||||
adminNotes
|
||||
);
|
||||
|
||||
return NextResponse.json({
|
||||
message: "Request rejected.",
|
||||
request: updated,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { requirePlatformRole } from "@/lib/session";
|
||||
import { listTenantRequests } from "@/lib/db";
|
||||
import { listTenantRequests, syncProvisioningStatuses } from "@/lib/db";
|
||||
import { getTenant } from "@/lib/k8s";
|
||||
|
||||
/**
|
||||
* GET /api/admin/requests
|
||||
* List all tenant requests. Optionally filter by ?status=pending
|
||||
* Auto-syncs "provisioning" → "active" when the PiecedTenant CR is Ready.
|
||||
*/
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
@@ -13,6 +15,12 @@ export async function GET(request: Request) {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
// Sync provisioning statuses before listing
|
||||
await syncProvisioningStatuses(async (tenantName: string) => {
|
||||
const tenant = await getTenant(tenantName);
|
||||
return tenant?.status?.phase ?? null;
|
||||
});
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get("status") as any;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
getTenantRequestByOrgId,
|
||||
} from "@/lib/db";
|
||||
import { getTenant, listTenants } from "@/lib/k8s";
|
||||
import { sendAdminNotificationEmail } from "@/lib/email";
|
||||
import type { OnboardingInput } from "@/types";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -87,6 +88,7 @@ export async function GET() {
|
||||
* POST /api/onboarding
|
||||
* Submit the onboarding wizard. Creates a tenant_request with status "pending".
|
||||
* The actual PiecedTenant CR is NOT created yet — admin approval required.
|
||||
* Sends a notification email to the admin.
|
||||
*/
|
||||
export async function POST(request: Request) {
|
||||
const user = await getSessionUser();
|
||||
@@ -138,6 +140,13 @@ export async function POST(request: Request) {
|
||||
billingNotes: input.billingNotes,
|
||||
});
|
||||
|
||||
// Notify admin about the new request
|
||||
await sendAdminNotificationEmail(
|
||||
user.orgName,
|
||||
user.name || user.email,
|
||||
user.email
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
{ message: "Onboarding request submitted.", request: tenantRequest },
|
||||
{ status: 201 }
|
||||
|
||||
Reference in New Issue
Block a user