refactor: move totalvnd into meta.invested for extensibility

Portfolio schema now uses meta object: { currency, assets, meta: { invested } }.
Migrates old totalvnd field automatically on load. The meta object provides
a clean place for future per-user metadata without polluting the top level.
This commit is contained in:
2026-04-14 17:33:11 +07:00
parent 0d4feb9ef8
commit a34c1cf85f
6 changed files with 32 additions and 30 deletions

View File

@@ -62,12 +62,12 @@ describe("trading/handlers", () => {
expect(ctx.replies[0]).toContain("5.000.000 VND");
});
it("tracks totalvnd", async () => {
it("tracks meta.invested", async () => {
const ctx = makeCtx("1000000");
await handleTopup(ctx, db);
const { getPortfolio } = await import("../../../src/modules/trading/portfolio.js");
const p = await getPortfolio(db, 42);
expect(p.totalvnd).toBe(1000000);
expect(p.meta.invested).toBe(1000000);
expect(p.currency.VND).toBe(1000000);
});
@@ -89,7 +89,7 @@ describe("trading/handlers", () => {
const { emptyPortfolio } = await import("../../../src/modules/trading/portfolio.js");
const p = emptyPortfolio();
p.currency.VND = 5000000;
p.totalvnd = 5000000;
p.meta.invested = 5000000;
await savePortfolio(db, 42, p);
const ctx = makeCtx("10 TCB");
@@ -169,7 +169,7 @@ describe("trading/handlers", () => {
const p = emptyPortfolio();
p.currency.VND = 5000000;
p.assets.TCB = 10;
p.totalvnd = 10000000;
p.meta.invested = 10000000;
await savePortfolio(db, 42, p);
const ctx = makeCtx("");