create token decorator and consumer module

This commit is contained in:
2026-03-16 17:56:51 +03:30
parent 0ad6a3200e
commit 69e9a0d082
38 changed files with 1027 additions and 66 deletions
@@ -0,0 +1,79 @@
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(consumerId: string) {
const accounts = await this.prisma.consumerAccount.findMany({
where: { user_id: consumerId },
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,
},
},
user: {
connect: {
id: consumerId,
},
},
},
})
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()
}
}