2026-08-24 17:19:24 -04:00
|
|
|
/**
|
|
|
|
|
* Shared field normalization for custom card designs.
|
|
|
|
|
* Single source of truth so the create and update routes never drift.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export function pickDesignFields(body = {}) {
|
|
|
|
|
const str = (v) => (typeof v === 'string' ? v.trim() : null);
|
2026-08-24 22:01:04 -04:00
|
|
|
const int = (v) => {
|
|
|
|
|
const n = parseInt(v, 10);
|
|
|
|
|
return Number.isInteger(n) ? n : null;
|
|
|
|
|
};
|
2026-08-24 17:19:24 -04:00
|
|
|
|
|
|
|
|
const artMode = str(body.art_mode) || str(body.artMode) || 'framed';
|
2026-08-24 22:01:04 -04:00
|
|
|
const gameTarget = str(body.game_target) || str(body.gameTarget) || 'custom';
|
2026-08-24 17:19:24 -04:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
name: str(body.name),
|
|
|
|
|
manaCost: str(body.mana_cost) || str(body.manaCost),
|
|
|
|
|
cardType: str(body.card_type) || str(body.cardType),
|
|
|
|
|
rarity: str(body.rarity),
|
|
|
|
|
rulesText: str(body.rules_text) || str(body.description),
|
|
|
|
|
actions: str(body.actions),
|
|
|
|
|
flavorQuote: str(body.flavor_quote) || str(body.flavorQuote),
|
|
|
|
|
power: str(body.power),
|
|
|
|
|
toughness: str(body.toughness),
|
|
|
|
|
frameId: str(body.frame_id) || str(body.frameId) || 'classic',
|
|
|
|
|
artworkUrl: str(body.artwork_url) || str(body.artworkUrl),
|
|
|
|
|
artMode: artMode === 'fullart' ? 'fullart' : 'framed',
|
2026-08-24 22:01:04 -04:00
|
|
|
gameTarget,
|
|
|
|
|
customGameId: int(body.custom_game_id) || int(body.customGameId),
|
2026-08-24 22:13:12 -04:00
|
|
|
customFrameId: int(body.custom_frame_id) || int(body.customFrameId),
|
2026-08-24 17:19:24 -04:00
|
|
|
};
|
|
|
|
|
}
|