refactor: share prisma json codec and check progress shape (WealthLedger/backend#170) (#191)
This commit was merged in pull request #191.
This commit is contained in:
+20
-27
@@ -2,12 +2,11 @@ import { Injectable } from '@nestjs/common';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { isDeepStrictEqual } from 'node:util';
|
||||
|
||||
import type { Prisma } from '../../../../../generated/prisma/client';
|
||||
|
||||
import { TbankErrorCode } from '../../../../integrations/tbank/tbank-error-code';
|
||||
import { claimSyncWork, lockConnectionGeneration } from '../../../../integrations/tbank/tbank-sync-claim';
|
||||
import { isJoinableRunningAttempt, type TbankBond, type TbankShare, type TbankSyncAttempt } from '../../../../integrations/tbank/tbank.api';
|
||||
import { PrismaService } from '../../../../prisma/prisma.service';
|
||||
import { toJson } from '../../../../prisma/to-json';
|
||||
|
||||
const UNCHANGED_REVISION_INCREMENT = 0;
|
||||
const REVISION_INCREMENT = 1;
|
||||
@@ -172,9 +171,7 @@ export class CatalogDiscoveryRepository {
|
||||
progress: {},
|
||||
});
|
||||
if (!claimed) return false;
|
||||
const payload = JSON.parse(
|
||||
JSON.stringify(value),
|
||||
) as Prisma.InputJsonObject;
|
||||
const payload = toJson(value);
|
||||
const identity = { provider, uid: input.uid };
|
||||
await tx.tbankInstrument.upsert({
|
||||
where: { provider_uid: identity },
|
||||
@@ -197,12 +194,10 @@ export class CatalogDiscoveryRepository {
|
||||
const previous = await tx.tbankInstrument.findUniqueOrThrow({
|
||||
where: { provider_uid: identity },
|
||||
});
|
||||
const metadata = JSON.parse(
|
||||
JSON.stringify({
|
||||
...instrument,
|
||||
instrumentType: input.instrumentType,
|
||||
}),
|
||||
) as Prisma.InputJsonObject;
|
||||
const metadata = toJson({
|
||||
...instrument,
|
||||
instrumentType: input.instrumentType,
|
||||
});
|
||||
await tx.tbankInstrument.update({
|
||||
where: { provider_uid: identity },
|
||||
data: {
|
||||
@@ -341,22 +336,20 @@ export class CatalogDiscoveryRepository {
|
||||
for (const instrument of instruments) {
|
||||
// Discovery can create a minimal identity, but cannot overwrite verified metadata.
|
||||
const identity = { provider, uid: instrument.uid };
|
||||
const payload = JSON.parse(
|
||||
JSON.stringify({
|
||||
uid: instrument.uid,
|
||||
figi: instrument.figi,
|
||||
ticker: instrument.ticker,
|
||||
name: instrument.name,
|
||||
isin: instrument.isin,
|
||||
classCode: instrument.classCode,
|
||||
instrumentKind: instrument.instrumentKind,
|
||||
apiTradeAvailableFlag: instrument.apiTradeAvailableFlag,
|
||||
currency: instrument.currency,
|
||||
brand: instrument.brand
|
||||
? { logoName: instrument.brand.logoName }
|
||||
: undefined,
|
||||
}),
|
||||
) as Prisma.InputJsonObject;
|
||||
const payload = toJson({
|
||||
uid: instrument.uid,
|
||||
figi: instrument.figi,
|
||||
ticker: instrument.ticker,
|
||||
name: instrument.name,
|
||||
isin: instrument.isin,
|
||||
classCode: instrument.classCode,
|
||||
instrumentKind: instrument.instrumentKind,
|
||||
apiTradeAvailableFlag: instrument.apiTradeAvailableFlag,
|
||||
currency: instrument.currency,
|
||||
brand: instrument.brand
|
||||
? { logoName: instrument.brand.logoName }
|
||||
: undefined,
|
||||
});
|
||||
await tx.tbankInstrument.upsert({
|
||||
where: { provider_uid: identity },
|
||||
update: {},
|
||||
|
||||
Reference in New Issue
Block a user