feat: redis cache and detach image into s3
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// struct-activity.mjs
|
||||
import { logger } from '../utils/logger.mjs';
|
||||
|
||||
let clubSchema = {
|
||||
academicYear: null,
|
||||
@@ -84,21 +85,34 @@ async function applyFields(field, structuredActivityData) {
|
||||
structuredActivityData.duration.isRecurringWeekly = true;
|
||||
break;
|
||||
default:
|
||||
//console.log(`No matching case for field: fID=${field.fID}, fType=${field.fType}`);
|
||||
logger.debug(`No matching case for field: fID=${field.fID}, fType=${field.fType}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async function postProcess(structuredActivityData) {
|
||||
structuredActivityData.description = structuredActivityData.description.replaceAll("<br/>","\n");
|
||||
structuredActivityData.description = structuredActivityData.description.replaceAll("\u000B","\v");
|
||||
if (structuredActivityData.name.search("Student-led") != -1) {
|
||||
structuredActivityData.isStudentLed = true;
|
||||
} else {
|
||||
structuredActivityData.isStudentLed = false;
|
||||
}
|
||||
const grades = structuredActivityData.schedule.match(/G(\d+)-(\d+)/);
|
||||
structuredActivityData.grades.min = grades[1];
|
||||
structuredActivityData.grades.max = grades[2];
|
||||
try {
|
||||
let grades = structuredActivityData.schedule.match(/G(\d+)-(\d+)/) ||
|
||||
structuredActivityData.schedule.match(/KG(\d+)-KG(\d+)/);
|
||||
|
||||
if (!grades || grades.length < 3) {
|
||||
throw new Error('Invalid grade format in schedule');
|
||||
}
|
||||
|
||||
structuredActivityData.grades.min = grades[1];
|
||||
structuredActivityData.grades.max = grades[2];
|
||||
} catch (error) {
|
||||
logger.error(`Failed to parse grades: ${error.message}`);
|
||||
structuredActivityData.grades.min = null;
|
||||
structuredActivityData.grades.max = null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function structActivityData(rawActivityData) {
|
||||
@@ -110,35 +124,39 @@ export async function structActivityData(rawActivityData) {
|
||||
for (let i = 0; i < rowObject.fields.length; i++) {
|
||||
const field = rowObject.fields[i];
|
||||
// Optimize: no fData, just skip
|
||||
if (field.fData == null && field.fData == "") { continue; }
|
||||
if (!field.fData) { continue; }
|
||||
// Process hard cases first
|
||||
if (field.fData == "Description") {
|
||||
structuredActivityData.description = rowObject.fields[i + 1].fData;
|
||||
if (i + 1 < rowObject.fields.length) {
|
||||
structuredActivityData.description = rowObject.fields[i + 1].fData;
|
||||
}
|
||||
continue;
|
||||
} else if (field.fData == "Name To Appear On Reports"){
|
||||
let staffForReports = rowObject.fields[i + 1].fData.split(", ");
|
||||
structuredActivityData.staffForReports = staffForReports;
|
||||
} else if (field.fData == "Name To Appear On Reports") {
|
||||
if (i + 1 < rowObject.fields.length) {
|
||||
let staffForReports = rowObject.fields[i + 1].fData.split(", ");
|
||||
structuredActivityData.staffForReports = staffForReports;
|
||||
}
|
||||
} else if (field.fData == "Upload Photo") {
|
||||
structuredActivityData.photo = rowObject.fields[i + 1].fData;
|
||||
if (i + 1 < rowObject.fields.length) {
|
||||
structuredActivityData.photo = rowObject.fields[i + 1].fData;
|
||||
}
|
||||
} else if (field.fData == "Poor Weather Plan") {
|
||||
structuredActivityData.poorWeatherPlan = rowObject.fields[i + 1].fData;
|
||||
if (i + 1 < rowObject.fields.length) {
|
||||
structuredActivityData.poorWeatherPlan = rowObject.fields[i + 1].fData;
|
||||
}
|
||||
} else if (field.fData == "Activity Runs From") {
|
||||
if (rowObject.fields[i + 4].fData == "Recurring Weekly") {
|
||||
structuredActivityData.duration.isRecurringWeekly = true;
|
||||
} else {
|
||||
structuredActivityData.duration.isRecurringWeekly = false;
|
||||
if (i + 4 < rowObject.fields.length) {
|
||||
structuredActivityData.duration.isRecurringWeekly =
|
||||
rowObject.fields[i + 4].fData == "Recurring Weekly";
|
||||
}
|
||||
} else if (field.fData == "Is Pre Sign-up") {
|
||||
if (rowObject.fields[i + 1].fData == "") {
|
||||
structuredActivityData.isPreSignup = false;
|
||||
} else {
|
||||
structuredActivityData.isPreSignup = true;
|
||||
if (i + 1 < rowObject.fields.length) {
|
||||
structuredActivityData.isPreSignup = rowObject.fields[i + 1].fData !== "";
|
||||
}
|
||||
} else if (field.fData == "Semester Cost") {
|
||||
if (rowObject.fields[i + 1].fData == "") {
|
||||
structuredActivityData.semesterCost = null;
|
||||
} else {
|
||||
structuredActivityData.semesterCost = rowObject.fields[i + 1].fData
|
||||
if (i + 1 < rowObject.fields.length) {
|
||||
structuredActivityData.semesterCost =
|
||||
rowObject.fields[i + 1].fData === "" ? null : rowObject.fields[i + 1].fData;
|
||||
}
|
||||
} else {
|
||||
// Pass any other easy cases to helper function
|
||||
|
||||
Reference in New Issue
Block a user