feat: add response DTOs for various services across modules
- Created response DTOs for ConfigService, AppService, AuthService, CatalogsService, AccountsService, BusinessActivityComplexesService, ComplexPosesService, SalesInvoicesService, BusinessActivitiesService, ConsumerBusinessActivityGoodsService, and others. - Implemented Create, FindAll, FindOne, and Update response types for services in consumer, partners, and POS modules. - Added request DTOs for creating and updating goods in the consumer business activities module. - Introduced filtering DTO for partner licenses. - Enhanced response mapping for partner license activations.
This commit is contained in:
@@ -3,6 +3,7 @@ import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { AccountsService } from './accounts.service'
|
||||
import { UpdateAccountDto } from './dto/account.dto'
|
||||
import type { AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
|
||||
|
||||
@ApiTags('PartnerConsumerAccounts')
|
||||
@Controller('partner/consumers/:consumerId/accounts')
|
||||
@@ -13,7 +14,7 @@ export class AccountsController {
|
||||
async findAll(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
) {
|
||||
): Promise<AccountsServiceFindAllResponseDto> {
|
||||
return this.accountsService.findAll(partnerId, consumerId)
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ export class AccountsController {
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
): Promise<AccountsServiceFindOneResponseDto> {
|
||||
return this.accountsService.findOne(partnerId, consumerId, id)
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ export class AccountsController {
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateAccountDto,
|
||||
) {
|
||||
): Promise<AccountsServiceUpdateResponseDto> {
|
||||
return this.accountsService.update(partnerId, consumerId, id, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,18 @@ export class AccountsService {
|
||||
private readonly defaultWhere = (partner_id, consumer_id) => ({
|
||||
consumer_id,
|
||||
consumer: {
|
||||
partner_id,
|
||||
OR: [
|
||||
{
|
||||
legal: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
{
|
||||
individual: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { AccountsService } from '../accounts.service'
|
||||
|
||||
export type AccountsServiceFindAllResponseDto = Awaited<ReturnType<AccountsService['findAll']>>
|
||||
export type AccountsServiceFindOneResponseDto = Awaited<ReturnType<AccountsService['findOne']>>
|
||||
export type AccountsServiceUpdateResponseDto = Awaited<ReturnType<AccountsService['update']>>
|
||||
+2
-1
@@ -3,6 +3,7 @@ import { Body, Controller, Param, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerBusinessActivityAccountsChargeService } from './accounts-charge.service'
|
||||
import { CreateBusinessActivityAccountsChargeDto } from './dto/accounts-charge.dto'
|
||||
import type { PartnerBusinessActivityAccountsChargeServiceCreateResponseDto } from './dto/accounts-charge-response.dto'
|
||||
|
||||
@ApiTags('PartnerConsumerBAAccountsCharge')
|
||||
@Controller(
|
||||
@@ -17,7 +18,7 @@ export class PartnerBusinessActivityAccountsChargeController {
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: CreateBusinessActivityAccountsChargeDto,
|
||||
) {
|
||||
): Promise<PartnerBusinessActivityAccountsChargeServiceCreateResponseDto> {
|
||||
return this.service.create(partnerId, consumerId, businessActivityId, data)
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -26,7 +26,18 @@ export class PartnerBusinessActivityAccountsChargeService {
|
||||
id: business_activity_id,
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
partner_id,
|
||||
OR: [
|
||||
{
|
||||
legal: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
{
|
||||
individual: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
OR: [
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { PartnerBusinessActivityAccountsChargeService } from '../accounts-charge.service'
|
||||
|
||||
export type PartnerBusinessActivityAccountsChargeServiceCreateResponseDto = Awaited<ReturnType<PartnerBusinessActivityAccountsChargeService['create']>>
|
||||
+6
-4
@@ -16,7 +16,7 @@ export class BusinessActivitiesController {
|
||||
async findAll(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
) {
|
||||
): Promise<BusinessActivitiesServiceFindAllResponseDto> {
|
||||
return this.businessActivitiesService.findAll(partnerId, consumerId)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export class BusinessActivitiesController {
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
): Promise<BusinessActivitiesServiceFindOneResponseDto> {
|
||||
return this.businessActivitiesService.findOne(partnerId, consumerId, id)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export class BusinessActivitiesController {
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Body() data: CreateBusinessActivitiesDto,
|
||||
) {
|
||||
): Promise<BusinessActivitiesServiceCreateResponseDto> {
|
||||
return this.businessActivitiesService.create(partnerId, consumerId, data)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class BusinessActivitiesController {
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateBusinessActivityDto,
|
||||
) {
|
||||
): Promise<BusinessActivitiesServiceUpdateResponseDto> {
|
||||
return this.businessActivitiesService.update(partnerId, consumerId, id, data)
|
||||
}
|
||||
|
||||
@@ -53,3 +53,5 @@ export class BusinessActivitiesController {
|
||||
// return this.businessActivitiesService.delete(id)
|
||||
// }
|
||||
}
|
||||
|
||||
import type { BusinessActivitiesServiceCreateResponseDto, BusinessActivitiesServiceFindAllResponseDto, BusinessActivitiesServiceFindOneResponseDto, BusinessActivitiesServiceUpdateResponseDto } from './dto/business-activities-response.dto'
|
||||
@@ -15,7 +15,7 @@ export class BusinessActivitiesService {
|
||||
).toISOString()
|
||||
}
|
||||
|
||||
defaultSelect: BusinessActivitySelect = {
|
||||
private readonly defaultSelect: BusinessActivitySelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
economic_code: true,
|
||||
@@ -49,6 +49,24 @@ export class BusinessActivitiesService {
|
||||
},
|
||||
}
|
||||
|
||||
private readonly defaultWhere = (partner_id: string, consumer_id: string) => ({
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
OR: [
|
||||
{
|
||||
legal: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
{
|
||||
individual: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
private readonly prepareBusinessActivityResponse = (businessActivity: any) => {
|
||||
const { license_activation, ...rest } = businessActivity
|
||||
const { license, ...license_activation_rest } = license_activation
|
||||
@@ -65,12 +83,7 @@ export class BusinessActivitiesService {
|
||||
|
||||
async findAll(partner_id: string, consumer_id: string) {
|
||||
const businessActivities = await this.prisma.businessActivity.findMany({
|
||||
where: {
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
where: this.defaultWhere(partner_id, consumer_id),
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.list(
|
||||
@@ -81,10 +94,7 @@ export class BusinessActivitiesService {
|
||||
async findOne(partner_id: string, consumer_id: string, id: string) {
|
||||
const businessActivity = await this.prisma.businessActivity.findUnique({
|
||||
where: {
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
partner_id,
|
||||
},
|
||||
...this.defaultWhere(partner_id, consumer_id),
|
||||
id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
@@ -171,7 +181,7 @@ export class BusinessActivitiesService {
|
||||
|
||||
async update(partner_id: string, consumer_id: string, id: string, data: any) {
|
||||
const businessActivity = await this.prisma.businessActivity.update({
|
||||
where: { id, consumer: { id: consumer_id, partner_id } },
|
||||
where: { ...this.defaultWhere(partner_id, consumer_id), id },
|
||||
data,
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
|
||||
+5
-4
@@ -3,6 +3,7 @@ import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { BusinessActivityComplexesService } from './complexes.service'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
import type { BusinessActivityComplexesServiceCreateResponseDto, BusinessActivityComplexesServiceFindAllResponseDto, BusinessActivityComplexesServiceFindOneResponseDto, BusinessActivityComplexesServiceUpdateResponseDto } from './dto/complexes-response.dto'
|
||||
|
||||
@ApiTags('PartnerBusinessActivityComplexes')
|
||||
@Controller(
|
||||
@@ -16,7 +17,7 @@ export class BusinessActivityComplexesController {
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
) {
|
||||
): Promise<BusinessActivityComplexesServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId, consumerId, businessActivityId)
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ export class BusinessActivityComplexesController {
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
): Promise<BusinessActivityComplexesServiceFindOneResponseDto> {
|
||||
return this.service.findOne(partnerId, consumerId, businessActivityId, id)
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ export class BusinessActivityComplexesController {
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: CreateComplexDto,
|
||||
) {
|
||||
): Promise<BusinessActivityComplexesServiceCreateResponseDto> {
|
||||
return this.service.create(partnerId, businessActivityId, data)
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ export class BusinessActivityComplexesController {
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateComplexDto,
|
||||
) {
|
||||
): Promise<BusinessActivityComplexesServiceUpdateResponseDto> {
|
||||
return this.service.update(partnerId, consumerId, businessActivityId, id, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,18 @@ export class BusinessActivityComplexesService {
|
||||
id: business_activity_id,
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
partner_id,
|
||||
OR: [
|
||||
{
|
||||
legal: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
{
|
||||
individual: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import type { BusinessActivityComplexesService } from '../complexes.service'
|
||||
|
||||
export type BusinessActivityComplexesServiceCreateResponseDto = Awaited<ReturnType<BusinessActivityComplexesService['create']>>
|
||||
export type BusinessActivityComplexesServiceFindAllResponseDto = Awaited<ReturnType<BusinessActivityComplexesService['findAll']>>
|
||||
export type BusinessActivityComplexesServiceFindOneResponseDto = Awaited<ReturnType<BusinessActivityComplexesService['findOne']>>
|
||||
export type BusinessActivityComplexesServiceUpdateResponseDto = Awaited<ReturnType<BusinessActivityComplexesService['update']>>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import type { ComplexPosesService } from '../poses.service'
|
||||
|
||||
export type ComplexPosesServiceCreateResponseDto = Awaited<ReturnType<ComplexPosesService['create']>>
|
||||
export type ComplexPosesServiceFindAllResponseDto = Awaited<ReturnType<ComplexPosesService['findAll']>>
|
||||
export type ComplexPosesServiceFindOneResponseDto = Awaited<ReturnType<ComplexPosesService['findOne']>>
|
||||
export type ComplexPosesServiceUpdateResponseDto = Awaited<ReturnType<ComplexPosesService['update']>>
|
||||
+5
-4
@@ -3,6 +3,7 @@ import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
|
||||
import { ComplexPosesService } from './poses.service'
|
||||
import type { ComplexPosesServiceCreateResponseDto, ComplexPosesServiceFindAllResponseDto, ComplexPosesServiceFindOneResponseDto, ComplexPosesServiceUpdateResponseDto } from './dto/poses-response.dto'
|
||||
|
||||
@ApiTags('AdminComplexPoses')
|
||||
@Controller('partner/business_activities/:businessActivityId/complexes/:complexId/poses')
|
||||
@@ -14,7 +15,7 @@ export class ComplexPosesController {
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
) {
|
||||
): Promise<ComplexPosesServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId, businessActivityId, complexId)
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ export class ComplexPosesController {
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
): Promise<ComplexPosesServiceFindOneResponseDto> {
|
||||
return this.service.findOne(partnerId, businessActivityId, complexId, id)
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ export class ComplexPosesController {
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Body() data: CreatePosDto,
|
||||
) {
|
||||
): Promise<ComplexPosesServiceCreateResponseDto> {
|
||||
return this.service.create(partnerId, businessActivityId, complexId, data)
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ export class ComplexPosesController {
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdatePosDto,
|
||||
) {
|
||||
): Promise<ComplexPosesServiceUpdateResponseDto> {
|
||||
return this.service.update(partnerId, businessActivityId, complexId, id, data)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import type { BusinessActivitiesService } from '../business-activities.service'
|
||||
|
||||
export type BusinessActivitiesServiceCreateResponseDto = Awaited<ReturnType<BusinessActivitiesService['create']>>
|
||||
export type BusinessActivitiesServiceFindAllResponseDto = Awaited<ReturnType<BusinessActivitiesService['findAll']>>
|
||||
export type BusinessActivitiesServiceFindOneResponseDto = Awaited<ReturnType<BusinessActivitiesService['findOne']>>
|
||||
export type BusinessActivitiesServiceUpdateResponseDto = Awaited<ReturnType<BusinessActivitiesService['update']>>
|
||||
@@ -2,23 +2,24 @@ import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { PartnerConsumersService } from './consumers.service'
|
||||
import { CreateConsumerDto, UpdateConsumerDto } from './dto/create-consumers.dto'
|
||||
import type { PartnerConsumersServiceCreateResponseDto, PartnerConsumersServiceFindAllResponseDto, PartnerConsumersServiceFindOneResponseDto, PartnerConsumersServiceUpdateResponseDto } from './dto/consumers-response.dto'
|
||||
|
||||
@Controller('partner/consumers')
|
||||
export class PartnerConsumersController {
|
||||
constructor(private readonly service: PartnerConsumersService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@PartnerInfo('id') partnerId: string) {
|
||||
async findAll(@PartnerInfo('id') partnerId: string): Promise<PartnerConsumersServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@PartnerInfo('id') partnerId: string, @Param('id') id: string) {
|
||||
async findOne(@PartnerInfo('id') partnerId: string, @Param('id') id: string): Promise<PartnerConsumersServiceFindOneResponseDto> {
|
||||
return this.service.findOne(partnerId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@PartnerInfo('id') partnerId: string, @Body() data: CreateConsumerDto) {
|
||||
async create(@PartnerInfo('id') partnerId: string, @Body() data: CreateConsumerDto): Promise<PartnerConsumersServiceCreateResponseDto> {
|
||||
return this.service.create(partnerId, data)
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ export class PartnerConsumersController {
|
||||
@Param('id') id: string,
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Body() data: UpdateConsumerDto,
|
||||
) {
|
||||
): Promise<PartnerConsumersServiceUpdateResponseDto> {
|
||||
return this.service.update(id, partnerId, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||
import mapConsumerWithLicenseUtil from '@/common/utils/mappers/consumer_mappers.util'
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import {
|
||||
AccountStatus,
|
||||
AccountType,
|
||||
ConsumerRole,
|
||||
ConsumerStatus,
|
||||
ConsumerType,
|
||||
PartnerStatus,
|
||||
} from '@/generated/prisma/enums'
|
||||
import { ConsumerSelect, ConsumerWhereInput } from '@/generated/prisma/models'
|
||||
import mapConsumerWithLicenseUtil from '@/modules/consumer/utils/mapConsumerWithLicense.util'
|
||||
import {
|
||||
ConsumerCreateInput,
|
||||
ConsumerSelect,
|
||||
ConsumerWhereInput,
|
||||
} from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -25,16 +31,24 @@ export class PartnerConsumersService {
|
||||
|
||||
defaultSelect: ConsumerSelect = {
|
||||
id: true,
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
mobile_number: true,
|
||||
national_code: true,
|
||||
...QUERY_CONSTANTS.CONSUMER.infoSelect,
|
||||
status: true,
|
||||
created_at: true,
|
||||
}
|
||||
|
||||
private defaultWhere = (partner_id: string): ConsumerWhereInput => ({
|
||||
partner_id,
|
||||
OR: [
|
||||
{
|
||||
legal: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
{
|
||||
individual: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
async findAll(partner_id: string, page = 1, perPage = 10) {
|
||||
@@ -105,48 +119,102 @@ export class PartnerConsumersService {
|
||||
throw new BadRequestException(`تعداد لایسنسهای فعلی شما به پایان رسیده است.`)
|
||||
}
|
||||
|
||||
const { username, password, license_starts_at, ...rest } = data
|
||||
const { username, password, customer, ...rest } = data
|
||||
const { individual, legal } = customer
|
||||
|
||||
const existingConsumer = await tx.consumer.findFirst({
|
||||
where: {
|
||||
partner_id,
|
||||
OR: [
|
||||
{ mobile_number: data.mobile_number },
|
||||
{ national_code: data.national_code },
|
||||
],
|
||||
},
|
||||
select: { id: true, first_name: true, last_name: true },
|
||||
})
|
||||
|
||||
if (existingConsumer) {
|
||||
throw new BadRequestException(
|
||||
`مصرف کنندهی ${existingConsumer.first_name} ${existingConsumer.last_name} با شماره موبایل یا کد ملی وارد شده از قبل ثبت شده است.`,
|
||||
)
|
||||
}
|
||||
|
||||
return await tx.consumer.create({
|
||||
data: {
|
||||
...rest,
|
||||
partner: {
|
||||
connect: {
|
||||
id: partner_id,
|
||||
},
|
||||
},
|
||||
consumer_accounts: {
|
||||
create: {
|
||||
role: ConsumerRole.OWNER,
|
||||
account: {
|
||||
create: {
|
||||
username,
|
||||
password: await PasswordUtil.hash(password),
|
||||
type: AccountType.CONSUMER,
|
||||
status: AccountStatus.ACTIVE,
|
||||
},
|
||||
const createConsumerData: ConsumerCreateInput = {
|
||||
...rest,
|
||||
accounts: {
|
||||
create: {
|
||||
role: ConsumerRole.OWNER,
|
||||
account: {
|
||||
create: {
|
||||
username,
|
||||
password: await PasswordUtil.hash(password),
|
||||
type: AccountType.CONSUMER,
|
||||
status: AccountStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
status: ConsumerStatus.ACTIVE,
|
||||
},
|
||||
status: ConsumerStatus.ACTIVE,
|
||||
}
|
||||
|
||||
const partner = {
|
||||
partner: { connect: { id: partner_id } },
|
||||
}
|
||||
|
||||
if (!legal && !individual) {
|
||||
throw new BadRequestException(
|
||||
`برای ایجاد مصرف کننده باید یکی از اطلاعات فردی یا حقوقی وارد شود.`,
|
||||
)
|
||||
}
|
||||
if (data.type === ConsumerType.INDIVIDUAL && !individual) {
|
||||
throw new BadRequestException(
|
||||
`برای ایجاد مصرف کننده با نوع حقیقی باید اطلاعات فردی وارد شود.`,
|
||||
)
|
||||
}
|
||||
if (data.type === ConsumerType.LEGAL && !legal) {
|
||||
throw new BadRequestException(
|
||||
`برای ایجاد مصرف کننده با نوع حقوقی باید اطلاعات حقوقی وارد شود.`,
|
||||
)
|
||||
}
|
||||
|
||||
let consumerExistError = ''
|
||||
|
||||
if (legal) {
|
||||
const existingConsumer = await tx.consumer.findFirst({
|
||||
where: {
|
||||
legal: { registration_code: legal.registration_code, partner_id },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
legal: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
createConsumerData.legal = {
|
||||
create: {
|
||||
...legal,
|
||||
...partner,
|
||||
},
|
||||
}
|
||||
|
||||
if (existingConsumer) {
|
||||
consumerExistError = `مشتری با نام ${existingConsumer.legal!.name} با این شماره ثبت، از قبل توسط شما ایجاد شده است.`
|
||||
}
|
||||
} else if (individual) {
|
||||
const existingConsumer = await tx.consumer.findFirst({
|
||||
where: {
|
||||
individual: { national_code: individual.national_code, partner_id },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
individual: {
|
||||
select: {
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
createConsumerData.individual = {
|
||||
create: {
|
||||
...individual,
|
||||
...partner,
|
||||
},
|
||||
}
|
||||
|
||||
if (existingConsumer) {
|
||||
;`مشتری با نام ${existingConsumer.individual!.first_name} ${existingConsumer.individual!.last_name} یا این کد ملی، از قبل توسط شما ایجاد شده است.`
|
||||
}
|
||||
}
|
||||
|
||||
return await tx.consumer.create({
|
||||
data: createConsumerData,
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { PartnerConsumersService } from '../consumers.service'
|
||||
|
||||
export type PartnerConsumersServiceCreateResponseDto = Awaited<ReturnType<PartnerConsumersService['create']>>
|
||||
export type PartnerConsumersServiceFindAllResponseDto = Awaited<ReturnType<PartnerConsumersService['findAll']>>
|
||||
export type PartnerConsumersServiceFindOneResponseDto = Awaited<ReturnType<PartnerConsumersService['findOne']>>
|
||||
export type PartnerConsumersServiceUpdateResponseDto = Awaited<ReturnType<PartnerConsumersService['update']>>
|
||||
@@ -1,23 +1,12 @@
|
||||
import { ConsumerStatus } from '@/generated/prisma/enums'
|
||||
import { ConsumerIndividual, ConsumerLegal } from '@/generated/prisma/client'
|
||||
import { ConsumerStatus, ConsumerType } from '@/generated/prisma/enums'
|
||||
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger'
|
||||
import { IsDateString, IsEnum, IsString } from 'class-validator'
|
||||
import { IsEnum, IsObject, IsString } from 'class-validator'
|
||||
|
||||
export class CreateConsumerDto {
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
first_name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
last_name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
mobile_number: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
national_code: string
|
||||
@IsEnum(ConsumerType)
|
||||
@ApiProperty({ enum: ConsumerType, required: true })
|
||||
type: ConsumerType
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
@@ -28,11 +17,11 @@ export class CreateConsumerDto {
|
||||
password: string
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@IsDateString(
|
||||
{ strict: true },
|
||||
{ message: 'invoice_date must be a valid ISO-8601 string' },
|
||||
)
|
||||
license_starts_at: Date
|
||||
@IsObject()
|
||||
customer: {
|
||||
individual?: Omit<ConsumerIndividual, 'partner_id' | 'consumer_id'>
|
||||
legal?: Omit<ConsumerLegal, 'partner_id' | 'consumer_id'>
|
||||
}
|
||||
}
|
||||
export class UpdateConsumerDto extends OmitType(PartialType(CreateConsumerDto), [
|
||||
'password',
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import type { LicensesService } from '../licenses.service'
|
||||
|
||||
export type LicensesServiceFindAllResponseDto = Awaited<ReturnType<LicensesService['findAll']>>
|
||||
@@ -2,6 +2,7 @@ import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { LicensesService } from './licenses.service'
|
||||
import type { LicensesServiceFindAllResponseDto } from './dto/licenses-response.dto'
|
||||
|
||||
@ApiTags('AdminConsumerAccounts')
|
||||
@Controller('admin/consumers/:consumerId/licenses')
|
||||
@@ -12,7 +13,7 @@ export class LicensesController {
|
||||
async findAll(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
) {
|
||||
): Promise<LicensesServiceFindAllResponseDto> {
|
||||
return this.service.findAll(partnerId, consumerId)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user