feat: refactored check to use versioning system
This commit is contained in:
@@ -56,16 +56,17 @@ export function applyResponseVersionChanges<T = any, TLegacyData = any>({
|
||||
// Sort versions from newest to oldest (we apply backwards)
|
||||
versionsToApply.reverse();
|
||||
|
||||
const printLogs = false;
|
||||
|
||||
// Apply each version's changes
|
||||
let transformedData = input;
|
||||
for (const version of versionsToApply) {
|
||||
const changes = VersionChangeRegistryClass.getChangesForVersion({
|
||||
version,
|
||||
});
|
||||
// console.log(`Changes for version ${version}`);
|
||||
// for (const change of changes) {
|
||||
// console.log(`[${change.oldVersion}]`, change.name);
|
||||
// }
|
||||
if (printLogs) {
|
||||
console.log(`Changes for version ${version}`);
|
||||
}
|
||||
|
||||
for (const change of changes) {
|
||||
// Skip if this change doesn't affect our resource
|
||||
@@ -88,6 +89,10 @@ export function applyResponseVersionChanges<T = any, TLegacyData = any>({
|
||||
const shouldApply = targetVersion.lte(change.oldVersion);
|
||||
if (!shouldApply) continue;
|
||||
|
||||
if (printLogs) {
|
||||
console.log(`Applying change ${change.name} for version ${version}`);
|
||||
}
|
||||
|
||||
// Apply the response transformation (backward)
|
||||
transformedData = change.transformResponse({
|
||||
input: transformedData,
|
||||
|
||||
@@ -6,8 +6,10 @@ import { V0_1_CustomerChange } from "@api/customers/changes/V0_1_CustomerChange.
|
||||
// Import customer changes
|
||||
import { V0_2_CustomerChange } from "@api/customers/changes/V0_2_CustomerChange.js";
|
||||
import { V0_2_InvoicesAlwaysExpanded } from "@api/customers/changes/V0_2_InvoicesAlwaysExpanded.js";
|
||||
|
||||
// Import customer product changes
|
||||
|
||||
import { V1_1_FeaturesArrayToObject } from "../../customers/changes/V1_1_FeaturesArrayToObject.js";
|
||||
import { ApiVersion } from "../ApiVersion.js";
|
||||
import type { VersionChangeConstructor } from "./VersionChange.js";
|
||||
import { VersionChangeRegistryClass } from "./VersionChangeRegistryClass.js";
|
||||
@@ -17,7 +19,7 @@ export const V1_4_CHANGES: VersionChangeConstructor[] = [
|
||||
];
|
||||
|
||||
export const V1_2_CHANGES: VersionChangeConstructor[] = [
|
||||
// V1_1_FeaturesArrayToObject, // Transforms TO V1_1
|
||||
V1_1_FeaturesArrayToObject, // Transforms TO V1_1
|
||||
];
|
||||
|
||||
export const V1_1_CHANGES: VersionChangeConstructor[] = [
|
||||
|
||||
Reference in New Issue
Block a user