Skip to content

Commit ea58793

Browse files
committed
chore(transformers): adjust internal resource handling
1 parent 84c1b03 commit ea58793

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

libs/resources/src/transformers/transformers.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,21 @@ export function transformFaction(faction: unknown): FACTION | null {
342342
return null;
343343
}
344344

345-
// @todo faction type is set to { type?: string | null; name?: string | null; } in some cases
345+
const factionObject = faction as { type?: string | null; name?: string | null; };
346346

347-
const hasFactionTypeWithoutName = faction.type && faction.name === null;
347+
const hasFactionTypeWithoutName = factionObject.type && factionObject.name === null;
348348
if (hasFactionTypeWithoutName) {
349-
const factionTypeStartsWithA = faction.type.toString().startsWith('A');
350-
summary.faction = factionTypeStartsWithA ? FACTION.A : FACTION.H;
351-
} else {
352-
summary.faction = faction.name;
349+
const typeUpper = factionObject.type.toString().toUpperCase();
350+
const validFactions = Object.values(FACTION).filter(f => f !== FACTION.ANY);
351+
const matchedFaction = validFactions.find(f => f.toString().toUpperCase() === typeUpper);
352+
return matchedFaction || null;
353+
}
354+
355+
if (factionObject.name) {
356+
const nameUpper = factionObject.name.toUpperCase();
357+
const validFactions = Object.values(FACTION).filter(f => f !== FACTION.ANY);
358+
const matchedFaction = validFactions.find(f => f.toString().toUpperCase() === nameUpper);
359+
return matchedFaction || null;
353360
}
354361

355362
return null

0 commit comments

Comments
 (0)