38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import {
|
|
Args, Mutation, Query, Resolver,
|
|
} from '@nestjs/graphql';
|
|
|
|
import { EnableTotpInput } from '@/src/module/auth/totp/inputs/enable-totp.input';
|
|
import { TotpModel } from '@/src/module/auth/totp/models/totp.model';
|
|
import { Authorization } from '@/src/shared/decorators/auth.decorator';
|
|
import { Authorized } from '@/src/shared/decorators/authorized.decorator';
|
|
import { User } from '@prisma/generated';
|
|
|
|
import { TotpService } from './totp.service';
|
|
|
|
@Resolver('Totp')
|
|
export class TotpResolver {
|
|
constructor(private readonly totpService: TotpService) {}
|
|
|
|
@Authorization()
|
|
@Query(() => TotpModel, { name: 'generateTotpSecret' })
|
|
public async generate(@Authorized() user: User) {
|
|
return this.totpService.generate(user);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => Boolean, { name: 'enableTotp' })
|
|
public async enable(
|
|
@Authorized() user: User,
|
|
@Args('data') input: EnableTotpInput,
|
|
) {
|
|
return this.totpService.enable(user, input);
|
|
}
|
|
|
|
@Authorization()
|
|
@Mutation(() => Boolean, { name: 'disableTotp' })
|
|
public async disable(@Authorized() user: User) {
|
|
return this.totpService.disable(user);
|
|
}
|
|
}
|