refactor(accounts): rename account DTOs for clarity and consistency
This commit is contained in:
@@ -1,14 +1,25 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { AccountsService } from './accounts.service'
|
||||
import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
import type { AccountsServiceCreateResponseDto, AccountsServiceDeleteResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
||||
import {
|
||||
CreateAdminPartnerAccountDto,
|
||||
UpdateAdminPartnerAccountDto,
|
||||
} from './dto/account.dto'
|
||||
import type {
|
||||
AccountsServiceCreateResponseDto,
|
||||
AccountsServiceDeleteResponseDto,
|
||||
AccountsServiceFindAllResponseDto,
|
||||
AccountsServiceFindOneResponseDto,
|
||||
AccountsServiceUpdateResponseDto,
|
||||
} from './dto/accounts-response.dto'
|
||||
|
||||
@Controller('admin/partners/:partnerId/accounts')
|
||||
export class AccountsController {
|
||||
constructor(private readonly accountsService: AccountsService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string): Promise<AccountsServiceFindAllResponseDto> {
|
||||
async findAll(
|
||||
@Param('partnerId') partnerId: string,
|
||||
): Promise<AccountsServiceFindAllResponseDto> {
|
||||
return this.accountsService.findAll(partnerId)
|
||||
}
|
||||
|
||||
@@ -20,13 +31,16 @@ export class AccountsController {
|
||||
@Post()
|
||||
async create(
|
||||
@Param('partnerId') partnerId: string,
|
||||
@Body() data: CreatePartnerAccountDto,
|
||||
@Body() data: CreateAdminPartnerAccountDto,
|
||||
): Promise<AccountsServiceCreateResponseDto> {
|
||||
return this.accountsService.create(partnerId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateAdminPartnerAccountDto,
|
||||
): Promise<AccountsServiceUpdateResponseDto> {
|
||||
return this.accountsService.update(id, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { PasswordUtil } from 'common/utils/password.util'
|
||||
import { AccountStatus, AccountType, PartnerRole } from 'generated/prisma/enums'
|
||||
import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
import {
|
||||
CreateAdminPartnerAccountDto,
|
||||
UpdateAdminPartnerAccountDto,
|
||||
} from './dto/account.dto'
|
||||
|
||||
@Injectable()
|
||||
export class AccountsService {
|
||||
@@ -38,7 +41,7 @@ export class AccountsService {
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(partnerId: string, data: CreatePartnerAccountDto) {
|
||||
async create(partnerId: string, data: CreateAdminPartnerAccountDto) {
|
||||
const { username, password } = data
|
||||
|
||||
const result = await this.prisma.$transaction(async tx => {
|
||||
@@ -69,7 +72,7 @@ export class AccountsService {
|
||||
return ResponseMapper.create(result)
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdateAccountDto) {
|
||||
async update(id: string, data: UpdateAdminPartnerAccountDto) {
|
||||
const account = await this.prisma.account.update({ where: { id }, data })
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||
import { PartnerRole } from 'generated/prisma/enums'
|
||||
|
||||
export class CreatePartnerAccountDto {
|
||||
export class CreateAdminPartnerAccountDto {
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
@UsernameFieldValidator()
|
||||
@@ -15,7 +15,9 @@ export class CreatePartnerAccountDto {
|
||||
password: string
|
||||
}
|
||||
|
||||
export class UpdateAccountDto extends PartialType(CreatePartnerAccountDto) {
|
||||
export class UpdateAdminPartnerAccountDto extends PartialType(
|
||||
CreateAdminPartnerAccountDto,
|
||||
) {
|
||||
@IsOptional()
|
||||
@IsEnum(PartnerRole)
|
||||
@ApiProperty({ enum: PartnerRole })
|
||||
|
||||
Reference in New Issue
Block a user