Skip to content

Commit

Permalink
Fix legacy process versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
OhKai committed Dec 3, 2024
1 parent af90b73 commit b8d838f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/management-system-v2/lib/data/legacy/_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Ability, { UnauthorizedError } from '@/lib/ability/abilityHelper';
import { ProcessMetadata, ProcessServerInput, ProcessServerInputSchema } from '../process-schema';
import { foldersMetaObject, getRootFolder } from './folders';
import { toCaslResource } from '@/lib/ability/caslAbility';
import { toCustomUTCString } from '@/lib/helpers/timeHelper';
import { fromCustomUTCString, toCustomUTCString } from '@/lib/helpers/timeHelper';

let firstInit = false;
// @ts-ignore
Expand Down Expand Up @@ -312,17 +312,20 @@ export async function addProcessVersion(processDefinitionsId: string, bpmn: stri

// save the new version in the directory of the process

await saveProcessVersion(
processDefinitionsId,
versionInformation.versionCreatedOn || toCustomUTCString(new Date()),
bpmn,
);
const versionCreatedOn = versionInformation.versionCreatedOn || toCustomUTCString(new Date());

await saveProcessVersion(processDefinitionsId, versionCreatedOn, bpmn);

// add information about the new version to the meta information and inform others about its existance
const newVersions = existingProcess.versions ? [...existingProcess.versions] : [];

//@ts-ignore
newVersions.push(versionInformation);
newVersions.push({
id: versionInformation.versionId!,
createdOn: fromCustomUTCString(versionCreatedOn),
description: versionInformation.description!,
name: versionInformation.name!,
versionBasedOn: versionInformation.versionBasedOn,
});
newVersions.sort((a, b) => (b.createdOn > a.createdOn ? 1 : -1));

await updateProcessMetaData(processDefinitionsId, { versions: newVersions });
Expand All @@ -343,7 +346,7 @@ export function getProcessVersionBpmn(processDefinitionsId: string, versionId: s
throw new Error('The version you are trying to get does not exist');
}

return getProcessVersion(processDefinitionsId, existingVersion.createdOn.toISOString());
return getProcessVersion(processDefinitionsId, toCustomUTCString(existingVersion.createdOn));
}

/** Removes information from the meta data that would not be correct after a restart */
Expand Down
7 changes: 7 additions & 0 deletions src/management-system-v2/lib/helpers/timeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,10 @@ export function toCustomUTCString(date: Date): string {

return `${year}-${month}-${day}-${hours}-${minutes}-${seconds}-${milliseconds}`;
}

export function fromCustomUTCString(dateString: string): Date {
const [year, month, day, hours, minutes, seconds, milliseconds] = dateString
.split('-')
.map(Number);
return new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds, milliseconds));
}

0 comments on commit b8d838f

Please sign in to comment.