refactor(accounts): rename account DTOs for clarity and consistency
This commit is contained in:
@@ -1,8 +1,16 @@
|
|||||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { AccountsService } from './accounts.service'
|
import { AccountsService } from './accounts.service'
|
||||||
import { CreateConsumerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
import {
|
||||||
import type { AccountsServiceCreateResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
CreateAdminConsumerAccountDto,
|
||||||
|
UpdateAdminConsumerAccountDto,
|
||||||
|
} from './dto/account.dto'
|
||||||
|
import type {
|
||||||
|
AccountsServiceCreateResponseDto,
|
||||||
|
AccountsServiceFindAllResponseDto,
|
||||||
|
AccountsServiceFindOneResponseDto,
|
||||||
|
AccountsServiceUpdateResponseDto,
|
||||||
|
} from './dto/accounts-response.dto'
|
||||||
|
|
||||||
@ApiTags('AdminConsumerAccounts')
|
@ApiTags('AdminConsumerAccounts')
|
||||||
@Controller('admin/consumers/:consumerId/accounts')
|
@Controller('admin/consumers/:consumerId/accounts')
|
||||||
@@ -10,7 +18,9 @@ export class AccountsController {
|
|||||||
constructor(private readonly accountsService: AccountsService) {}
|
constructor(private readonly accountsService: AccountsService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(@Param('consumerId') consumerId: string): Promise<AccountsServiceFindAllResponseDto> {
|
async findAll(
|
||||||
|
@Param('consumerId') consumerId: string,
|
||||||
|
): Promise<AccountsServiceFindAllResponseDto> {
|
||||||
return this.accountsService.findAll(consumerId)
|
return this.accountsService.findAll(consumerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,13 +32,16 @@ export class AccountsController {
|
|||||||
@Post()
|
@Post()
|
||||||
async create(
|
async create(
|
||||||
@Param('consumerId') consumerId: string,
|
@Param('consumerId') consumerId: string,
|
||||||
@Body() data: CreateConsumerAccountDto,
|
@Body() data: CreateAdminConsumerAccountDto,
|
||||||
): Promise<AccountsServiceCreateResponseDto> {
|
): Promise<AccountsServiceCreateResponseDto> {
|
||||||
return this.accountsService.create(consumerId, data)
|
return this.accountsService.create(consumerId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
|
async update(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: UpdateAdminConsumerAccountDto,
|
||||||
|
): Promise<AccountsServiceUpdateResponseDto> {
|
||||||
return this.accountsService.update(id, data)
|
return this.accountsService.update(id, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import { AccountStatus, AccountType } from '@/generated/prisma/enums'
|
|||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { CreateConsumerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
import {
|
||||||
|
CreateAdminConsumerAccountDto,
|
||||||
|
UpdateAdminConsumerAccountDto,
|
||||||
|
} from './dto/account.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
@@ -70,7 +73,7 @@ export class AccountsService {
|
|||||||
return ResponseMapper.single(account)
|
return ResponseMapper.single(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(consumerId: string, data: CreateConsumerAccountDto) {
|
async create(consumerId: string, data: CreateAdminConsumerAccountDto) {
|
||||||
const account = await this.prisma.consumerAccount.create({
|
const account = await this.prisma.consumerAccount.create({
|
||||||
data: {
|
data: {
|
||||||
role: data.role,
|
role: data.role,
|
||||||
@@ -95,7 +98,7 @@ export class AccountsService {
|
|||||||
return ResponseMapper.create(account)
|
return ResponseMapper.create(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: UpdateAccountDto) {
|
async update(id: string, data: UpdateAdminConsumerAccountDto) {
|
||||||
const account = await this.prisma.account.update({ where: { id }, data })
|
const account = await this.prisma.account.update({ where: { id }, data })
|
||||||
return ResponseMapper.update(account)
|
return ResponseMapper.update(account)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ApiProperty, PartialType } from '@nestjs/swagger'
|
|||||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||||
import { AccountStatus, ConsumerRole } from 'generated/prisma/enums'
|
import { AccountStatus, ConsumerRole } from 'generated/prisma/enums'
|
||||||
|
|
||||||
export class CreateConsumerAccountDto {
|
export class CreateAdminConsumerAccountDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@UsernameFieldValidator()
|
@UsernameFieldValidator()
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@@ -19,7 +19,9 @@ export class CreateConsumerAccountDto {
|
|||||||
role: ConsumerRole
|
role: ConsumerRole
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateAccountDto extends PartialType(CreateConsumerAccountDto) {
|
export class UpdateAdminConsumerAccountDto extends PartialType(
|
||||||
|
CreateAdminConsumerAccountDto,
|
||||||
|
) {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(AccountStatus)
|
@IsEnum(AccountStatus)
|
||||||
@ApiProperty({ enum: AccountStatus })
|
@ApiProperty({ enum: AccountStatus })
|
||||||
|
|||||||
@@ -1,14 +1,25 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
||||||
import { AccountsService } from './accounts.service'
|
import { AccountsService } from './accounts.service'
|
||||||
import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
import {
|
||||||
import type { AccountsServiceCreateResponseDto, AccountsServiceDeleteResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
CreateAdminPartnerAccountDto,
|
||||||
|
UpdateAdminPartnerAccountDto,
|
||||||
|
} from './dto/account.dto'
|
||||||
|
import type {
|
||||||
|
AccountsServiceCreateResponseDto,
|
||||||
|
AccountsServiceDeleteResponseDto,
|
||||||
|
AccountsServiceFindAllResponseDto,
|
||||||
|
AccountsServiceFindOneResponseDto,
|
||||||
|
AccountsServiceUpdateResponseDto,
|
||||||
|
} from './dto/accounts-response.dto'
|
||||||
|
|
||||||
@Controller('admin/partners/:partnerId/accounts')
|
@Controller('admin/partners/:partnerId/accounts')
|
||||||
export class AccountsController {
|
export class AccountsController {
|
||||||
constructor(private readonly accountsService: AccountsService) {}
|
constructor(private readonly accountsService: AccountsService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(@Param('partnerId') partnerId: string): Promise<AccountsServiceFindAllResponseDto> {
|
async findAll(
|
||||||
|
@Param('partnerId') partnerId: string,
|
||||||
|
): Promise<AccountsServiceFindAllResponseDto> {
|
||||||
return this.accountsService.findAll(partnerId)
|
return this.accountsService.findAll(partnerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,13 +31,16 @@ export class AccountsController {
|
|||||||
@Post()
|
@Post()
|
||||||
async create(
|
async create(
|
||||||
@Param('partnerId') partnerId: string,
|
@Param('partnerId') partnerId: string,
|
||||||
@Body() data: CreatePartnerAccountDto,
|
@Body() data: CreateAdminPartnerAccountDto,
|
||||||
): Promise<AccountsServiceCreateResponseDto> {
|
): Promise<AccountsServiceCreateResponseDto> {
|
||||||
return this.accountsService.create(partnerId, data)
|
return this.accountsService.create(partnerId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@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)
|
return this.accountsService.update(id, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import { Injectable } from '@nestjs/common'
|
|||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { PasswordUtil } from 'common/utils/password.util'
|
import { PasswordUtil } from 'common/utils/password.util'
|
||||||
import { AccountStatus, AccountType, PartnerRole } from 'generated/prisma/enums'
|
import { AccountStatus, AccountType, PartnerRole } from 'generated/prisma/enums'
|
||||||
import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
import {
|
||||||
|
CreateAdminPartnerAccountDto,
|
||||||
|
UpdateAdminPartnerAccountDto,
|
||||||
|
} from './dto/account.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
@@ -38,7 +41,7 @@ export class AccountsService {
|
|||||||
return ResponseMapper.single(account)
|
return ResponseMapper.single(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(partnerId: string, data: CreatePartnerAccountDto) {
|
async create(partnerId: string, data: CreateAdminPartnerAccountDto) {
|
||||||
const { username, password } = data
|
const { username, password } = data
|
||||||
|
|
||||||
const result = await this.prisma.$transaction(async tx => {
|
const result = await this.prisma.$transaction(async tx => {
|
||||||
@@ -69,7 +72,7 @@ export class AccountsService {
|
|||||||
return ResponseMapper.create(result)
|
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 })
|
const account = await this.prisma.account.update({ where: { id }, data })
|
||||||
return ResponseMapper.update(account)
|
return ResponseMapper.update(account)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ApiProperty, PartialType } from '@nestjs/swagger'
|
|||||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||||
import { PartnerRole } from 'generated/prisma/enums'
|
import { PartnerRole } from 'generated/prisma/enums'
|
||||||
|
|
||||||
export class CreatePartnerAccountDto {
|
export class CreateAdminPartnerAccountDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ApiProperty({})
|
@ApiProperty({})
|
||||||
@UsernameFieldValidator()
|
@UsernameFieldValidator()
|
||||||
@@ -15,7 +15,9 @@ export class CreatePartnerAccountDto {
|
|||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateAccountDto extends PartialType(CreatePartnerAccountDto) {
|
export class UpdateAdminPartnerAccountDto extends PartialType(
|
||||||
|
CreateAdminPartnerAccountDto,
|
||||||
|
) {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(PartnerRole)
|
@IsEnum(PartnerRole)
|
||||||
@ApiProperty({ enum: PartnerRole })
|
@ApiProperty({ enum: PartnerRole })
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { AccountsService } from './accounts.service'
|
import { AccountsService } from './accounts.service'
|
||||||
import { CreateAccountDto, UpdateAccountDto } from './dto/account.dto'
|
import { CreateAdminAccountDto, UpdateAdminAccountDto } from './dto/account.dto'
|
||||||
import type { AccountsServiceCreateResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
import type {
|
||||||
|
AccountsServiceCreateResponseDto,
|
||||||
|
AccountsServiceFindAllResponseDto,
|
||||||
|
AccountsServiceFindOneResponseDto,
|
||||||
|
AccountsServiceUpdateResponseDto,
|
||||||
|
} from './dto/accounts-response.dto'
|
||||||
|
|
||||||
@ApiTags('accounts')
|
@ApiTags('accounts')
|
||||||
@Controller('admin/users/:userId/accounts')
|
@Controller('admin/users/:userId/accounts')
|
||||||
@@ -10,7 +15,9 @@ export class AccountsController {
|
|||||||
constructor(private readonly accountsService: AccountsService) {}
|
constructor(private readonly accountsService: AccountsService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(@Param('userId') userId: string): Promise<AccountsServiceFindAllResponseDto> {
|
async findAll(
|
||||||
|
@Param('userId') userId: string,
|
||||||
|
): Promise<AccountsServiceFindAllResponseDto> {
|
||||||
return this.accountsService.findAll(userId)
|
return this.accountsService.findAll(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,12 +27,18 @@ export class AccountsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Param('userId') userId: string, @Body() data: CreateAccountDto): Promise<AccountsServiceCreateResponseDto> {
|
async create(
|
||||||
|
@Param('userId') userId: string,
|
||||||
|
@Body() data: CreateAdminAccountDto,
|
||||||
|
): Promise<AccountsServiceCreateResponseDto> {
|
||||||
return this.accountsService.create(userId, data)
|
return this.accountsService.create(userId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
|
async update(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: UpdateAdminAccountDto,
|
||||||
|
): Promise<AccountsServiceUpdateResponseDto> {
|
||||||
return this.accountsService.update(id, data)
|
return this.accountsService.update(id, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { CreateAccountDto, UpdateAccountDto } from './dto/account.dto'
|
import { CreateAdminAccountDto, UpdateAdminAccountDto } from './dto/account.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
@@ -23,7 +23,7 @@ export class AccountsService {
|
|||||||
return ResponseMapper.single({})
|
return ResponseMapper.single({})
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(userId: string, data: CreateAccountDto) {
|
async create(userId: string, data: CreateAdminAccountDto) {
|
||||||
// const account = await this.prisma.account.create({
|
// const account = await this.prisma.account.create({
|
||||||
// data: {
|
// data: {
|
||||||
// ...data,
|
// ...data,
|
||||||
@@ -39,7 +39,7 @@ export class AccountsService {
|
|||||||
return ResponseMapper.create({})
|
return ResponseMapper.create({})
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: UpdateAccountDto) {
|
async update(id: string, data: UpdateAdminAccountDto) {
|
||||||
const account = await this.prisma.account.update({ where: { id }, data })
|
const account = await this.prisma.account.update({ where: { id }, data })
|
||||||
return ResponseMapper.update(account)
|
return ResponseMapper.update(account)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ApiProperty, PartialType } from '@nestjs/swagger'
|
|||||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||||
import { AccountStatus, AccountType } from 'generated/prisma/enums'
|
import { AccountStatus, AccountType } from 'generated/prisma/enums'
|
||||||
|
|
||||||
export class CreateAccountDto {
|
export class CreateAdminAccountDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@UsernameFieldValidator()
|
@UsernameFieldValidator()
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@@ -19,7 +19,7 @@ export class CreateAccountDto {
|
|||||||
type: AccountType
|
type: AccountType
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateAccountDto extends PartialType(CreateAccountDto) {
|
export class UpdateAdminAccountDto extends PartialType(CreateAdminAccountDto) {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(AccountStatus)
|
@IsEnum(AccountStatus)
|
||||||
@ApiProperty({ enum: AccountStatus })
|
@ApiProperty({ enum: AccountStatus })
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
|||||||
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
|
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { AccountsService } from './accounts.service'
|
import { AccountsService } from './accounts.service'
|
||||||
import { UpdateAccountDto } from './dto/account.dto'
|
import { UpdateConsumerAccountDto } from './dto/account.dto'
|
||||||
import type { AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
import type {
|
||||||
|
AccountsServiceFindAllResponseDto,
|
||||||
|
AccountsServiceFindOneResponseDto,
|
||||||
|
AccountsServiceUpdateResponseDto,
|
||||||
|
} from './dto/accounts-response.dto'
|
||||||
|
|
||||||
@ApiTags('ConsumerAccounts')
|
@ApiTags('ConsumerAccounts')
|
||||||
@Controller('consumer/accounts')
|
@Controller('consumer/accounts')
|
||||||
@@ -11,7 +15,9 @@ export class AccountsController {
|
|||||||
constructor(private readonly accountsService: AccountsService) {}
|
constructor(private readonly accountsService: AccountsService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(@TokenAccount('userId') consumerId: string): Promise<AccountsServiceFindAllResponseDto> {
|
async findAll(
|
||||||
|
@TokenAccount('userId') consumerId: string,
|
||||||
|
): Promise<AccountsServiceFindAllResponseDto> {
|
||||||
return this.accountsService.findAll(consumerId)
|
return this.accountsService.findAll(consumerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +35,10 @@ export class AccountsController {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
|
async update(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: UpdateConsumerAccountDto,
|
||||||
|
): Promise<AccountsServiceUpdateResponseDto> {
|
||||||
return this.accountsService.update(id, data)
|
return this.accountsService.update(id, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ConsumerRole } from '@/generated/prisma/enums'
|
|||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { UpdateAccountDto } from './dto/account.dto'
|
import { UpdateConsumerAccountDto } from './dto/account.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
@@ -91,7 +91,7 @@ export class AccountsService {
|
|||||||
// return ResponseMapper.create(account)
|
// return ResponseMapper.create(account)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
async update(id: string, data: UpdateAccountDto) {
|
async update(id: string, data: UpdateConsumerAccountDto) {
|
||||||
const account = await this.prisma.account.update({ where: { id }, data })
|
const account = await this.prisma.account.update({ where: { id }, data })
|
||||||
return ResponseMapper.update(account)
|
return ResponseMapper.update(account)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class CreateConsumerAccountDto {
|
|||||||
// role: ConsumerRole
|
// role: ConsumerRole
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateAccountDto extends PartialType(CreateConsumerAccountDto) {
|
export class UpdateConsumerAccountDto extends PartialType(CreateConsumerAccountDto) {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(AccountStatus)
|
@IsEnum(AccountStatus)
|
||||||
@ApiProperty({ enum: AccountStatus })
|
@ApiProperty({ enum: AccountStatus })
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
|||||||
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
|
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { AccountsService } from './accounts.service'
|
import { AccountsService } from './accounts.service'
|
||||||
import { UpdateAccountDto } from './dto/account.dto'
|
import { UpdatePartnerAccountDto } from './dto/account.dto'
|
||||||
import type { AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
import type {
|
||||||
|
AccountsServiceFindAllResponseDto,
|
||||||
|
AccountsServiceFindOneResponseDto,
|
||||||
|
AccountsServiceUpdateResponseDto,
|
||||||
|
} from './dto/accounts-response.dto'
|
||||||
|
|
||||||
@ApiTags('PartnerAccounts')
|
@ApiTags('PartnerAccounts')
|
||||||
@Controller('partner/accounts')
|
@Controller('partner/accounts')
|
||||||
@@ -11,7 +15,9 @@ export class AccountsController {
|
|||||||
constructor(private readonly service: AccountsService) {}
|
constructor(private readonly service: AccountsService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(@TokenAccount('userId') consumerId: string): Promise<AccountsServiceFindAllResponseDto> {
|
async findAll(
|
||||||
|
@TokenAccount('userId') consumerId: string,
|
||||||
|
): Promise<AccountsServiceFindAllResponseDto> {
|
||||||
return this.service.findAll(consumerId)
|
return this.service.findAll(consumerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +35,10 @@ export class AccountsController {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
|
async update(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: UpdatePartnerAccountDto,
|
||||||
|
): Promise<AccountsServiceUpdateResponseDto> {
|
||||||
return this.service.update(id, data)
|
return this.service.update(id, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { AccountStatus, AccountType } from '@/generated/prisma/enums'
|
|||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
import { CreatePartnerAccountDto, UpdatePartnerAccountDto } from './dto/account.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
@@ -73,7 +73,7 @@ export class AccountsService {
|
|||||||
return ResponseMapper.create(account)
|
return ResponseMapper.create(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: UpdateAccountDto) {
|
async update(id: string, data: UpdatePartnerAccountDto) {
|
||||||
const account = await this.prisma.account.update({ where: { id }, data })
|
const account = await this.prisma.account.update({ where: { id }, data })
|
||||||
return ResponseMapper.update(account)
|
return ResponseMapper.update(account)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class CreatePartnerAccountDto {
|
|||||||
role: PartnerRole
|
role: PartnerRole
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateAccountDto extends PartialType(CreatePartnerAccountDto) {
|
export class UpdatePartnerAccountDto extends PartialType(CreatePartnerAccountDto) {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(AccountStatus)
|
@IsEnum(AccountStatus)
|
||||||
@ApiProperty({ enum: AccountStatus })
|
@ApiProperty({ enum: AccountStatus })
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
|||||||
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
|
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { AccountsService } from './accounts.service'
|
import { AccountsService } from './accounts.service'
|
||||||
import { UpdateAccountDto } from './dto/account.dto'
|
import { UpdatePartnerConsumerAccountDto } from './dto/account.dto'
|
||||||
import type { AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
import type {
|
||||||
|
AccountsServiceFindAllResponseDto,
|
||||||
|
AccountsServiceFindOneResponseDto,
|
||||||
|
AccountsServiceUpdateResponseDto,
|
||||||
|
} from './dto/accounts-response.dto'
|
||||||
|
|
||||||
@ApiTags('PartnerConsumerAccounts')
|
@ApiTags('PartnerConsumerAccounts')
|
||||||
@Controller('partner/consumers/:consumerId/accounts')
|
@Controller('partner/consumers/:consumerId/accounts')
|
||||||
@@ -41,7 +45,7 @@ export class AccountsController {
|
|||||||
@PartnerInfo('id') partnerId: string,
|
@PartnerInfo('id') partnerId: string,
|
||||||
@Param('consumerId') consumerId: string,
|
@Param('consumerId') consumerId: string,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@Body() data: UpdateAccountDto,
|
@Body() data: UpdatePartnerConsumerAccountDto,
|
||||||
): Promise<AccountsServiceUpdateResponseDto> {
|
): Promise<AccountsServiceUpdateResponseDto> {
|
||||||
return this.accountsService.update(partnerId, consumerId, id, data)
|
return this.accountsService.update(partnerId, consumerId, id, data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ConsumerAccountSelect } from '@/generated/prisma/models'
|
|||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { UpdateAccountDto } from './dto/account.dto'
|
import { UpdatePartnerConsumerAccountDto } from './dto/account.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
@@ -126,7 +126,7 @@ export class AccountsService {
|
|||||||
partner_id: string,
|
partner_id: string,
|
||||||
consumer_id: string,
|
consumer_id: string,
|
||||||
id: string,
|
id: string,
|
||||||
data: UpdateAccountDto,
|
data: UpdatePartnerConsumerAccountDto,
|
||||||
) {
|
) {
|
||||||
const account = await this.prisma.account.update({
|
const account = await this.prisma.account.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ApiProperty, PartialType } from '@nestjs/swagger'
|
|||||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||||
import { AccountStatus, ConsumerRole } from 'generated/prisma/enums'
|
import { AccountStatus, ConsumerRole } from 'generated/prisma/enums'
|
||||||
|
|
||||||
export class CreateConsumerAccountDto {
|
export class CreatePartnerConsumerAccountDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@UsernameFieldValidator()
|
@UsernameFieldValidator()
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@@ -19,7 +19,9 @@ export class CreateConsumerAccountDto {
|
|||||||
role: ConsumerRole
|
role: ConsumerRole
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateAccountDto extends PartialType(CreateConsumerAccountDto) {
|
export class UpdatePartnerConsumerAccountDto extends PartialType(
|
||||||
|
CreatePartnerConsumerAccountDto,
|
||||||
|
) {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsEnum(AccountStatus)
|
@IsEnum(AccountStatus)
|
||||||
@ApiProperty({ enum: AccountStatus })
|
@ApiProperty({ enum: AccountStatus })
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { POSStatus, POSType } from '@/generated/prisma/enums'
|
import { POSStatus, POSType } from '@/generated/prisma/enums'
|
||||||
import { CreateConsumerAccountDto } from '@/modules/partners/consumers/accounts/dto/account.dto'
|
import { CreatePartnerConsumerAccountDto } from '@/modules/partners/consumers/accounts/dto/account.dto'
|
||||||
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger'
|
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger'
|
||||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||||
|
|
||||||
export class CreatePosDto extends OmitType(CreateConsumerAccountDto, ['role']) {
|
export class CreatePosDto extends OmitType(CreatePartnerConsumerAccountDto, ['role']) {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ApiProperty({})
|
@ApiProperty({})
|
||||||
name: string
|
name: string
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ export class CustomersService {
|
|||||||
id: true,
|
id: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('type', type)
|
||||||
|
console.log('type === CustomerType.LEGAL', type === CustomerType.LEGAL)
|
||||||
|
console.log('type === CustomerType.INDIVIDUAL', type === CustomerType.INDIVIDUAL)
|
||||||
|
|
||||||
if (type === CustomerType.LEGAL) {
|
if (type === CustomerType.LEGAL) {
|
||||||
where.legal = {
|
where.legal = {
|
||||||
business_activity_id: posInfo.business_id,
|
business_activity_id: posInfo.business_id,
|
||||||
@@ -118,9 +122,7 @@ export class CustomersService {
|
|||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
type: true,
|
...select,
|
||||||
created_at: true,
|
|
||||||
updated_at: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return ResponseMapper.list(customers)
|
return ResponseMapper.list(customers)
|
||||||
|
|||||||
Reference in New Issue
Block a user