fixes
This commit is contained in:
parent
bc591f687f
commit
f9f1bcd34a
|
|
@ -1,4 +1,5 @@
|
|||
import { getDocumesoDocumentByExternalId, checkDocumentSignatureStatus } from '~/server/utils/documeso';
|
||||
import { getInterestById } from '~/server/utils/nocodb';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
|
@ -12,6 +13,8 @@ export default defineEventHandler(async (event) => {
|
|||
const interestId = query.interestId as string;
|
||||
const documentId = query.documentId as string;
|
||||
|
||||
console.log('[check-signature-status] Request params:', { interestId, documentId });
|
||||
|
||||
if (!interestId && !documentId) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
|
|
@ -21,6 +24,7 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
// If we have a document ID, check directly
|
||||
if (documentId) {
|
||||
console.log('[check-signature-status] Using provided document ID:', documentId);
|
||||
const status = await checkDocumentSignatureStatus(parseInt(documentId));
|
||||
return {
|
||||
success: true,
|
||||
|
|
@ -28,17 +32,40 @@ export default defineEventHandler(async (event) => {
|
|||
};
|
||||
}
|
||||
|
||||
// Otherwise, try to find by external ID (using interestId)
|
||||
// Get the interest to check for stored documensoID
|
||||
const interest = await getInterestById(interestId);
|
||||
console.log('[check-signature-status] Interest retrieved:', {
|
||||
id: interest.Id,
|
||||
documensoID: interest['documensoID'],
|
||||
documensoID_type: typeof interest['documensoID'],
|
||||
has_signature_links: !!(interest['Signature Link Client'] || interest['Signature Link CC'] || interest['Signature Link Developer'])
|
||||
});
|
||||
|
||||
// If we have a stored documensoID, use it directly
|
||||
if (interest && interest['documensoID']) {
|
||||
console.log('[check-signature-status] Using stored documensoID:', interest['documensoID']);
|
||||
const status = await checkDocumentSignatureStatus(parseInt(interest['documensoID']));
|
||||
return {
|
||||
success: true,
|
||||
documentId: parseInt(interest['documensoID']),
|
||||
...status
|
||||
};
|
||||
}
|
||||
|
||||
// Otherwise, try to find by external ID (using interestId) - fallback method
|
||||
console.log('[check-signature-status] No documensoID stored, trying external ID fallback');
|
||||
const externalId = `loi-${interestId}`;
|
||||
const document = await getDocumesoDocumentByExternalId(externalId);
|
||||
|
||||
if (!document) {
|
||||
console.log('[check-signature-status] No document found by external ID either');
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Document not found for this interest',
|
||||
statusMessage: 'Document not found for this interest - no documensoID stored and external ID lookup failed',
|
||||
});
|
||||
}
|
||||
|
||||
console.log('[check-signature-status] Found document by external ID:', document.id);
|
||||
const status = await checkDocumentSignatureStatus(document.id);
|
||||
|
||||
return {
|
||||
|
|
@ -47,7 +74,7 @@ export default defineEventHandler(async (event) => {
|
|||
...status
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('Failed to check signature status:', error);
|
||||
console.error('[check-signature-status] Failed to check signature status:', error);
|
||||
throw createError({
|
||||
statusCode: error.statusCode || 500,
|
||||
statusMessage: error.statusMessage || 'Failed to check signature status',
|
||||
|
|
|
|||
Loading…
Reference in New Issue