@steedos-labs/plugin-workflow 3.0.23 → 3.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -165,9 +165,10 @@ UUFlowManager.getSpaceUser = async function (space_id, user_id, options = {}) {
|
|
|
165
165
|
* @throws {Error} If flow not found
|
|
166
166
|
*/
|
|
167
167
|
UUFlowManager.getFlow = async function (flow_id, options = {}) {
|
|
168
|
+
let now;
|
|
168
169
|
UUFlowManager.stats.getFlow++;
|
|
169
170
|
if (process.env.STEEDOS_DEBUG) {
|
|
170
|
-
|
|
171
|
+
now = new Date().toISOString();
|
|
171
172
|
console.time('UUFlowManager.getFlow' + now);
|
|
172
173
|
}
|
|
173
174
|
|
|
@@ -4264,6 +4265,7 @@ UUFlowManager.draft_save_instance = async function (ins, userId) {
|
|
|
4264
4265
|
submitter: 1,
|
|
4265
4266
|
traces: 1,
|
|
4266
4267
|
form: 1,
|
|
4268
|
+
form_version: 1,
|
|
4267
4269
|
flow_version: 1,
|
|
4268
4270
|
space: 1,
|
|
4269
4271
|
flow: 1
|
|
@@ -4342,6 +4344,65 @@ UUFlowManager.draft_save_instance = async function (ins, userId) {
|
|
|
4342
4344
|
}
|
|
4343
4345
|
}
|
|
4344
4346
|
|
|
4347
|
+
// Convert date/datetime field values from ISO strings to Date objects
|
|
4348
|
+
// Fetch form to check field types and get name formula
|
|
4349
|
+
// For draft save, always use current form version (not historys which could be very large)
|
|
4350
|
+
const form = await db.forms.findOne(
|
|
4351
|
+
{ _id: form_id },
|
|
4352
|
+
{ projection: { 'current._id': 1, 'current.fields': 1, 'current.name_forumla': 1 } }
|
|
4353
|
+
);
|
|
4354
|
+
|
|
4355
|
+
// Draft save always uses current form version
|
|
4356
|
+
const formVersion = form?.current;
|
|
4357
|
+
|
|
4358
|
+
// Convert date strings to Date objects for proper MongoDB storage
|
|
4359
|
+
if (formVersion && formVersion.fields && values) {
|
|
4360
|
+
const convertFieldValue = (field, value) => {
|
|
4361
|
+
if (!value) return value;
|
|
4362
|
+
|
|
4363
|
+
// Handle date and datetime fields - convert ISO strings to Date objects
|
|
4364
|
+
if (field.type === 'date' || field.type === 'datetime') {
|
|
4365
|
+
// Check if value is a string (ISO date format from frontend)
|
|
4366
|
+
if (typeof value === 'string') {
|
|
4367
|
+
const dateObj = new Date(value);
|
|
4368
|
+
// Validate it's a valid date
|
|
4369
|
+
if (!isNaN(dateObj.getTime())) {
|
|
4370
|
+
return dateObj;
|
|
4371
|
+
}
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
// Handle table fields (subforms)
|
|
4375
|
+
else if (field.type === 'table' && Array.isArray(value) && field.fields) {
|
|
4376
|
+
return value.map(row => {
|
|
4377
|
+
const convertedRow = {...row};
|
|
4378
|
+
field.fields.forEach(subField => {
|
|
4379
|
+
if (row[subField.code] !== undefined) {
|
|
4380
|
+
convertedRow[subField.code] = convertFieldValue(subField, row[subField.code]);
|
|
4381
|
+
}
|
|
4382
|
+
});
|
|
4383
|
+
return convertedRow;
|
|
4384
|
+
});
|
|
4385
|
+
}
|
|
4386
|
+
|
|
4387
|
+
return value;
|
|
4388
|
+
};
|
|
4389
|
+
|
|
4390
|
+
// Process all form fields
|
|
4391
|
+
formVersion.fields.forEach(field => {
|
|
4392
|
+
if (field.type === 'section' && field.fields) {
|
|
4393
|
+
// Process section's child fields
|
|
4394
|
+
field.fields.forEach(sectionField => {
|
|
4395
|
+
if (values[sectionField.code] !== undefined) {
|
|
4396
|
+
values[sectionField.code] = convertFieldValue(sectionField, values[sectionField.code]);
|
|
4397
|
+
}
|
|
4398
|
+
});
|
|
4399
|
+
} else if (values[field.code] !== undefined) {
|
|
4400
|
+
// Process regular fields
|
|
4401
|
+
values[field.code] = convertFieldValue(field, values[field.code]);
|
|
4402
|
+
}
|
|
4403
|
+
});
|
|
4404
|
+
}
|
|
4405
|
+
|
|
4345
4406
|
setObj[key_str + 'values'] = values;
|
|
4346
4407
|
setObj[key_str + 'description'] = description;
|
|
4347
4408
|
setObj[key_str + 'judge'] = 'submitted';
|
|
@@ -4352,11 +4413,6 @@ UUFlowManager.draft_save_instance = async function (ins, userId) {
|
|
|
4352
4413
|
}
|
|
4353
4414
|
|
|
4354
4415
|
// Calculate instance name
|
|
4355
|
-
const form = await db.forms.findOne(
|
|
4356
|
-
{ _id: form_id },
|
|
4357
|
-
{ projection: { 'current.name_forumla': 1 } }
|
|
4358
|
-
);
|
|
4359
|
-
|
|
4360
4416
|
if (form?.current?.name_forumla) {
|
|
4361
4417
|
setObj.name = await UUFlowManager.getInstanceName(ins, values);
|
|
4362
4418
|
if(result !== 'upgraded'){
|