| 1 | import { publicCharacter } from "../characters/service.js"; |
| 2 | |
| 3 | export function buildAccountDataExport ({ stateDb }, account) |
| 4 | { |
| 5 | const characterRows = stateDb.listCharacters(account.account_id); |
| 6 | const exportedCharacters = characterRows.map((row) => |
| 7 | { |
| 8 | const bag = stateDb.getBag(row.character_id); |
| 9 | const skills = stateDb.getSkills(row.character_id); |
| 10 | const spells = stateDb.getSpells(row.character_id); |
| 11 | return { |
| 12 | ...publicCharacter(row), |
| 13 | inventory: bag?.inventory ?? [], |
| 14 | equipment: bag?.equipment ?? {}, |
| 15 | currency: bag?.currency ?? 0, |
| 16 | vault: bag?.vault ?? [], |
| 17 | vaultReserved: bag?.vaultReserved ?? [], |
| 18 | skills, |
| 19 | spells |
| 20 | }; |
| 21 | }); |
| 22 | |
| 23 | return { |
| 24 | exported_at: new Date().toISOString(), |
| 25 | account: { |
| 26 | authSubject: account.auth_subject, |
| 27 | username: account.username ?? null, |
| 28 | email: account.email ?? null, |
| 29 | isAdmin: !!account.is_admin |
| 30 | }, |
| 31 | characters: exportedCharacters, |
| 32 | inheritance: stateDb.getInheritance(account.account_id) |
| 33 | }; |
| 34 | } |