updates
This commit is contained in:
@@ -43,6 +43,27 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 404, statusMessage: "Interest not found" });
|
||||
}
|
||||
|
||||
// Documenso API configuration - moved to top for use throughout
|
||||
const documensoApiKey = process.env.NUXT_DOCUMENSO_API_KEY;
|
||||
const documensoBaseUrl = process.env.NUXT_DOCUMENSO_BASE_URL;
|
||||
const templateId = '9';
|
||||
|
||||
if (!documensoApiKey || !documensoBaseUrl) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "Documenso configuration missing. Please check NUXT_DOCUMENSO_API_KEY and NUXT_DOCUMENSO_BASE_URL environment variables."
|
||||
});
|
||||
}
|
||||
|
||||
// Check if uploaded EOI documents exist - prevent generation if they do
|
||||
const eoiDocuments = interest['EOI Document'] || [];
|
||||
if (eoiDocuments.length > 0) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Cannot generate EOI - uploaded documents already exist. Please remove uploaded documents first."
|
||||
});
|
||||
}
|
||||
|
||||
// Check if EOI already exists (has signature links)
|
||||
if (interest['Signature Link Client'] && interest['Signature Link CC'] && interest['Signature Link Developer']) {
|
||||
console.log('EOI already exists, returning existing links');
|
||||
@@ -58,6 +79,29 @@ export default defineEventHandler(async (event) => {
|
||||
};
|
||||
}
|
||||
|
||||
// If there's an existing generated document, delete it from Documenso first
|
||||
if (interest['documensoID']) {
|
||||
console.log('Existing generated document found, deleting from Documenso first');
|
||||
try {
|
||||
const deleteResponse = await fetch(`${documensoBaseUrl}/api/v1/documents/${interest['documensoID']}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${documensoApiKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (deleteResponse.ok) {
|
||||
console.log('Successfully deleted old document from Documenso');
|
||||
} else {
|
||||
console.warn('Failed to delete old document from Documenso, continuing with new generation');
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error deleting old document from Documenso:', error);
|
||||
// Continue with generation even if deletion fails
|
||||
}
|
||||
}
|
||||
|
||||
// Validate required fields
|
||||
const requiredFields = [
|
||||
{ field: 'Full Name', value: interest['Full Name'] },
|
||||
@@ -104,18 +148,6 @@ export default defineEventHandler(async (event) => {
|
||||
// Concatenate berth numbers
|
||||
const berthNumbers = berths.map(b => b['Mooring Number']).join(', ');
|
||||
|
||||
// Documenso API configuration
|
||||
const documensoApiKey = process.env.NUXT_DOCUMENSO_API_KEY;
|
||||
const documensoBaseUrl = process.env.NUXT_DOCUMENSO_BASE_URL;
|
||||
const templateId = '9';
|
||||
|
||||
if (!documensoApiKey || !documensoBaseUrl) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: "Documenso configuration missing. Please check NUXT_DOCUMENSO_API_KEY and NUXT_DOCUMENSO_BASE_URL environment variables."
|
||||
});
|
||||
}
|
||||
|
||||
// 1. Get template (optional - just to verify it exists)
|
||||
try {
|
||||
const templateResponse = await fetch(`${documensoBaseUrl}/api/v1/templates/${templateId}`, {
|
||||
@@ -272,7 +304,8 @@ export default defineEventHandler(async (event) => {
|
||||
'EOI Status': 'Waiting for Signatures',
|
||||
'Sales Process Level': 'LOI and NDA Sent',
|
||||
// Don't set EOI Time Sent here - only when email is sent or link is copied
|
||||
'Extra Comments': updatedComments
|
||||
'Extra Comments': updatedComments,
|
||||
'documensoID': documentResponse.documentId.toString()
|
||||
};
|
||||
|
||||
// Add signing links to update data with new column names
|
||||
|
||||
Reference in New Issue
Block a user