2 Commits

Author SHA1 Message Date
aewing 6f02194c23 Add checklist items and plum label to Planner tasks
- Add 3 checklist items to new Planner tasks:
  1. Create Voxer Chat
  2. Create Quickbooks
  3. Upload plans
- Add plum label (category6) to tasks
- Checklist and description patched in single API call
- Label added via separate PATCH with proper ETag handling
2026-01-07 07:37:48 +00:00
aewing cc52c11bf6 feat: implement environment-aware Planner configuration and UNK job name support 2026-01-07 07:02:16 +00:00
+62 -21
View File
@@ -23,20 +23,30 @@ const CONFIG = {
TEST: {
pbCollection: 'Job_Info_TestEnv',
excelTable: 'Test_Table',
plannerGroupId: 'e45f2188-dc65-42d6-b7b0-d0a873e07472',
plannerPlanId: '87nMEU5OqUqro1xLjY58-2UAD4uj',
plannerBucketId: '9VuH0OQEa0GQsCHtPgUCFmUACHVF',
description: '🧪 TEST ENVIRONMENT'
},
PROD: {
pbCollection: process.env.PB_COLLECTION || 'Job_Info_Prod',
excelTable: process.env.EXCEL_TABLE_NAME || 'Job_List',
plannerGroupId: process.env.PLANNER_GROUP_ID || 'e45f2188-dc65-42d6-b7b0-d0a873e07472',
plannerPlanId: process.env.PLANNER_PLAN_ID || '87nMEU5OqUqro1xLjY58-2UAD4uj',
plannerBucketId: process.env.PLANNER_BUCKET_ID || '9VuH0OQEa0GQsCHtPgUCFmUACHVF',
description: '🚀 PRODUCTION ENVIRONMENT'
}
};
const activeConfig = MODE === 'PROD' ? CONFIG.PROD : CONFIG.TEST;
console.log('\n' + '*'.repeat(60));
console.log(' RUNNING IN: ' + activeConfig.description);
console.log(' PocketBase: ' + activeConfig.pbCollection);
console.log(' Excel Table: ' + activeConfig.excelTable);
console.log(' RUNNING IN: ' + activeConfig.description);
console.log(' PocketBase: ' + activeConfig.pbCollection);
console.log(' Excel Table: ' + activeConfig.excelTable);
console.log(' Planner Plan: ' + activeConfig.plannerPlanId);
console.log(' Planner Bucket: ' + activeConfig.plannerBucketId);
console.log(' Planner Plan: ' + activeConfig.plannerPlanId);
console.log(' Planner Bucket: ' + activeConfig.plannerBucketId);
console.log('*'.repeat(60) + '\n');
const app = new Hono();
@@ -436,29 +446,46 @@ async function createPlannerTask({
// Task title: "Disposition New Job Folder for [Job_Number] [Job_Full_Name]"
const title = `Disposition New Job Folder for ${jobNumber} ${jobFullName}`;
// Create the Planner task
const groupId = process.env.PLANNER_GROUP_ID;
const planId = process.env.PLANNER_PLAN_ID;
const bucketId = process.env.PLANNER_BUCKET_ID;
// Create the Planner task
const groupId = activeConfig.plannerGroupId;
const planId = activeConfig.plannerPlanId;
const bucketId = activeConfig.plannerBucketId;
if (!groupId || !planId || !bucketId) {
throw new Error('Missing Planner configuration: PLANNER_GROUP_ID, PLANNER_PLAN_ID, or PLANNER_BUCKET_ID');
}
if (!groupId || !planId || !bucketId) {
throw new Error('Missing Planner configuration in activeConfig');
}
const newTask = await client.api('/planner/tasks').post({
planId,
bucketId,
title,
assignments: {
[assigneeId]: {
'@odata.type': 'microsoft.graph.plannerAssignment',
orderHint: ' !',
planId,
bucketId,
title,
assignments: {
[assigneeId]: {
'@odata.type': 'microsoft.graph.plannerAssignment',
orderHint: ' !',
},
},
},
...(dueDateObj ? { dueDateTime: dueDateObj } : {}),
...(dueDateObj ? { dueDateTime: dueDateObj } : {}),
});
console.log(`✓ Planner task created in Plan ID: ${planId}`);
console.log(`✓ Planner task created in Plan ID: ${planId}`);
// Build checklist object with unique IDs
const checklist: Record<string, { '@odata.type': string; title: string; isChecked: boolean; orderHint: string }> = {};
const checklistItems = ['Create Voxer Chat', 'Create Quickbooks', 'Upload plans'];
checklistItems.forEach((item, index) => {
const itemId = `checklist_${Date.now()}_${index}`;
checklist[itemId] = {
'@odata.type': 'microsoft.graph.plannerChecklistItem',
title: item,
isChecked: false,
orderHint: ` ${index}!`,
};
});
// Set the Notes/Description via task details (match the working test script)
// Set the Notes/Description AND checklist via task details
const taskDetails = await client.api(`/planner/tasks/${newTask.id}/details`).get();
const detailsEtag = taskDetails['@odata.etag'];
console.log(`[Planner] Task created ${newTask.id}, fetched details ETag: ${detailsEtag}`);
@@ -467,8 +494,22 @@ async function createPlannerTask({
.header('If-Match', detailsEtag)
.patch({
description: 'Move the new folder to the correct Job Pages folder.',
checklist: checklist,
});
console.log(`[Planner] Successfully patched description`);
console.log(`[Planner] Successfully patched description and added ${checklistItems.length} checklist items`);
// Add "plum" label (category6) to task
const taskForLabel = await client.api(`/planner/tasks/${newTask.id}`).get();
const taskEtag = taskForLabel['@odata.etag'];
await client
.api(`/planner/tasks/${newTask.id}`)
.header('If-Match', taskEtag)
.patch({
appliedCategories: {
category6: true,
},
});
console.log(`[Planner] Added plum label to task`);
console.log(`✓ Planner task created: "${title}" assigned to ${assigneeName}`);
return { success: true, taskId: newTask.id, title };