velody/backend/src/modules/users/account.service.ts
2026-06-24 07:36:57 +02:00

42 lines
1.2 KiB
TypeScript

import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../infrastructure/database/prisma.service';
import { DeviceAuthService } from '../auth/device-auth.service';
import { CurrentAccountResponseDto } from './account.dto';
@Injectable()
export class AccountService {
constructor(
private readonly prismaService: PrismaService,
private readonly deviceAuthService: DeviceAuthService,
) {}
async getCurrentAccount(): Promise<CurrentAccountResponseDto> {
const authenticatedDevice =
this.deviceAuthService.getAuthenticatedDeviceOrThrow();
const account = await this.prismaService.user.findUnique({
where: {
id: authenticatedDevice.userId,
},
select: {
id: true,
accountKind: true,
accountStatus: true,
libraryNamespace: true,
},
});
if (!account) {
throw new NotFoundException('Account not found');
}
return {
accountId: account.id,
accountKind: account.accountKind,
accountStatus: account.accountStatus,
libraryNamespace: account.libraryNamespace,
currentDeviceId: authenticatedDevice.deviceId,
};
}
}