42 lines
1.2 KiB
TypeScript
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,
|
|
};
|
|
}
|
|
}
|