feat: implement partner licenses module with pagination and filtering capabilities
This commit is contained in:
@@ -46,14 +46,14 @@ export class AdminConsumersService {
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
const [consumers, count] = await this.prisma.$transaction([
|
||||
const [consumers, total] = await this.prisma.$transaction([
|
||||
this.prisma.consumer.findMany({
|
||||
select: this.defaultSelect,
|
||||
}),
|
||||
this.prisma.consumer.count(),
|
||||
])
|
||||
|
||||
return ResponseMapper.paginate(consumers.map(mapConsumerWithLicenseUtil), { count })
|
||||
return ResponseMapper.paginate(consumers.map(mapConsumerWithLicenseUtil), { total })
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
|
||||
@@ -7,16 +7,16 @@ import { CreateDeviceDto, UpdateDeviceDto } from './dto/device.dto'
|
||||
export class DevicesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll(page = 1, pageSize = 10) {
|
||||
const [items, count] = await this.prisma.$transaction([
|
||||
async findAll(page = 1, perPage = 10) {
|
||||
const [items, total] = await this.prisma.$transaction([
|
||||
this.prisma.device.findMany({
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
include: { brand: true },
|
||||
}),
|
||||
this.prisma.device.count(),
|
||||
])
|
||||
return ResponseMapper.paginate(items, { count, page, pageSize })
|
||||
return ResponseMapper.paginate(items, { total, page, perPage })
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
|
||||
@@ -37,7 +37,7 @@ export class GoodsService {
|
||||
})
|
||||
|
||||
async findAll(guildId: string) {
|
||||
const [goods, count] = await this.prisma.$transaction([
|
||||
const [goods, total] = await this.prisma.$transaction([
|
||||
this.prisma.good.findMany({
|
||||
where: this.defaultWhere(guildId),
|
||||
select: this.defaultSelect,
|
||||
@@ -45,7 +45,7 @@ export class GoodsService {
|
||||
this.prisma.good.count(),
|
||||
])
|
||||
return ResponseMapper.paginate(goods, {
|
||||
count,
|
||||
total,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export class GuildsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll() {
|
||||
const [guilds, count] = await this.prisma.$transaction([
|
||||
const [guilds, total] = await this.prisma.$transaction([
|
||||
this.prisma.guild.findMany({
|
||||
include: {
|
||||
_count: {
|
||||
@@ -30,7 +30,7 @@ export class GuildsService {
|
||||
businessActivitiesCount: guild._count.business_activities,
|
||||
}
|
||||
}),
|
||||
{ count },
|
||||
{ total },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -48,20 +48,20 @@ export class PartnerLicensesService {
|
||||
created_at: true,
|
||||
}
|
||||
|
||||
async findAll(page = 1, pageSize = 10) {
|
||||
const [licenses, count] = await this.prisma.$transaction([
|
||||
async findAll(page = 1, perPage = 10) {
|
||||
const [licenses, total] = await this.prisma.$transaction([
|
||||
this.prisma.licenseActivation.findMany({
|
||||
select: this.licenseDefaultSelect,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
}),
|
||||
this.prisma.licenseActivation.count(),
|
||||
])
|
||||
|
||||
return ResponseMapper.paginate(licenses, {
|
||||
count,
|
||||
total,
|
||||
page,
|
||||
pageSize,
|
||||
perPage,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ResponseMapper } from 'common/response/response-mapper'
|
||||
export class PartnerActivatedLicensesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
async findAll(partner_id: string, page = 1, perPage = 10) {
|
||||
const defaultWhere: LicenseActivationWhereInput = {
|
||||
license: {
|
||||
charge_transaction: {
|
||||
@@ -15,11 +15,11 @@ export class PartnerActivatedLicensesService {
|
||||
},
|
||||
},
|
||||
}
|
||||
const [licenses, count] = await this.prisma.$transaction(async tx => [
|
||||
const [licenses, total] = await this.prisma.$transaction(async tx => [
|
||||
await tx.licenseActivation.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
select: {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
@@ -71,8 +71,8 @@ export class PartnerActivatedLicensesService {
|
||||
|
||||
return ResponseMapper.paginate(mappedLicenses, {
|
||||
page,
|
||||
pageSize,
|
||||
count,
|
||||
perPage,
|
||||
total,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -7,18 +7,18 @@ import { ResponseMapper } from 'common/response/response-mapper'
|
||||
export class PartnerAllocatedAccountsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
async findAll(partner_id: string, page = 1, perPage = 10) {
|
||||
const defaultWhere: PartnerAccountQuotaCreditWhereInput = {
|
||||
charge_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
}
|
||||
|
||||
const [allocations, count] = await this.prisma.$transaction(async tx => [
|
||||
const [allocations, total] = await this.prisma.$transaction(async tx => [
|
||||
await tx.partnerAccountQuotaCredit.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
select: {
|
||||
id: true,
|
||||
created_at: true,
|
||||
@@ -54,8 +54,8 @@ export class PartnerAllocatedAccountsService {
|
||||
|
||||
return ResponseMapper.paginate(allocations, {
|
||||
page,
|
||||
pageSize,
|
||||
count,
|
||||
perPage,
|
||||
total,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -51,16 +51,16 @@ export class PartnerAccountChargeTransactionService {
|
||||
},
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
async findAll(partner_id: string, page = 1, perPage = 10) {
|
||||
const defaultWhere: PartnerAccountQuotaChargeTransactionWhereInput = {
|
||||
partner_id,
|
||||
}
|
||||
|
||||
const [transactions, count] = await this.prisma.$transaction(async tx => [
|
||||
const [transactions, total] = await this.prisma.$transaction(async tx => [
|
||||
await tx.partnerAccountQuotaChargeTransaction.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
select: this.defaultSelect,
|
||||
}),
|
||||
await tx.partnerAccountQuotaChargeTransaction.count({
|
||||
@@ -72,8 +72,8 @@ export class PartnerAccountChargeTransactionService {
|
||||
|
||||
return ResponseMapper.paginate(mappedTransactions, {
|
||||
page,
|
||||
pageSize,
|
||||
count,
|
||||
perPage,
|
||||
total,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -51,16 +51,16 @@ export class PartnerLicenseChargeTransactionService {
|
||||
},
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
async findAll(partner_id: string, page = 1, perPage = 10) {
|
||||
const defaultWhere: LicenseChargeTransactionWhereInput = {
|
||||
partner_id,
|
||||
}
|
||||
|
||||
const [transactions, count] = await this.prisma.$transaction(async tx => [
|
||||
const [transactions, total] = await this.prisma.$transaction(async tx => [
|
||||
await tx.licenseChargeTransaction.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
select: this.defaultSelect,
|
||||
}),
|
||||
await tx.licenseChargeTransaction.count({
|
||||
@@ -72,8 +72,8 @@ export class PartnerLicenseChargeTransactionService {
|
||||
|
||||
return ResponseMapper.paginate(mappedTransactions, {
|
||||
page,
|
||||
pageSize,
|
||||
count,
|
||||
perPage,
|
||||
total,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ export class AdminUsersService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll() {
|
||||
const [users, count] = await this.prisma.$transaction([
|
||||
const [users, total] = await this.prisma.$transaction([
|
||||
this.prisma.admin.findMany(),
|
||||
this.prisma.admin.count(),
|
||||
])
|
||||
return ResponseMapper.paginate(
|
||||
users.map(user => ({ ...user, fullname: `${user.first_name} ${user.last_name}` })),
|
||||
{ count },
|
||||
{ total },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user