mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 09:58:12 +00:00
refactor( iam ): remove prisma.user references from passenger-side services
This commit is contained in:
@@ -73,6 +73,7 @@ describe('VerifaydaService (OIDC, client-callback)', () => {
|
||||
service = new VerifaydaService(
|
||||
buildConfigService(cfg),
|
||||
prisma as unknown as PrismaService,
|
||||
{ query: jest.fn().mockResolvedValue([]) } as any,
|
||||
);
|
||||
(global as any).fetch = jest.fn();
|
||||
});
|
||||
@@ -126,6 +127,7 @@ describe('VerifaydaService (OIDC, client-callback)', () => {
|
||||
const disabledService = new VerifaydaService(
|
||||
buildConfigService(buildConfig({ enabled: false })),
|
||||
prisma as unknown as PrismaService,
|
||||
{ query: jest.fn().mockResolvedValue([]) } as any,
|
||||
);
|
||||
await expect(
|
||||
disabledService.startVerification({ purpose: 'PURCHASE' }),
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { InjectDataSource } from '@nestjs/typeorm';
|
||||
import { DataSource } from 'typeorm';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import { PrismaService } from '../../common/prisma.service';
|
||||
import { FaydaConfig, FaydaPlatform } from '../../config/fayda.config';
|
||||
@@ -85,6 +87,7 @@ export class VerifaydaService {
|
||||
constructor(
|
||||
private readonly config: ConfigService,
|
||||
private readonly prisma: PrismaService,
|
||||
@InjectDataSource() private readonly dataSource: DataSource,
|
||||
) {
|
||||
const fayda = this.config.get<FaydaConfig>('fayda');
|
||||
if (!fayda) {
|
||||
@@ -438,23 +441,16 @@ export class VerifaydaService {
|
||||
|
||||
const iamUserId = session.iamUserId;
|
||||
if (iamUserId && session.saveToAccount) {
|
||||
const passenger = await this.prisma.passenger.findUnique({
|
||||
where: { iamUserId },
|
||||
select: { userId: true },
|
||||
});
|
||||
const localUserId = passenger?.userId;
|
||||
if (!localUserId) return;
|
||||
const conflicts = await this.dataSource.query<{ id: string }[]>(
|
||||
`SELECT id FROM iam.users WHERE metadata->>'faydaSub' = $1 AND id != $2 LIMIT 1`,
|
||||
[normalized.sub, iamUserId],
|
||||
);
|
||||
if (conflicts.length) throw new FaydaIdentityConflictException();
|
||||
|
||||
const conflict = await this.prisma.user.findFirst({
|
||||
where: { faydaSub: normalized.sub, NOT: { id: localUserId } },
|
||||
select: { id: true },
|
||||
});
|
||||
if (conflict) throw new FaydaIdentityConflictException();
|
||||
|
||||
await this.prisma.user.update({
|
||||
where: { id: localUserId },
|
||||
data: { faydaVerified: true, faydaVerifiedAt: new Date(), faydaSub: normalized.sub },
|
||||
});
|
||||
await this.dataSource.query(
|
||||
`UPDATE iam.users SET metadata = COALESCE(metadata, '{}') || $1::jsonb WHERE id = $2`,
|
||||
[JSON.stringify({ faydaSub: normalized.sub, faydaVerified: true, faydaVerifiedAt: new Date().toISOString() }), iamUserId],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user