fix(ledger): 补全 getEffectivePrice 复合查询条件,修复历史价格跨资产串联 Bug
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { db } from '@/db';
|
||||
import { portfolioSnapshots, transactions, assetPricesHistory, assets, exchangeRates } from '@/db/schema';
|
||||
import { getPortfolioPositions } from './portfolio';
|
||||
import { asc, desc, eq, gte, lte, sql } from 'drizzle-orm';
|
||||
import { and, asc, desc, eq, gte, lte, sql } from 'drizzle-orm';
|
||||
import Big from 'big.js';
|
||||
|
||||
function formatDateString(date: Date): string {
|
||||
@@ -194,8 +194,12 @@ export async function getEffectivePrice(
|
||||
price: assetPricesHistory.price,
|
||||
})
|
||||
.from(assetPricesHistory)
|
||||
.where(eq(assetPricesHistory.assetId, assetId))
|
||||
.where(lte(assetPricesHistory.date, dateStr))
|
||||
.where(
|
||||
and(
|
||||
eq(assetPricesHistory.assetId, assetId),
|
||||
lte(assetPricesHistory.date, dateStr)
|
||||
)
|
||||
)
|
||||
.orderBy(desc(assetPricesHistory.date))
|
||||
.limit(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user