form 16 renaming logs added
This commit is contained in:
parent
44a19bbfea
commit
1a02781731
Binary file not shown.
@ -745,6 +745,13 @@ async function renameForm16SubmissionPdfAfterCreditNote(params: {
|
|||||||
oldRelativePath: string;
|
oldRelativePath: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { submissionId, requestId, oldRelativePath } = params;
|
const { submissionId, requestId, oldRelativePath } = params;
|
||||||
|
logger.info('[Form16] PDF rename flow start', {
|
||||||
|
submissionId,
|
||||||
|
requestId,
|
||||||
|
oldRelativePath,
|
||||||
|
nodeEnv: process.env.NODE_ENV,
|
||||||
|
gcpBucket: process.env.GCP_BUCKET_NAME || null,
|
||||||
|
});
|
||||||
const oldPathNorm = String(oldRelativePath || '').replace(/\\/g, '/').trim();
|
const oldPathNorm = String(oldRelativePath || '').replace(/\\/g, '/').trim();
|
||||||
if (!oldPathNorm || oldPathNorm.includes('..') || !oldPathNorm.startsWith('requests/')) {
|
if (!oldPathNorm || oldPathNorm.includes('..') || !oldPathNorm.startsWith('requests/')) {
|
||||||
logger.warn('[Form16] Skip PDF rename: invalid storage path', { oldPathNorm });
|
logger.warn('[Form16] Skip PDF rename: invalid storage path', { oldPathNorm });
|
||||||
@ -752,16 +759,39 @@ async function renameForm16SubmissionPdfAfterCreditNote(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sub = await Form16aSubmission.findByPk(submissionId);
|
const sub = await Form16aSubmission.findByPk(submissionId);
|
||||||
if (!sub) return;
|
if (!sub) {
|
||||||
|
logger.warn('[Form16] Skip PDF rename: submission not found', { submissionId, requestId });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newFileName = buildForm16CreditNoteSuccessPdfFileName(sub);
|
const newFileName = buildForm16CreditNoteSuccessPdfFileName(sub);
|
||||||
|
logger.info('[Form16] PDF rename target name computed', {
|
||||||
|
submissionId,
|
||||||
|
requestId,
|
||||||
|
newFileName,
|
||||||
|
tanNumber: (sub as any).tanNumber || null,
|
||||||
|
financialYear: (sub as any).financialYear || null,
|
||||||
|
quarter: (sub as any).quarter || null,
|
||||||
|
form16aNumber: (sub as any).form16aNumber || null,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await gcsStorageService.renameRequestDocumentFile({
|
const result = await gcsStorageService.renameRequestDocumentFile({
|
||||||
oldRelativePath: oldPathNorm,
|
oldRelativePath: oldPathNorm,
|
||||||
newFileName,
|
newFileName,
|
||||||
});
|
});
|
||||||
|
logger.info('[Form16] Storage rename success', {
|
||||||
|
submissionId,
|
||||||
|
requestId,
|
||||||
|
oldPathNorm,
|
||||||
|
renamedFilePath: result.filePath,
|
||||||
|
renamedStorageUrlPrefix: String(result.storageUrl || '').slice(0, 120),
|
||||||
|
});
|
||||||
await sub.update({ documentUrl: result.storageUrl });
|
await sub.update({ documentUrl: result.storageUrl });
|
||||||
|
logger.info('[Form16] Submission documentUrl updated after rename', {
|
||||||
|
submissionId,
|
||||||
|
requestId,
|
||||||
|
});
|
||||||
|
|
||||||
const doc = await Document.findOne({
|
const doc = await Document.findOne({
|
||||||
where: { requestId, filePath: oldPathNorm },
|
where: { requestId, filePath: oldPathNorm },
|
||||||
@ -776,6 +806,13 @@ async function renameForm16SubmissionPdfAfterCreditNote(params: {
|
|||||||
filePath: fp,
|
filePath: fp,
|
||||||
storageUrl: su,
|
storageUrl: su,
|
||||||
});
|
});
|
||||||
|
logger.info('[Form16] Document metadata updated after rename', {
|
||||||
|
requestId,
|
||||||
|
submissionId,
|
||||||
|
documentId: (doc as any).id || null,
|
||||||
|
oldPathNorm,
|
||||||
|
newPath: fp,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
logger.warn('[Form16] PDF renamed; documents row not found for path', { requestId, oldPathNorm });
|
logger.warn('[Form16] PDF renamed; documents row not found for path', { requestId, oldPathNorm });
|
||||||
}
|
}
|
||||||
@ -1331,6 +1368,12 @@ export async function createSubmission(
|
|||||||
);
|
);
|
||||||
// When credit note is issued (completed), set workflow status to CLOSED so the request appears on Closed requests page
|
// When credit note is issued (completed), set workflow status to CLOSED so the request appears on Closed requests page
|
||||||
if (validationStatus === 'success' && creditNoteNumber) {
|
if (validationStatus === 'success' && creditNoteNumber) {
|
||||||
|
logger.info('[Form16] Success path reached; triggering PDF rename', {
|
||||||
|
requestId,
|
||||||
|
submissionId: submission.id,
|
||||||
|
creditNoteNumber,
|
||||||
|
uploadFilePath,
|
||||||
|
});
|
||||||
const workflow = await WorkflowRequest.findOne({ where: { requestId }, attributes: ['requestId', 'status'] });
|
const workflow = await WorkflowRequest.findOne({ where: { requestId }, attributes: ['requestId', 'status'] });
|
||||||
if (workflow && (workflow as any).status !== WorkflowStatus.CLOSED) {
|
if (workflow && (workflow as any).status !== WorkflowStatus.CLOSED) {
|
||||||
await workflow.update({ status: WorkflowStatus.CLOSED });
|
await workflow.update({ status: WorkflowStatus.CLOSED });
|
||||||
@ -1341,6 +1384,17 @@ export async function createSubmission(
|
|||||||
requestId,
|
requestId,
|
||||||
oldRelativePath: uploadFilePath.replace(/\\/g, '/'),
|
oldRelativePath: uploadFilePath.replace(/\\/g, '/'),
|
||||||
});
|
});
|
||||||
|
logger.info('[Form16] PDF rename call completed', {
|
||||||
|
requestId,
|
||||||
|
submissionId: submission.id,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
logger.info('[Form16] PDF rename not triggered (submission not successful)', {
|
||||||
|
requestId,
|
||||||
|
submissionId: submission.id,
|
||||||
|
validationStatus,
|
||||||
|
creditNoteNumber: creditNoteNumber || null,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|||||||
@ -355,6 +355,14 @@ class GCSStorageService {
|
|||||||
}): Promise<{ storageUrl: string; filePath: string; fileName: string }> {
|
}): Promise<{ storageUrl: string; filePath: string; fileName: string }> {
|
||||||
const { oldRelativePath } = options;
|
const { oldRelativePath } = options;
|
||||||
let newFileName = path.basename(String(options.newFileName || '').trim());
|
let newFileName = path.basename(String(options.newFileName || '').trim());
|
||||||
|
logger.info('[GCS] renameRequestDocumentFile called', {
|
||||||
|
oldRelativePath,
|
||||||
|
requestedNewFileName: options.newFileName,
|
||||||
|
sanitizedNewFileName: newFileName,
|
||||||
|
nodeEnv: process.env.NODE_ENV,
|
||||||
|
bucket: this.bucketName || null,
|
||||||
|
useGoogleSecretManager: process.env.USE_GOOGLE_SECRET_MANAGER || null,
|
||||||
|
});
|
||||||
if (!newFileName || newFileName === '.' || newFileName === '..') {
|
if (!newFileName || newFileName === '.' || newFileName === '..') {
|
||||||
throw new Error('Invalid new file name');
|
throw new Error('Invalid new file name');
|
||||||
}
|
}
|
||||||
@ -367,6 +375,7 @@ class GCSStorageService {
|
|||||||
const newRelativePath = `${dir}/${newFileName}`;
|
const newRelativePath = `${dir}/${newFileName}`;
|
||||||
|
|
||||||
if (!this.isConfigured()) {
|
if (!this.isConfigured()) {
|
||||||
|
logger.info('[GCS] renameRequestDocumentFile using local storage mode');
|
||||||
const fullOld = path.join(UPLOAD_DIR, ...oldNorm.split('/').filter(Boolean));
|
const fullOld = path.join(UPLOAD_DIR, ...oldNorm.split('/').filter(Boolean));
|
||||||
const fullNew = path.join(UPLOAD_DIR, ...newRelativePath.split('/').filter(Boolean));
|
const fullNew = path.join(UPLOAD_DIR, ...newRelativePath.split('/').filter(Boolean));
|
||||||
if (!fs.existsSync(fullOld)) {
|
if (!fs.existsSync(fullOld)) {
|
||||||
@ -387,12 +396,19 @@ class GCSStorageService {
|
|||||||
const bucket = this.storage.bucket(this.bucketName);
|
const bucket = this.storage.bucket(this.bucketName);
|
||||||
const oldFile = bucket.file(oldNorm);
|
const oldFile = bucket.file(oldNorm);
|
||||||
const [exists] = await oldFile.exists();
|
const [exists] = await oldFile.exists();
|
||||||
|
logger.info('[GCS] renameRequestDocumentFile GCS existence check', {
|
||||||
|
oldNorm,
|
||||||
|
exists,
|
||||||
|
newRelativePath,
|
||||||
|
});
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
throw new Error(`GCS file not found: ${oldNorm}`);
|
throw new Error(`GCS file not found: ${oldNorm}`);
|
||||||
}
|
}
|
||||||
const newFile = bucket.file(newRelativePath);
|
const newFile = bucket.file(newRelativePath);
|
||||||
await oldFile.copy(newFile);
|
await oldFile.copy(newFile);
|
||||||
|
logger.info('[GCS] renameRequestDocumentFile copy success', { from: oldNorm, to: newRelativePath });
|
||||||
await oldFile.delete();
|
await oldFile.delete();
|
||||||
|
logger.info('[GCS] renameRequestDocumentFile delete old success', { oldNorm });
|
||||||
|
|
||||||
let publicUrl: string;
|
let publicUrl: string;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user