mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2026-01-08 05:02:13 +00:00
add auth docs, add eslint import/order
This commit is contained in:
@@ -9,13 +9,16 @@ import {
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common'
|
||||
import { UsersService } from '../services/users.service'
|
||||
import { CreateUserDto } from '../dto/create-user.dto'
|
||||
import { CommandBus } from '@nestjs/cqrs'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
|
||||
import { Pagination } from '../../../infrastructure/common/pagination/pagination.service'
|
||||
import { BaseAuthGuard } from '../../auth/guards'
|
||||
import { CommandBus } from '@nestjs/cqrs'
|
||||
import { CreateUserCommand } from '../../auth/use-cases'
|
||||
import { CreateUserDto } from '../dto/create-user.dto'
|
||||
import { UsersService } from '../services/users.service'
|
||||
|
||||
@ApiTags('Admin')
|
||||
@Controller('users')
|
||||
export class UsersController {
|
||||
constructor(private usersService: UsersService, private commandBus: CommandBus) {}
|
||||
@@ -25,7 +28,9 @@ export class UsersController {
|
||||
const { page, pageSize } = Pagination.getPaginationData(query)
|
||||
|
||||
const users = await this.usersService.getUsers(page, pageSize, query.name, query.email)
|
||||
|
||||
if (!users) throw new NotFoundException('Users not found')
|
||||
|
||||
return users
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { PartialType } from '@nestjs/mapped-types'
|
||||
|
||||
import { CreateUserDto } from './create-user.dto'
|
||||
|
||||
export class UpdateUserDto extends PartialType(CreateUserDto) {}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Logger,
|
||||
} from '@nestjs/common'
|
||||
import { Prisma } from '@prisma/client'
|
||||
import { addHours } from 'date-fns'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
import { Pagination } from '../../../infrastructure/common/pagination/pagination.service'
|
||||
import { PrismaService } from '../../../prisma.service'
|
||||
import {
|
||||
CreateUserInput,
|
||||
EntityWithPaginationType,
|
||||
@@ -5,17 +17,6 @@ import {
|
||||
UserViewType,
|
||||
VerificationWithUser,
|
||||
} from '../../../types/types'
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Logger,
|
||||
} from '@nestjs/common'
|
||||
import { addHours } from 'date-fns'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { PrismaService } from '../../../prisma.service'
|
||||
import { Prisma } from '@prisma/client'
|
||||
import { Pagination } from '../../../infrastructure/common/pagination/pagination.service'
|
||||
|
||||
@Injectable()
|
||||
export class UsersRepository {
|
||||
@@ -52,6 +53,7 @@ export class UsersRepository {
|
||||
take: itemsPerPage,
|
||||
}),
|
||||
])
|
||||
|
||||
return Pagination.transformPaginationData(res, { currentPage, itemsPerPage })
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
@@ -100,6 +102,7 @@ export class UsersRepository {
|
||||
id,
|
||||
},
|
||||
})
|
||||
|
||||
return result.isDeleted
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
@@ -115,6 +118,7 @@ export class UsersRepository {
|
||||
async deleteAllUsers(): Promise<number> {
|
||||
try {
|
||||
const result = await this.prisma.user.deleteMany()
|
||||
|
||||
return result.count
|
||||
} catch (e) {
|
||||
this.logger.error(e?.message || e)
|
||||
@@ -128,6 +132,7 @@ export class UsersRepository {
|
||||
where: { id },
|
||||
include,
|
||||
})
|
||||
|
||||
if (!user) {
|
||||
return null
|
||||
}
|
||||
@@ -154,6 +159,7 @@ export class UsersRepository {
|
||||
if (!user) {
|
||||
return null
|
||||
}
|
||||
|
||||
return user
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
@@ -176,9 +182,11 @@ export class UsersRepository {
|
||||
user: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!verification) {
|
||||
return null
|
||||
}
|
||||
|
||||
return verification
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
@@ -206,6 +214,7 @@ export class UsersRepository {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return result.isEmailVerified
|
||||
} catch (e) {
|
||||
this.logger.error(e?.message || e)
|
||||
@@ -276,9 +285,11 @@ export class UsersRepository {
|
||||
user: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!resetPassword) {
|
||||
return null
|
||||
}
|
||||
|
||||
return resetPassword.user
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
@@ -335,9 +346,11 @@ export class UsersRepository {
|
||||
user: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!revokedToken.user) {
|
||||
return null
|
||||
}
|
||||
|
||||
return revokedToken.user
|
||||
} catch (e) {
|
||||
this.logger.error(e?.message || e)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Injectable, Logger } from '@nestjs/common'
|
||||
import { UsersRepository } from '../infrastructure/users.repository'
|
||||
import * as bcrypt from 'bcrypt'
|
||||
import { MailerService } from '@nestjs-modules/mailer'
|
||||
import * as bcrypt from 'bcrypt'
|
||||
|
||||
import { UsersRepository } from '../infrastructure/users.repository'
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -23,6 +24,7 @@ export class UsersService {
|
||||
|
||||
async deleteAllUsers(): Promise<{ deleted: number }> {
|
||||
const deleted = await this.usersRepository.deleteAllUsers()
|
||||
|
||||
return { deleted }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { UsersService } from './services/users.service'
|
||||
import { CqrsModule } from '@nestjs/cqrs'
|
||||
|
||||
import { UsersController } from './api/users.controller'
|
||||
import { UsersRepository } from './infrastructure/users.repository'
|
||||
import { CqrsModule } from '@nestjs/cqrs'
|
||||
import { UsersService } from './services/users.service'
|
||||
|
||||
@Module({
|
||||
imports: [CqrsModule],
|
||||
|
||||
Reference in New Issue
Block a user