Fix middleware order, pbCollection scope, and add UNK support
This commit is contained in:
@@ -751,8 +751,8 @@ app.post('/api/submit', async (c) => {
|
|||||||
const onlySymbols = /^[^A-Za-z0-9]+$/.test(jobName);
|
const onlySymbols = /^[^A-Za-z0-9]+$/.test(jobName);
|
||||||
const hasLetters = /[A-Za-z]/.test(jobName);
|
const hasLetters = /[A-Za-z]/.test(jobName);
|
||||||
const isInvalidLiteral = invalidLiterals.includes(jobName.toLowerCase());
|
const isInvalidLiteral = invalidLiterals.includes(jobName.toLowerCase());
|
||||||
const isLongEnough = jobName.length >= 4;
|
const isLongEnough = jobName.length >= 4 || jobName.toUpperCase() === "UNK";
|
||||||
if (!isLongEnough || !hasLetters || onlySymbols || isInvalidLiteral) {
|
if (!isLongEnough || (!hasLetters && jobName.toUpperCase() !== "UNK") || onlySymbols || isInvalidLiteral) {
|
||||||
return c.json({
|
return c.json({
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Job name must be at least 4 characters with letters (no symbols-only, no N/A).'
|
message: 'Job name must be at least 4 characters with letters (no symbols-only, no N/A).'
|
||||||
@@ -771,7 +771,7 @@ app.post('/api/submit', async (c) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get all existing job numbers and find the max
|
// Get all existing job numbers and find the max
|
||||||
const existingJobs = await pb.collection(pbCollection).getFullList({
|
const existingJobs = await pb.collection(activeConfig.pbCollection).getFullList({
|
||||||
fields: 'Job_Number',
|
fields: 'Job_Number',
|
||||||
sort: '-created',
|
sort: '-created',
|
||||||
});
|
});
|
||||||
@@ -792,7 +792,7 @@ app.post('/api/submit', async (c) => {
|
|||||||
delete data.pbToken;
|
delete data.pbToken;
|
||||||
|
|
||||||
// Create the record in PocketBase as the authenticated user
|
// Create the record in PocketBase as the authenticated user
|
||||||
const record = await pb.collection(pbCollection).create(data);
|
const record = await pb.collection(activeConfig.pbCollection).create(data);
|
||||||
console.log(`✓ Created PocketBase record with Job_Number: ${newJobNumber}, ID: ${record.id}`);
|
console.log(`✓ Created PocketBase record with Job_Number: ${newJobNumber}, ID: ${record.id}`);
|
||||||
|
|
||||||
// Persist calculated fields to PocketBase immediately after creation
|
// Persist calculated fields to PocketBase immediately after creation
|
||||||
@@ -802,7 +802,7 @@ app.post('/api/submit', async (c) => {
|
|||||||
const voxerLinkVal = calculateVoxerLink(record);
|
const voxerLinkVal = calculateVoxerLink(record);
|
||||||
const jobCodesVal = calculateJobCodes(record);
|
const jobCodesVal = calculateJobCodes(record);
|
||||||
|
|
||||||
await pb.collection(pbCollection).update(record.id, {
|
await pb.collection(activeConfig.pbCollection).update(record.id, {
|
||||||
Job_Full_Name: fullName,
|
Job_Full_Name: fullName,
|
||||||
Job_QB_Link: qbLink,
|
Job_QB_Link: qbLink,
|
||||||
Voxer_Link: voxerLinkVal,
|
Voxer_Link: voxerLinkVal,
|
||||||
@@ -872,7 +872,7 @@ app.post('/api/submit', async (c) => {
|
|||||||
try {
|
try {
|
||||||
const dueStatic = calculateDueDateCounter(record);
|
const dueStatic = calculateDueDateCounter(record);
|
||||||
const activeStatic = calculateActive(record);
|
const activeStatic = calculateActive(record);
|
||||||
await pb.collection(pbCollection).update(record.id, {
|
await pb.collection(activeConfig.pbCollection).update(record.id, {
|
||||||
Job_Folder_Link: jobFolderLink || '',
|
Job_Folder_Link: jobFolderLink || '',
|
||||||
Due_Date_Counter: dueStatic,
|
Due_Date_Counter: dueStatic,
|
||||||
Active: activeStatic
|
Active: activeStatic
|
||||||
|
|||||||
Reference in New Issue
Block a user