chore: strengthen backend eslint profile
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { isDeepStrictEqual } from 'node:util';
|
||||
|
||||
import type { Prisma } from '../../../../../generated/prisma/client';
|
||||
|
||||
import { PrismaService } from '../../../../prisma/prisma.service';
|
||||
|
||||
export type ForecastSourceVersion = {
|
||||
instrumentUid: string;
|
||||
source: string;
|
||||
kind: string;
|
||||
rangeKey: string;
|
||||
dataRevision: number;
|
||||
fetchedAt: Date;
|
||||
instrumentUid: string;
|
||||
kind: string;
|
||||
rangeKey: string;
|
||||
source: string;
|
||||
};
|
||||
const forecastSourceReadBatchSize = 100;
|
||||
|
||||
@@ -18,15 +20,15 @@ export class ForecastRepository {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
resolve(input: {
|
||||
userId: string;
|
||||
revision: string;
|
||||
membershipRevision: number;
|
||||
scopeKey: string;
|
||||
candidate?: object;
|
||||
membershipRevision: number;
|
||||
portfolioProjection: string;
|
||||
portfolios: { accountId: string; dataRevision: number }[];
|
||||
revision: string;
|
||||
scopeKey: string;
|
||||
sources: ForecastSourceVersion[];
|
||||
timestamps: { resourceKey: string; at: string }[];
|
||||
timestamps: { at: string; resourceKey: string }[];
|
||||
userId: string;
|
||||
}) {
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
const owner = { userId: input.userId, revision: input.revision };
|
||||
@@ -54,9 +56,9 @@ export class ForecastRepository {
|
||||
where: { userId_revision_scopeKey: key },
|
||||
});
|
||||
const fallback =
|
||||
previous?.membershipRevision === input.membershipRevision
|
||||
? previous
|
||||
: null;
|
||||
previous?.membershipRevision === input.membershipRevision ?
|
||||
previous :
|
||||
null;
|
||||
if (!input.candidate) return fallback;
|
||||
const portfolios = await tx.tbankPortfolio.findMany({
|
||||
where: {
|
||||
@@ -74,15 +76,16 @@ export class ForecastRepository {
|
||||
row.dataRevision === expected.dataRevision,
|
||||
),
|
||||
)
|
||||
)
|
||||
) {
|
||||
return fallback;
|
||||
}
|
||||
// Four identity parameters per source: stay below SQLite's parameter limit.
|
||||
const sources: ForecastSourceVersion[] = [];
|
||||
for (
|
||||
let offset = 0;
|
||||
offset < input.sources.length;
|
||||
offset += forecastSourceReadBatchSize
|
||||
)
|
||||
) {
|
||||
sources.push(
|
||||
...(await tx.tbankInstrumentSource.findMany({
|
||||
where: {
|
||||
@@ -106,6 +109,7 @@ export class ForecastRepository {
|
||||
},
|
||||
})),
|
||||
);
|
||||
}
|
||||
if (
|
||||
input.sources.some(
|
||||
(expected) =>
|
||||
@@ -119,8 +123,9 @@ export class ForecastRepository {
|
||||
row.fetchedAt.valueOf() === expected.fetchedAt.valueOf(),
|
||||
),
|
||||
)
|
||||
)
|
||||
) {
|
||||
return fallback;
|
||||
}
|
||||
const revisions = JSON.parse(
|
||||
JSON.stringify({
|
||||
portfolioProjection: input.portfolioProjection,
|
||||
@@ -133,8 +138,9 @@ export class ForecastRepository {
|
||||
fallback &&
|
||||
isDeepStrictEqual(fallback.dependencyRevisions, revisions) &&
|
||||
isDeepStrictEqual(fallback.sourceTimestamps, timestamps)
|
||||
)
|
||||
) {
|
||||
return fallback;
|
||||
}
|
||||
const data = {
|
||||
membershipRevision: input.membershipRevision,
|
||||
payload: JSON.parse(
|
||||
|
||||
Reference in New Issue
Block a user