init to partner module

This commit is contained in:
2026-04-13 15:47:59 +03:30
parent 388aa25de4
commit 59da9585c4
21 changed files with 553 additions and 12 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 { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
@Injectable()
export class AccountsService {
constructor(private readonly prisma: PrismaService) {}
async findAll(partner_id: string) {
const accounts = await this.prisma.partnerAccount.findMany({
where: { partner_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.partnerAccount.findUniqueOrThrow({
where: { id },
select: {
id: true,
role: true,
created_at: true,
account: {
select: {
username: true,
status: true,
},
},
},
})
return ResponseMapper.single(account)
}
async create(partnerId: string, data: CreatePartnerAccountDto) {
const account = await this.prisma.partnerAccount.create({
data: {
role: data.role,
account: {
create: {
password: await PasswordUtil.hash(data.password),
status: AccountStatus.ACTIVE,
type: AccountType.PARTNER,
username: data.username,
},
},
partner: {
connect: {
id: partnerId,
},
},
},
})
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()
// }
}