feat: add consumer accounts and business activities management
- Implemented AccountsService for managing consumer accounts including create, update, delete, and find operations. - Created DTOs for account creation and updates. - Developed BusinessActivitiesController and BusinessActivitiesService for handling business activities related to consumers. - Added complexes management with ComplexesController and ComplexesService. - Introduced POS management with ComplexPosesController and ComplexPosesService. - Created necessary DTOs for business activities and POS. - Established Licenses management with LicensesController and LicensesService. - Integrated consumer management with PartnerConsumersController and PartnerConsumersService. - Added Prisma module imports and service connections across modules.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { AccountsService } from './accounts.service'
|
||||
import { CreateConsumerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
|
||||
@ApiTags('PartnerConsumerAccounts')
|
||||
@Controller('partner/consumers/:consumerId/accounts')
|
||||
export class AccountsController {
|
||||
constructor(private readonly accountsService: AccountsService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('consumerId') consumerId: string) {
|
||||
return this.accountsService.findAll(consumerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string) {
|
||||
return this.accountsService.findOne(id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Body() data: CreateConsumerAccountDto,
|
||||
) {
|
||||
return this.accountsService.create(consumerId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
|
||||
return this.accountsService.update(id, data)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.accountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { AccountsController } from './accounts.controller'
|
||||
import { AccountsService } from './accounts.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [AccountsController],
|
||||
providers: [AccountsService],
|
||||
exports: [AccountsService],
|
||||
})
|
||||
export class PartnerConsumerAccountsModule {}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import { AccountStatus, AccountType } from '@/generated/prisma/enums'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateConsumerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
|
||||
@Injectable()
|
||||
export class AccountsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll(consumer_id: string) {
|
||||
const accounts = await this.prisma.consumerAccount.findMany({
|
||||
where: { consumer_id },
|
||||
select: {
|
||||
id: true,
|
||||
role: true,
|
||||
created_at: true,
|
||||
account: {
|
||||
select: {
|
||||
username: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.list(accounts)
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const account = await this.prisma.consumerAccount.findMany({
|
||||
where: { id },
|
||||
select: {
|
||||
id: true,
|
||||
role: true,
|
||||
created_at: true,
|
||||
account: {
|
||||
select: {
|
||||
username: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(consumerId: string, data: CreateConsumerAccountDto) {
|
||||
const account = await this.prisma.consumerAccount.create({
|
||||
data: {
|
||||
role: data.role,
|
||||
account: {
|
||||
create: {
|
||||
password: await PasswordUtil.hash(data.password),
|
||||
status: AccountStatus.ACTIVE,
|
||||
type: AccountType.CONSUMER,
|
||||
username: data.username,
|
||||
},
|
||||
},
|
||||
consumer: {
|
||||
connect: {
|
||||
id: consumerId,
|
||||
},
|
||||
},
|
||||
permission: {
|
||||
create: {},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdateAccountDto) {
|
||||
const account = await this.prisma.account.update({ where: { id }, data })
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
await this.prisma.account.delete({ where: { id } })
|
||||
return ResponseMapper.delete()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||
import { AccountStatus, ConsumerRole } from 'generated/prisma/enums'
|
||||
|
||||
export class CreateConsumerAccountDto {
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
username: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
password: string
|
||||
|
||||
@IsEnum(ConsumerRole)
|
||||
@ApiProperty({ required: true, enum: ConsumerRole })
|
||||
role: ConsumerRole
|
||||
}
|
||||
|
||||
export class UpdateAccountDto extends PartialType(CreateConsumerAccountDto) {
|
||||
@IsOptional()
|
||||
@IsEnum(AccountStatus)
|
||||
@ApiProperty({ enum: AccountStatus })
|
||||
status?: AccountStatus
|
||||
}
|
||||
Reference in New Issue
Block a user