task-h
This commit is contained in:
@@ -19,8 +19,6 @@ const enquiryRequestSchema = enquirySchema.extend({
|
||||
contactId: z.string().nullable().optional(),
|
||||
branchId: z.string().nullable().optional(),
|
||||
leadChannel: z.string().nullable().optional(),
|
||||
estimatedValue: z.number().nullable().optional(),
|
||||
chancePercent: z.number().nullable().optional(),
|
||||
expectedCloseDate: z.string().nullable().optional()
|
||||
});
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ const enquiryRequestSchema = enquirySchema.extend({
|
||||
contactId: z.string().nullable().optional(),
|
||||
branchId: z.string().nullable().optional(),
|
||||
leadChannel: z.string().nullable().optional(),
|
||||
estimatedValue: z.number().nullable().optional(),
|
||||
chancePercent: z.number().nullable().optional(),
|
||||
expectedCloseDate: z.string().nullable().optional()
|
||||
});
|
||||
|
||||
|
||||
78
src/app/api/crm/quotations/[id]/approved-pdf/route.ts
Normal file
78
src/app/api/crm/quotations/[id]/approved-pdf/route.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { auditAction } from '@/features/foundation/audit-log/service';
|
||||
import {
|
||||
generateApprovedQuotationPdf,
|
||||
getStoredApprovedQuotationPdf
|
||||
} from '@/features/foundation/pdf-generator/server/service';
|
||||
import { getQuotationDetail } from '@/features/crm/quotations/server/service';
|
||||
import { PERMISSIONS } from '@/lib/auth/rbac';
|
||||
import { AuthError, requireOrganizationAccess } from '@/lib/auth/session';
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const { organization } = await requireOrganizationAccess({
|
||||
permission: PERMISSIONS.crmQuotationPdfDownload
|
||||
});
|
||||
const pdf = await getStoredApprovedQuotationPdf(id, organization.id);
|
||||
|
||||
return new NextResponse(pdf.buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `inline; filename="${pdf.fileName}"`
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
return NextResponse.json({ message: error.message }, { status: error.status });
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return NextResponse.json({ message: error.message }, { status: 400 });
|
||||
}
|
||||
return NextResponse.json({ message: 'Unable to load approved PDF' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const { organization, session } = await requireOrganizationAccess({
|
||||
permission: PERMISSIONS.crmQuotationPdfGenerateApproved
|
||||
});
|
||||
const before = await getQuotationDetail(id, organization.id);
|
||||
const pdf = await generateApprovedQuotationPdf(id, organization.id, session.user.id);
|
||||
const after = await getQuotationDetail(id, organization.id);
|
||||
|
||||
await auditAction({
|
||||
organizationId: organization.id,
|
||||
userId: session.user.id,
|
||||
entityType: 'crm_quotation_pdf_generate_approved',
|
||||
entityId: id,
|
||||
action: 'generate_approved',
|
||||
beforeData: before,
|
||||
afterData: {
|
||||
approvedPdfUrl: after.approvedPdfUrl,
|
||||
approvedTemplateVersionId: after.approvedTemplateVersionId
|
||||
}
|
||||
});
|
||||
|
||||
return new NextResponse(pdf.buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `attachment; filename="${pdf.fileName}"`
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
return NextResponse.json({ message: error.message }, { status: error.status });
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return NextResponse.json({ message: error.message }, { status: 400 });
|
||||
}
|
||||
return NextResponse.json({ message: 'Unable to generate approved PDF' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
33
src/app/api/crm/quotations/[id]/pdf-download/route.ts
Normal file
33
src/app/api/crm/quotations/[id]/pdf-download/route.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { generateQuotationPdf } from '@/features/foundation/pdf-generator/server/service';
|
||||
import { PERMISSIONS } from '@/lib/auth/rbac';
|
||||
import { AuthError, requireOrganizationAccess } from '@/lib/auth/session';
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const { organization } = await requireOrganizationAccess({
|
||||
permission: PERMISSIONS.crmQuotationPdfDownload
|
||||
});
|
||||
const pdf = await generateQuotationPdf(id, organization.id);
|
||||
|
||||
return new NextResponse(pdf.buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `attachment; filename="${pdf.fileName}"`
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
return NextResponse.json({ message: error.message }, { status: error.status });
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return NextResponse.json({ message: error.message }, { status: 400 });
|
||||
}
|
||||
return NextResponse.json({ message: 'Unable to generate quotation PDF' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
33
src/app/api/crm/quotations/[id]/pdf-preview/route.ts
Normal file
33
src/app/api/crm/quotations/[id]/pdf-preview/route.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { generateQuotationPreviewPdf } from '@/features/foundation/pdf-generator/server/service';
|
||||
import { PERMISSIONS } from '@/lib/auth/rbac';
|
||||
import { AuthError, requireOrganizationAccess } from '@/lib/auth/session';
|
||||
|
||||
type Params = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function GET(_request: NextRequest, { params }: Params) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const { organization } = await requireOrganizationAccess({
|
||||
permission: PERMISSIONS.crmQuotationPdfPreview
|
||||
});
|
||||
const pdf = await generateQuotationPreviewPdf(id, organization.id);
|
||||
|
||||
return new NextResponse(pdf.buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `inline; filename="${pdf.fileName}"`
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
return NextResponse.json({ message: error.message }, { status: error.status });
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return NextResponse.json({ message: error.message }, { status: 400 });
|
||||
}
|
||||
return NextResponse.json({ message: 'Unable to generate preview PDF' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user