feat: add hourly portfolio sync history
This commit is contained in:
@@ -121,6 +121,18 @@ export class TbankAccessService {
|
||||
return work ? this.tokens.decrypt(work.connection.encryptedToken) : null;
|
||||
}
|
||||
|
||||
async onlineToken(userId: string) {
|
||||
const connection = await this.prisma.tbankConnection.findUnique({
|
||||
where: { userId },
|
||||
select: { encryptedToken: true, invalidToken: true },
|
||||
});
|
||||
if (!connection) throw new ConflictException({ code: TbankErrorCode.NotConnected });
|
||||
if (connection.invalidToken) {
|
||||
throw new BadRequestException({ code: TbankErrorCode.InvalidToken });
|
||||
}
|
||||
return this.tokens.decrypt(connection.encryptedToken);
|
||||
}
|
||||
|
||||
async publishMembership(
|
||||
attempt: TbankSyncAttempt,
|
||||
accounts: TbankAccount[],
|
||||
@@ -192,6 +204,17 @@ export class TbankAccessService {
|
||||
membershipRevision: { increment: changed ? MEMBERSHIP_REVISION_INCREMENT : UNCHANGED_MEMBERSHIP_REVISION_INCREMENT },
|
||||
},
|
||||
});
|
||||
// Value history visibility follows the confirmed membership only; a
|
||||
// failed fetch never reaches this transaction and changes nothing.
|
||||
const supportedIds = supported.map(({ id }) => id);
|
||||
await tx.tbankPortfolioValueHistory.updateMany({
|
||||
where: { userId, accountId: { in: supportedIds } },
|
||||
data: { deletedAt: null },
|
||||
});
|
||||
await tx.tbankPortfolioValueHistory.updateMany({
|
||||
where: { userId, accountId: { notIn: supportedIds }, deletedAt: null },
|
||||
data: { deletedAt: fetchedAt },
|
||||
});
|
||||
if (completeWork) {
|
||||
await tx.tbankSyncWork.update({
|
||||
where: { id: attempt.id },
|
||||
|
||||
Reference in New Issue
Block a user