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:
2026-04-27 10:45:39 +03:30
parent 34793295c9
commit dee96b6e91
208 changed files with 8058 additions and 2349 deletions
@@ -2,6 +2,7 @@ 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'
import type { AccountsServiceCreateResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
@ApiTags('AdminConsumerAccounts')
@Controller('admin/consumers/:consumerId/accounts')
@@ -9,12 +10,12 @@ export class AccountsController {
constructor(private readonly accountsService: AccountsService) {}
@Get()
async findAll(@Param('consumerId') consumerId: string) {
async findAll(@Param('consumerId') consumerId: string): Promise<AccountsServiceFindAllResponseDto> {
return this.accountsService.findAll(consumerId)
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<AccountsServiceFindOneResponseDto> {
return this.accountsService.findOne(id)
}
@@ -22,12 +23,12 @@ export class AccountsController {
async create(
@Param('consumerId') consumerId: string,
@Body() data: CreateConsumerAccountDto,
) {
): Promise<AccountsServiceCreateResponseDto> {
return this.accountsService.create(consumerId, data)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
return this.accountsService.update(id, data)
}
@@ -0,0 +1,7 @@
import type { AccountsService } from '../accounts.service'
export type AccountsServiceCreateResponseDto = Awaited<ReturnType<AccountsService['create']>>
export type AccountsServiceDeleteResponseDto = Awaited<ReturnType<AccountsService['delete']>>
export type AccountsServiceFindAllResponseDto = Awaited<ReturnType<AccountsService['findAll']>>
export type AccountsServiceFindOneResponseDto = Awaited<ReturnType<AccountsService['findOne']>>
export type AccountsServiceUpdateResponseDto = Awaited<ReturnType<AccountsService['update']>>
@@ -1,17 +1,18 @@
import { Controller, Get, Param } from '@nestjs/common'
import { BusinessActivitiesService } from './business-activities.service'
import type { BusinessActivitiesServiceFindAllResponseDto, BusinessActivitiesServiceFindOneResponseDto } from './dto/business-activities-response.dto'
@Controller('admin/consumers/:consumerId/business_activities')
export class BusinessActivitiesController {
constructor(private readonly businessActivitiesService: BusinessActivitiesService) {}
@Get()
async findAll(@Param('consumerId') consumerId: string) {
async findAll(@Param('consumerId') consumerId: string): Promise<BusinessActivitiesServiceFindAllResponseDto> {
return this.businessActivitiesService.findAll(consumerId)
}
@Get(':id')
async findOne(@Param('consumerId') consumerId: string, @Param('id') id: string) {
async findOne(@Param('consumerId') consumerId: string, @Param('id') id: string): Promise<BusinessActivitiesServiceFindOneResponseDto> {
return this.businessActivitiesService.findOne(consumerId, id)
}
@@ -1,6 +1,7 @@
import { Controller, Get, Param } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { BusinessActivityComplexesService } from './complexes.service'
import type { BusinessActivityComplexesServiceFindAllResponseDto, BusinessActivityComplexesServiceFindOneResponseDto } from './dto/complexes-response.dto'
@ApiTags('AdminBusinessActivityComplexes')
@Controller(
@@ -13,7 +14,7 @@ export class BusinessActivityComplexesController {
async findAll(
@Param('consumerId') consumerId: string,
@Param('businessActivityId') businessActivityId: string,
) {
): Promise<BusinessActivityComplexesServiceFindAllResponseDto> {
return this.service.findAll(consumerId, businessActivityId)
}
@@ -22,7 +23,7 @@ export class BusinessActivityComplexesController {
@Param('consumerId') consumerId: string,
@Param('businessActivityId') businessActivityId: string,
@Param('id') id: string,
) {
): Promise<BusinessActivityComplexesServiceFindOneResponseDto> {
return this.service.findOne(consumerId, businessActivityId, id)
}
@@ -0,0 +1,4 @@
import type { BusinessActivityComplexesService } from '../complexes.service'
export type BusinessActivityComplexesServiceFindAllResponseDto = Awaited<ReturnType<BusinessActivityComplexesService['findAll']>>
export type BusinessActivityComplexesServiceFindOneResponseDto = Awaited<ReturnType<BusinessActivityComplexesService['findOne']>>
@@ -0,0 +1,4 @@
import type { ComplexPosesService } from '../poses.service'
export type ComplexPosesServiceFindAllResponseDto = Awaited<ReturnType<ComplexPosesService['findAll']>>
export type ComplexPosesServiceFindOneResponseDto = Awaited<ReturnType<ComplexPosesService['findOne']>>
@@ -1,6 +1,7 @@
import { Controller, Get, Param } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { ComplexPosesService } from './poses.service'
import type { ComplexPosesServiceFindAllResponseDto, ComplexPosesServiceFindOneResponseDto } from './dto/poses-response.dto'
@ApiTags('AdminComplexPoses')
@Controller('admin/business_activities/:businessActivityId/complexes/:complexId/poses')
@@ -11,7 +12,7 @@ export class ComplexPosesController {
async findAll(
@Param('businessActivityId') businessActivityId: string,
@Param('complexId') complexId: string,
) {
): Promise<ComplexPosesServiceFindAllResponseDto> {
return this.service.findAll(businessActivityId, complexId)
}
@@ -20,7 +21,7 @@ export class ComplexPosesController {
@Param('businessActivityId') businessActivityId: string,
@Param('complexId') complexId: string,
@Param('id') id: string,
) {
): Promise<ComplexPosesServiceFindOneResponseDto> {
return this.service.findOne(businessActivityId, complexId, id)
}
@@ -0,0 +1,4 @@
import type { BusinessActivitiesService } from '../business-activities.service'
export type BusinessActivitiesServiceFindAllResponseDto = Awaited<ReturnType<BusinessActivitiesService['findAll']>>
export type BusinessActivitiesServiceFindOneResponseDto = Awaited<ReturnType<BusinessActivitiesService['findOne']>>
@@ -1,17 +1,18 @@
import { Controller, Get, Param } from '@nestjs/common'
import { AdminConsumersService } from './consumers.service'
import type { AdminConsumersServiceFindAllResponseDto, AdminConsumersServiceFindOneResponseDto } from './dto/consumers-response.dto'
@Controller('admin/consumers')
export class AdminUsersController {
constructor(private readonly usersService: AdminConsumersService) {}
@Get()
async findAll() {
async findAll(): Promise<AdminConsumersServiceFindAllResponseDto> {
return this.usersService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<AdminConsumersServiceFindOneResponseDto> {
return this.usersService.findOne(id)
}
@@ -1,5 +1,6 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
import { ConsumerSelect } from '@/generated/prisma/models'
import mapConsumerWithLicenseUtil from '@/modules/consumer/utils/mapConsumerWithLicense.util'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
import { ResponseMapper } from 'common/response/response-mapper'
@@ -8,41 +9,41 @@ import { ResponseMapper } from 'common/response/response-mapper'
export class AdminConsumersService {
constructor(private readonly prisma: PrismaService) {}
private readonly now = new Date()
private readonly defaultSelect: ConsumerSelect = {
id: true,
first_name: true,
last_name: true,
mobile_number: true,
type: true,
...QUERY_CONSTANTS.CONSUMER.infoSelect,
status: true,
partner: {
created_at: true,
_count: {
select: {
id: true,
name: true,
code: true,
business_activities: {
where: {
license_activation: {
OR: [
{
expires_at: {
gt: this.now,
},
},
{
license_renews: {
some: {
expires_at: {
gt: this.now,
},
},
},
},
],
},
},
},
},
},
created_at: true,
// activation: {
// select: {
// id: true,
// starts_at: true,
// expires_at: true,
// license: {
// select: {
// charge_transaction: {
// select: {
// partner: {
// select: {
// id: true,
// name: true,
// },
// },
// },
// },
// },
// },
// },
// },
}
async findAll() {
@@ -53,7 +54,7 @@ export class AdminConsumersService {
this.prisma.consumer.count(),
])
return ResponseMapper.paginate(consumers.map(mapConsumerWithLicenseUtil), { total })
return ResponseMapper.paginate(consumers.map(consumer_mappersUtil), { total })
}
async findOne(id: string) {
@@ -62,7 +63,7 @@ export class AdminConsumersService {
select: this.defaultSelect,
})
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
return ResponseMapper.single(consumer_mappersUtil(consumer))
}
// async create(data: CreateConsumerDto) {
@@ -72,7 +73,7 @@ export class AdminConsumersService {
// const { username, password, partner_id, ...rest } = data
// const dataToCreate: ConsumerCreateInput = {
// ...rest,
// consumer_accounts: {
// accounts: {
// create: {
// role: ConsumerRole.OWNER,
// account: {
@@ -0,0 +1,4 @@
import type { AdminConsumersService } from '../consumers.service'
export type AdminConsumersServiceFindAllResponseDto = Awaited<ReturnType<AdminConsumersService['findAll']>>
export type AdminConsumersServiceFindOneResponseDto = Awaited<ReturnType<AdminConsumersService['findOne']>>
@@ -0,0 +1,3 @@
import type { LicensesService } from '../licenses.service'
export type LicensesServiceFindAllResponseDto = Awaited<ReturnType<LicensesService['findAll']>>
@@ -1,6 +1,7 @@
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')
@@ -8,7 +9,7 @@ export class LicensesController {
constructor(private readonly service: LicensesService) {}
@Get()
async findAll(@Param('consumerId') consumerId: string) {
async findAll(@Param('consumerId') consumerId: string): Promise<LicensesServiceFindAllResponseDto> {
return this.service.findAll(consumerId)
}
@@ -2,33 +2,34 @@ import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/commo
import { DeviceBrandsService } from './device-brands.service'
import { CreateDeviceBrandDto } from './dto/create-device-brand.dto'
import { UpdateDeviceBrandDto } from './dto/update-device-brand.dto'
import type { DeviceBrandsServiceCreateResponseDto, DeviceBrandsServiceDeleteResponseDto, DeviceBrandsServiceFindAllResponseDto, DeviceBrandsServiceFindOneResponseDto, DeviceBrandsServiceUpdateResponseDto } from './dto/device-brands-response.dto'
@Controller('admin/device_brands')
export class DeviceBrandsController {
constructor(private readonly deviceBrandsService: DeviceBrandsService) {}
@Get()
async findAll() {
async findAll(): Promise<DeviceBrandsServiceFindAllResponseDto> {
return this.deviceBrandsService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<DeviceBrandsServiceFindOneResponseDto> {
return this.deviceBrandsService.findOne(id)
}
@Post()
async create(@Body() data: CreateDeviceBrandDto) {
async create(@Body() data: CreateDeviceBrandDto): Promise<DeviceBrandsServiceCreateResponseDto> {
return this.deviceBrandsService.create(data)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateDeviceBrandDto) {
async update(@Param('id') id: string, @Body() data: UpdateDeviceBrandDto): Promise<DeviceBrandsServiceUpdateResponseDto> {
return this.deviceBrandsService.update(id, data)
}
@Delete(':id')
async delete(@Param('id') id: string) {
async delete(@Param('id') id: string): Promise<DeviceBrandsServiceDeleteResponseDto> {
return this.deviceBrandsService.delete(id)
}
}
@@ -0,0 +1,7 @@
import type { DeviceBrandsService } from '../device-brands.service'
export type DeviceBrandsServiceCreateResponseDto = Awaited<ReturnType<DeviceBrandsService['create']>>
export type DeviceBrandsServiceDeleteResponseDto = Awaited<ReturnType<DeviceBrandsService['delete']>>
export type DeviceBrandsServiceFindAllResponseDto = Awaited<ReturnType<DeviceBrandsService['findAll']>>
export type DeviceBrandsServiceFindOneResponseDto = Awaited<ReturnType<DeviceBrandsService['findOne']>>
export type DeviceBrandsServiceUpdateResponseDto = Awaited<ReturnType<DeviceBrandsService['update']>>
@@ -1,33 +1,34 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
import { DevicesService } from './devices.service'
import { CreateDeviceDto, UpdateDeviceDto } from './dto/device.dto'
import type { DevicesServiceCreateResponseDto, DevicesServiceDeleteResponseDto, DevicesServiceFindAllResponseDto, DevicesServiceFindOneResponseDto, DevicesServiceUpdateResponseDto } from './dto/devices-response.dto'
@Controller('admin/devices')
export class DevicesController {
constructor(private readonly devicesService: DevicesService) {}
@Get()
async findAll() {
async findAll(): Promise<DevicesServiceFindAllResponseDto> {
return this.devicesService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<DevicesServiceFindOneResponseDto> {
return this.devicesService.findOne(id)
}
@Post()
async create(@Body() data: CreateDeviceDto) {
async create(@Body() data: CreateDeviceDto): Promise<DevicesServiceCreateResponseDto> {
return this.devicesService.create(data)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateDeviceDto) {
async update(@Param('id') id: string, @Body() data: UpdateDeviceDto): Promise<DevicesServiceUpdateResponseDto> {
return this.devicesService.update(id, data)
}
@Delete(':id')
async delete(@Param('id') id: string) {
async delete(@Param('id') id: string): Promise<DevicesServiceDeleteResponseDto> {
return this.devicesService.delete(id)
}
}
@@ -0,0 +1,7 @@
import type { DevicesService } from '../devices.service'
export type DevicesServiceCreateResponseDto = Awaited<ReturnType<DevicesService['create']>>
export type DevicesServiceDeleteResponseDto = Awaited<ReturnType<DevicesService['delete']>>
export type DevicesServiceFindAllResponseDto = Awaited<ReturnType<DevicesService['findAll']>>
export type DevicesServiceFindOneResponseDto = Awaited<ReturnType<DevicesService['findOne']>>
export type DevicesServiceUpdateResponseDto = Awaited<ReturnType<DevicesService['update']>>
@@ -0,0 +1,6 @@
import type { GuildsService } from '../guilds.service'
export type GuildsServiceCreateResponseDto = Awaited<ReturnType<GuildsService['create']>>
export type GuildsServiceFindAllResponseDto = Awaited<ReturnType<GuildsService['findAll']>>
export type GuildsServiceFindOneResponseDto = Awaited<ReturnType<GuildsService['findOne']>>
export type GuildsServiceUpdateResponseDto = Awaited<ReturnType<GuildsService['update']>>
@@ -0,0 +1,6 @@
import type { GoodCategoriesService } from '../good-categories.service'
export type GoodCategoriesServiceCreateResponseDto = Awaited<ReturnType<GoodCategoriesService['create']>>
export type GoodCategoriesServiceFindAllResponseDto = Awaited<ReturnType<GoodCategoriesService['findAll']>>
export type GoodCategoriesServiceFindOneResponseDto = Awaited<ReturnType<GoodCategoriesService['findOne']>>
export type GoodCategoriesServiceUpdateResponseDto = Awaited<ReturnType<GoodCategoriesService['update']>>
@@ -0,0 +1,6 @@
import type { GoodsService } from '../goods.service'
export type GoodsServiceCreateResponseDto = Awaited<ReturnType<GoodsService['create']>>
export type GoodsServiceFindAllResponseDto = Awaited<ReturnType<GoodsService['findAll']>>
export type GoodsServiceFindOneResponseDto = Awaited<ReturnType<GoodsService['findOne']>>
export type GoodsServiceUpdateResponseDto = Awaited<ReturnType<GoodsService['update']>>
@@ -0,0 +1,6 @@
import type { GuildGoodImagesService } from '../images.service'
export type GuildGoodImagesServiceUploadFileResponseDto = Awaited<ReturnType<GuildGoodImagesService['uploadFile']>>
export type GuildGoodImagesControllerUploadImageResponseDto = {
url: GuildGoodImagesServiceUploadFileResponseDto
}
@@ -11,6 +11,7 @@ import {
import { FileInterceptor } from '@nestjs/platform-express'
import { ApiBody, ApiConsumes } from '@nestjs/swagger'
import { GuildGoodImagesService } from './images.service'
import type { GuildGoodImagesControllerUploadImageResponseDto } from './dto/images-response.dto'
@Controller('admin/guilds/:guildId/goods/:goodId/images')
export class GuildGoodImagesController {
@@ -32,7 +33,7 @@ export class GuildGoodImagesController {
@Param('guildId') guildId: string,
@Param('goodId') goodId: string,
@UploadedFile() file: Express.Multer.File,
) {
): Promise<GuildGoodImagesControllerUploadImageResponseDto> {
if (!file) {
throw new BadRequestException('فایل را وارد کنید')
}
+13 -4
View File
@@ -3,6 +3,12 @@ import { ApiTags } from '@nestjs/swagger'
import { CreateGuildDto } from './dto/create-guild.dto'
import { UpdateGuildDto } from './dto/update-guild.dto'
import { GuildsService } from './guilds.service'
import type {
GuildsServiceCreateResponseDto,
GuildsServiceFindAllResponseDto,
GuildsServiceFindOneResponseDto,
GuildsServiceUpdateResponseDto,
} from './dto/guilds-response.dto'
@ApiTags('guilds')
@Controller('admin/guilds')
@@ -10,22 +16,25 @@ export class GuildsController {
constructor(private readonly guildsService: GuildsService) {}
@Get()
async findAll() {
async findAll(): Promise<GuildsServiceFindAllResponseDto> {
return this.guildsService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<GuildsServiceFindOneResponseDto> {
return this.guildsService.findOne(id)
}
@Post()
async create(@Body() data: CreateGuildDto) {
async create(@Body() data: CreateGuildDto): Promise<GuildsServiceCreateResponseDto> {
return await this.guildsService.create(data)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateGuildDto) {
async update(
@Param('id') id: string,
@Body() data: UpdateGuildDto,
): Promise<GuildsServiceUpdateResponseDto> {
return await this.guildsService.update(id, data)
}
@@ -0,0 +1,4 @@
import type { PartnerLicensesService } from '../licenses.service'
export type PartnerLicensesServiceFindAllResponseDto = Awaited<ReturnType<PartnerLicensesService['findAll']>>
export type PartnerLicensesServiceFindOneResponseDto = Awaited<ReturnType<PartnerLicensesService['findOne']>>
@@ -1,17 +1,18 @@
import { Controller, Get, Param } from '@nestjs/common'
import { PartnerLicensesService } from './licenses.service'
import type { PartnerLicensesServiceFindAllResponseDto, PartnerLicensesServiceFindOneResponseDto } from './dto/licenses-response.dto'
@Controller('admin/licenses')
export class LicensesController {
constructor(private readonly licensesService: PartnerLicensesService) {}
@Get()
async findAll() {
async findAll(): Promise<PartnerLicensesServiceFindAllResponseDto> {
return this.licensesService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<PartnerLicensesServiceFindOneResponseDto> {
return this.licensesService.findOne(id)
}
+20 -4
View File
@@ -1,3 +1,5 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
import { LicenseActivationSelect } from '@/generated/prisma/models'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
@@ -18,8 +20,7 @@ export class PartnerLicensesService {
consumer: {
select: {
id: true,
first_name: true,
last_name: true,
...QUERY_CONSTANTS.CONSUMER.infoSelect,
},
},
},
@@ -49,7 +50,7 @@ export class PartnerLicensesService {
}
async findAll(page = 1, perPage = 10) {
const [licenses, total] = await this.prisma.$transaction([
const [activatedLicenses, total] = await this.prisma.$transaction([
this.prisma.licenseActivation.findMany({
select: this.licenseDefaultSelect,
skip: (page - 1) * perPage,
@@ -58,7 +59,22 @@ export class PartnerLicensesService {
this.prisma.licenseActivation.count(),
])
return ResponseMapper.paginate(licenses, {
const mappedLicenses = activatedLicenses.map(license => {
const { business_activity, ...rest } = license
const { consumer, ...businessActivityRest } = business_activity as any
const mappedConsumer = consumer_mappersUtil(consumer)
return {
...rest,
business_activity: {
...businessActivityRest,
mappedConsumer,
},
}
})
return ResponseMapper.paginate(activatedLicenses, {
total,
page,
perPage,
@@ -1,6 +1,7 @@
import { Controller, Get, Param } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { PartnerActivatedLicensesService } from './activatedLicenses.service'
import type { PartnerActivatedLicensesServiceFindAllResponseDto } from './dto/activatedLicenses-response.dto'
@ApiTags('AdminPartnerActivatedLicenses')
@Controller('admin/partners/:partnerId/activated-licenses')
@@ -8,7 +9,7 @@ export class PartnerLicensesController {
constructor(private readonly service: PartnerActivatedLicensesService) {}
@Get()
async findAll(@Param('partnerId') partnerId: string) {
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerActivatedLicensesServiceFindAllResponseDto> {
return this.service.findAll(partnerId)
}
@@ -1,3 +1,5 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
import { LicenseActivationWhereInput } from '@/generated/prisma/models'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
@@ -15,7 +17,7 @@ export class PartnerActivatedLicensesService {
},
},
}
const [licenses, total] = await this.prisma.$transaction(async tx => [
const [activatedLicense, total] = await this.prisma.$transaction(async tx => [
await tx.licenseActivation.findMany({
where: defaultWhere,
skip: (page - 1) * perPage,
@@ -38,8 +40,7 @@ export class PartnerActivatedLicensesService {
consumer: {
select: {
id: true,
first_name: true,
last_name: true,
...QUERY_CONSTANTS.CONSUMER.infoSelect,
},
},
},
@@ -51,8 +52,11 @@ export class PartnerActivatedLicensesService {
}),
])
const mappedLicenses = licenses.map(license => {
const mappedLicenses = activatedLicense.map(license => {
const { account_allocations, business_activity, ...rest } = license
const { consumer, ...businessActivityRest } = business_activity
const mappedConsumer = consumer_mappersUtil(consumer)
return {
...rest,
@@ -64,7 +68,7 @@ export class PartnerActivatedLicensesService {
},
business_activity: {
...business_activity,
consumer_name: `${business_activity.consumer.first_name} ${business_activity.consumer.last_name}`,
consumer_name: mappedConsumer.name,
},
}
})
@@ -0,0 +1,4 @@
import type { PartnerActivatedLicensesService } from '../activatedLicenses.service'
export type PartnerActivatedLicensesServiceDeleteResponseDto = Awaited<ReturnType<PartnerActivatedLicensesService['delete']>>
export type PartnerActivatedLicensesServiceFindAllResponseDto = Awaited<ReturnType<PartnerActivatedLicensesService['findAll']>>
@@ -1,6 +1,7 @@
import { Controller, Get, Param } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { PartnerAllocatedAccountsService } from './allocatedAccounts.service'
import type { PartnerAllocatedAccountsServiceFindAllResponseDto } from './dto/allocatedAccounts-response.dto'
@ApiTags('AdminPartnerAllocatedAccounts')
@Controller('admin/partners/:partnerId/allocated-accounts')
@@ -8,7 +9,7 @@ export class PartnerAllocatedAccountsController {
constructor(private readonly service: PartnerAllocatedAccountsService) {}
@Get()
async findAll(@Param('partnerId') partnerId: string) {
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerAllocatedAccountsServiceFindAllResponseDto> {
return this.service.findAll(partnerId)
}
}
@@ -0,0 +1,3 @@
import type { PartnerAllocatedAccountsService } from '../allocatedAccounts.service'
export type PartnerAllocatedAccountsServiceFindAllResponseDto = Awaited<ReturnType<PartnerAllocatedAccountsService['findAll']>>
@@ -2,6 +2,7 @@ import { Body, Controller, Get, Param, Post } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { PartnerAccountChargeTransactionService } from './chargeAccountQuotaTransactions.service'
import { ChargeAccountQuotaDto } from './dto/chargeAccountQuotaTransactions.dto'
import type { PartnerAccountChargeTransactionServiceCreateResponseDto, PartnerAccountChargeTransactionServiceFindAllResponseDto, PartnerAccountChargeTransactionServiceFindOneResponseDto } from './dto/chargeAccountQuotaTransactions-response.dto'
@ApiTags('Admin Partner Account Charge')
@Controller('admin/partners/:partnerId/charge-account-transactions')
@@ -9,12 +10,12 @@ export class PartnerAccountChargeTransactionController {
constructor(private readonly service: PartnerAccountChargeTransactionService) {}
@Get()
async findAll(@Param('partnerId') partnerId: string) {
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerAccountChargeTransactionServiceFindAllResponseDto> {
return this.service.findAll(partnerId)
}
@Get(':id')
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string) {
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string): Promise<PartnerAccountChargeTransactionServiceFindOneResponseDto> {
return this.service.findOne(partnerId, id)
}
@@ -22,7 +23,7 @@ export class PartnerAccountChargeTransactionController {
async create(
@Param('partnerId') partnerId: string,
@Body() data: ChargeAccountQuotaDto,
) {
): Promise<PartnerAccountChargeTransactionServiceCreateResponseDto> {
return this.service.create(partnerId, data)
}
@@ -0,0 +1,5 @@
import type { PartnerAccountChargeTransactionService } from '../chargeAccountQuotaTransactions.service'
export type PartnerAccountChargeTransactionServiceCreateResponseDto = Awaited<ReturnType<PartnerAccountChargeTransactionService['create']>>
export type PartnerAccountChargeTransactionServiceFindAllResponseDto = Awaited<ReturnType<PartnerAccountChargeTransactionService['findAll']>>
export type PartnerAccountChargeTransactionServiceFindOneResponseDto = Awaited<ReturnType<PartnerAccountChargeTransactionService['findOne']>>
@@ -2,6 +2,7 @@ import { Body, Controller, Get, Param, Post } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { PartnerLicenseChargeTransactionService } from './chargedLicenseTransactions.service'
import { ChargeLicenseDto } from './dto/chargedLicenseTransactions.dto'
import type { PartnerLicenseChargeTransactionServiceCreateResponseDto, PartnerLicenseChargeTransactionServiceFindAllResponseDto, PartnerLicenseChargeTransactionServiceFindOneResponseDto } from './dto/chargedLicenseTransactions-response.dto'
@ApiTags('AdminPartnerLicenseChargeTransaction')
@Controller('admin/partners/:partnerId/charge-license-transactions')
@@ -9,17 +10,17 @@ export class PartnerLicenseChargeTransactionController {
constructor(private readonly service: PartnerLicenseChargeTransactionService) {}
@Get()
async findAll(@Param('partnerId') partnerId: string) {
async findAll(@Param('partnerId') partnerId: string): Promise<PartnerLicenseChargeTransactionServiceFindAllResponseDto> {
return this.service.findAll(partnerId)
}
@Get(':id')
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string) {
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string): Promise<PartnerLicenseChargeTransactionServiceFindOneResponseDto> {
return this.service.findOne(partnerId, id)
}
@Post()
async create(@Param('partnerId') partnerId: string, @Body() data: ChargeLicenseDto) {
async create(@Param('partnerId') partnerId: string, @Body() data: ChargeLicenseDto): Promise<PartnerLicenseChargeTransactionServiceCreateResponseDto> {
return this.service.create(partnerId, data)
}
@@ -0,0 +1,5 @@
import type { PartnerLicenseChargeTransactionService } from '../chargedLicenseTransactions.service'
export type PartnerLicenseChargeTransactionServiceCreateResponseDto = Awaited<ReturnType<PartnerLicenseChargeTransactionService['create']>>
export type PartnerLicenseChargeTransactionServiceFindAllResponseDto = Awaited<ReturnType<PartnerLicenseChargeTransactionService['findAll']>>
export type PartnerLicenseChargeTransactionServiceFindOneResponseDto = Awaited<ReturnType<PartnerLicenseChargeTransactionService['findOne']>>
@@ -23,6 +23,10 @@ export class CreatePartnerDto {
@IsString()
@ApiProperty({ required: true })
password: string
@IsOptional()
@ApiProperty({ required: false, type: 'string', format: 'binary' })
logo?: any
}
export class UpdatePartnerDto extends PartialType(CreatePartnerDto) {
@@ -0,0 +1,7 @@
import type { PartnersService } from '../partners.service'
export type PartnersServiceCreateResponseDto = Awaited<ReturnType<PartnersService['create']>>
export type PartnersServiceDeleteResponseDto = Awaited<ReturnType<PartnersService['delete']>>
export type PartnersServiceFindAllResponseDto = Awaited<ReturnType<PartnersService['findAll']>>
export type PartnersServiceFindOneResponseDto = Awaited<ReturnType<PartnersService['findOne']>>
export type PartnersServiceUpdateResponseDto = Awaited<ReturnType<PartnersService['update']>>
@@ -1,18 +1,19 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
import { AccountsService } from './accounts.service'
import { CreatePartnerAccountDto, UpdateAccountDto } from './dto/account.dto'
import type { AccountsServiceCreateResponseDto, AccountsServiceDeleteResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
@Controller('admin/partners/:partnerId/accounts')
export class AccountsController {
constructor(private readonly accountsService: AccountsService) {}
@Get()
async findAll(@Param('partnerId') partnerId: string) {
async findAll(@Param('partnerId') partnerId: string): Promise<AccountsServiceFindAllResponseDto> {
return this.accountsService.findAll(partnerId)
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<AccountsServiceFindOneResponseDto> {
return this.accountsService.findOne(id)
}
@@ -20,17 +21,17 @@ export class AccountsController {
async create(
@Param('partnerId') partnerId: string,
@Body() data: CreatePartnerAccountDto,
) {
): Promise<AccountsServiceCreateResponseDto> {
return this.accountsService.create(partnerId, data)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
return this.accountsService.update(id, data)
}
@Delete(':id')
async delete(@Param('id') id: string) {
async delete(@Param('id') id: string): Promise<AccountsServiceDeleteResponseDto> {
return this.accountsService.delete(id)
}
}
@@ -0,0 +1,7 @@
import type { AccountsService } from '../accounts.service'
export type AccountsServiceCreateResponseDto = Awaited<ReturnType<AccountsService['create']>>
export type AccountsServiceDeleteResponseDto = Awaited<ReturnType<AccountsService['delete']>>
export type AccountsServiceFindAllResponseDto = Awaited<ReturnType<AccountsService['findAll']>>
export type AccountsServiceFindOneResponseDto = Awaited<ReturnType<AccountsService['findOne']>>
export type AccountsServiceUpdateResponseDto = Awaited<ReturnType<AccountsService['update']>>
@@ -1,4 +1,16 @@
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
import { multerImageOptions } from '@/multer.config'
import {
Body,
Controller,
Get,
Param,
Patch,
Post,
UploadedFile,
UseInterceptors,
} from '@nestjs/common'
import { FileInterceptor } from '@nestjs/platform-express'
import { ApiBody, ApiConsumes } from '@nestjs/swagger'
import { CreatePartnerDto, UpdatePartnerDto } from './dto/partner.dto'
import { PartnersService } from './partners.service'
@@ -7,23 +19,47 @@ export class PartnersController {
constructor(private readonly partnersService: PartnersService) {}
@Get()
async findAll() {
async findAll(): Promise<PartnersServiceFindAllResponseDto> {
return this.partnersService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<PartnersServiceFindOneResponseDto> {
return this.partnersService.findOne(id)
}
@Post()
async create(@Body() data: CreatePartnerDto) {
return this.partnersService.create(data)
@UseInterceptors(FileInterceptor('logo', multerImageOptions))
@ApiConsumes('multipart/form-data')
@ApiBody({
schema: {
type: 'object',
properties: {
logo: { type: 'string', format: 'binary' },
},
},
})
async create(@Body() data: CreatePartnerDto, @UploadedFile() logo: any): Promise<PartnersServiceCreateResponseDto> {
return this.partnersService.create(data, logo)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdatePartnerDto) {
return this.partnersService.update(id, data)
@UseInterceptors(FileInterceptor('logo', multerImageOptions))
@ApiConsumes('multipart/form-data')
@ApiBody({
schema: {
type: 'object',
properties: {
logo: { type: 'string', format: 'binary' },
},
},
})
async update(
@Param('id') id: string,
@Body() data: UpdatePartnerDto,
@UploadedFile() logo: Express.Multer.File,
): Promise<PartnersServiceUpdateResponseDto> {
return this.partnersService.update(id, data, logo)
}
// @Delete(':id')
@@ -31,3 +67,5 @@ export class PartnersController {
// return this.partnersService.delete(id)
// }
}
import type { PartnersServiceCreateResponseDto, PartnersServiceFindAllResponseDto, PartnersServiceFindOneResponseDto, PartnersServiceUpdateResponseDto } from './dto/partners-response.dto'
@@ -1,3 +1,4 @@
import { UploaderModule } from '@/modules/uploader/uploader.module'
import { PrismaModule } from '@/prisma/prisma.module'
import { Module } from '@nestjs/common'
@@ -11,6 +12,7 @@ import { PartnersService } from './partners.service'
@Module({
imports: [
PrismaModule,
UploaderModule,
AdminPartnerLicenseChargeTransactionModule,
AdminPartnerActivatedLicensesModule,
// AdminPartnerAllocatedAccountsModule,
+50 -10
View File
@@ -1,3 +1,4 @@
import { UploadedFileTypes } from '@/common/enums/enums'
import { PasswordUtil } from '@/common/utils/password.util'
import {
AccountStatus,
@@ -6,6 +7,7 @@ import {
PartnerStatus,
} from '@/generated/prisma/enums'
import { PartnerSelect } from '@/generated/prisma/models'
import { UploaderService } from '@/modules/uploader/uploader.service'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
import { ResponseMapper } from 'common/response/response-mapper'
@@ -14,13 +16,17 @@ import { CreatePartnerDto, UpdatePartnerDto } from './dto/partner.dto'
@Injectable()
export class PartnersService {
private now = new Date().getTime()
constructor(private readonly prisma: PrismaService) {}
constructor(
private readonly prisma: PrismaService,
private readonly uploaderService: UploaderService,
) {}
private readonly defaultSelect: PartnerSelect = {
id: true,
name: true,
code: true,
status: true,
logo_url: true,
created_at: true,
license_charge_transactions: {
select: {
@@ -145,19 +151,26 @@ export class PartnersService {
return ResponseMapper.single(this.mapPartner(partner))
}
async create(data: CreatePartnerDto) {
const { username, password, ...rest } = data
async create(data: CreatePartnerDto, logo?: any) {
const { username, password, ...rest } = data as any
delete rest.logo
const logo_url = logo
? await this.uploaderService.uploadFile(logo, UploadedFileTypes.PARTNER_LOGO)
: undefined
const partner = await this.prisma.partner.create({
data: {
...rest,
status: PartnerStatus.ACTIVE,
partner_accounts: {
...(logo_url ? { logo_url } : {}),
accounts: {
create: {
role: PartnerRole.OWNER,
account: {
create: {
username,
password: await PasswordUtil.hash(data.password),
password: await PasswordUtil.hash(password),
status: AccountStatus.ACTIVE,
type: AccountType.PARTNER,
},
@@ -170,12 +183,39 @@ export class PartnersService {
return ResponseMapper.create(partner)
}
async update(id: string, data: UpdatePartnerDto) {
const partner = await this.prisma.partner.update({
where: { id },
data,
select: this.defaultSelect,
async update(id: string, data: UpdatePartnerDto, logo?: any) {
const rest = { ...(data as any) }
delete rest.logo
const partner = await this.prisma.$transaction(async tx => {
let logo_url = ''
if (logo) {
const uploadedUrl = await this.uploaderService.uploadFile(
logo,
UploadedFileTypes.PARTNER_LOGO,
)
logo_url = uploadedUrl || ''
}
const prevLogo = await tx.partner.findUnique({
where: { id },
select: { logo_url: true },
})
if (logo_url && prevLogo?.logo_url) {
this.uploaderService.deleteFile(prevLogo.logo_url, UploadedFileTypes.PARTNER_LOGO)
}
return tx.partner.update({
where: { id },
data: {
...rest,
...(logo_url ? { logo_url } : {}),
},
select: this.defaultSelect,
})
})
return ResponseMapper.update(partner)
}
@@ -0,0 +1,6 @@
import type { ProvidersService } from '../providers.service'
export type ProvidersServiceCreateResponseDto = Awaited<ReturnType<ProvidersService['create']>>
export type ProvidersServiceFindAllResponseDto = Awaited<ReturnType<ProvidersService['findAll']>>
export type ProvidersServiceFindOneResponseDto = Awaited<ReturnType<ProvidersService['findOne']>>
export type ProvidersServiceUpdateResponseDto = Awaited<ReturnType<ProvidersService['update']>>
@@ -2,6 +2,7 @@ import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { CreateProviderDto, UpdateProviderDto } from './dto/provider.dto'
import { ProvidersService } from './providers.service'
import type { ProvidersServiceCreateResponseDto, ProvidersServiceFindAllResponseDto, ProvidersServiceFindOneResponseDto, ProvidersServiceUpdateResponseDto } from './dto/providers-response.dto'
@ApiTags('Admin Providers')
@Controller('admin/providers')
@@ -9,22 +10,22 @@ export class ProvidersController {
constructor(private readonly providersService: ProvidersService) {}
@Get()
async findAll() {
async findAll(): Promise<ProvidersServiceFindAllResponseDto> {
return this.providersService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<ProvidersServiceFindOneResponseDto> {
return this.providersService.findOne(id)
}
@Post()
async create(@Body() data: CreateProviderDto) {
async create(@Body() data: CreateProviderDto): Promise<ProvidersServiceCreateResponseDto> {
return this.providersService.create(data)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateProviderDto) {
async update(@Param('id') id: string, @Body() data: UpdateProviderDto): Promise<ProvidersServiceUpdateResponseDto> {
return this.providersService.update(id, data)
}
@@ -27,7 +27,7 @@ export class ProvidersService {
const provider = await this.prisma.provider.create({
data: {
...rest,
provider_accounts: {
accounts: {
create: {
role: ProviderRole.OWNER,
account: {
@@ -0,0 +1,3 @@
import type { TranslateService } from '../translate.service'
export type TranslateServiceGetTranslationsResponseDto = Awaited<ReturnType<TranslateService['getTranslations']>>
@@ -1,12 +1,13 @@
import { Controller, Get } from '@nestjs/common'
import { TranslateService } from './translate.service'
import type { TranslateServiceGetTranslationsResponseDto } from './dto/translate-response.dto'
@Controller('admin/translates')
export class TranslateController {
constructor(private readonly translateService: TranslateService) {}
@Get()
async getTranslations() {
async getTranslations(): Promise<TranslateServiceGetTranslationsResponseDto> {
return this.translateService.getTranslations()
}
}
@@ -40,11 +40,11 @@ export class TranslateService {
guild_goods: 'کالا',
guild_good_categories: 'دسته‌بندی کالا',
partners: 'شریک تجاری',
partner_accounts: 'حساب',
accounts: 'حساب',
partner_licenses: 'مجوز',
providers: 'ارائه‌دهنده',
provider_accounts: 'حساب',
accounts: 'حساب کاربری',
// accounts: 'حساب',
// accounts: 'حساب کاربری',
licenses: 'لایسنس',
business_activities: 'فعالیت‌ اقتصادی',
},
@@ -56,11 +56,11 @@ export class TranslateService {
guild_goods: 'کالاها',
guild_good_categories: 'دسته‌بندی کالاها',
partners: 'شرکای تجاری',
partner_accounts: 'حساب‌های شریک تجاری',
accounts: 'حساب‌های شریک تجاری',
partner_licenses: 'مجوزهای داده شده',
providers: 'ارائه‌دهندگان',
provider_accounts: 'حساب‌های ارائه‌دهنده',
accounts: 'حساب‌های کاربری',
// accounts: 'حساب‌های ارائه‌دهنده',
// accounts: 'حساب‌های کاربری',
licenses: 'لایسنس‌ها',
business_activities: 'فعالیت‌های اقتصادی',
},
@@ -2,29 +2,30 @@ import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { AccountsService } from './accounts.service'
import { CreateAccountDto, UpdateAccountDto } from './dto/account.dto'
import type { AccountsServiceCreateResponseDto, AccountsServiceFindAllResponseDto, AccountsServiceFindOneResponseDto, AccountsServiceUpdateResponseDto } from './dto/accounts-response.dto'
@ApiTags('AdminAccounts')
@ApiTags('accounts')
@Controller('admin/users/:userId/accounts')
export class AccountsController {
constructor(private readonly accountsService: AccountsService) {}
@Get()
async findAll(@Param('userId') userId: string) {
async findAll(@Param('userId') userId: string): Promise<AccountsServiceFindAllResponseDto> {
return this.accountsService.findAll(userId)
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<AccountsServiceFindOneResponseDto> {
return this.accountsService.findOne(id)
}
@Post()
async create(@Param('userId') userId: string, @Body() data: CreateAccountDto) {
async create(@Param('userId') userId: string, @Body() data: CreateAccountDto): Promise<AccountsServiceCreateResponseDto> {
return this.accountsService.create(userId, data)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
return this.accountsService.update(id, data)
}
@@ -0,0 +1,7 @@
import type { AccountsService } from '../accounts.service'
export type AccountsServiceCreateResponseDto = Awaited<ReturnType<AccountsService['create']>>
export type AccountsServiceDeleteResponseDto = Awaited<ReturnType<AccountsService['delete']>>
export type AccountsServiceFindAllResponseDto = Awaited<ReturnType<AccountsService['findAll']>>
export type AccountsServiceFindOneResponseDto = Awaited<ReturnType<AccountsService['findOne']>>
export type AccountsServiceUpdateResponseDto = Awaited<ReturnType<AccountsService['update']>>
@@ -0,0 +1,7 @@
import type { AdminUsersService } from '../users.service'
export type AdminUsersServiceCreateResponseDto = Awaited<ReturnType<AdminUsersService['create']>>
export type AdminUsersServiceDeleteResponseDto = Awaited<ReturnType<AdminUsersService['delete']>>
export type AdminUsersServiceFindAllResponseDto = Awaited<ReturnType<AdminUsersService['findAll']>>
export type AdminUsersServiceFindOneResponseDto = Awaited<ReturnType<AdminUsersService['findOne']>>
export type AdminUsersServiceUpdateResponseDto = Awaited<ReturnType<AdminUsersService['update']>>
+6 -5
View File
@@ -1,33 +1,34 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
import { CreateUserDto, UpdateUserDto } from './dto/user.dto'
import { AdminUsersService } from './users.service'
import type { AdminUsersServiceCreateResponseDto, AdminUsersServiceDeleteResponseDto, AdminUsersServiceFindAllResponseDto, AdminUsersServiceFindOneResponseDto, AdminUsersServiceUpdateResponseDto } from './dto/users-response.dto'
@Controller('admin/users')
export class AdminUsersController {
constructor(private readonly usersService: AdminUsersService) {}
@Get()
async findAll() {
async findAll(): Promise<AdminUsersServiceFindAllResponseDto> {
return this.usersService.findAll()
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<AdminUsersServiceFindOneResponseDto> {
return this.usersService.findOne(id)
}
@Post()
async create(@Body() data: any) {
async create(@Body() data: any): Promise<AdminUsersServiceCreateResponseDto> {
return this.usersService.create(data as CreateUserDto)
}
@Patch(':id')
async update(@Param('id') id: string, @Body() data: any) {
async update(@Param('id') id: string, @Body() data: any): Promise<AdminUsersServiceUpdateResponseDto> {
return this.usersService.update(id, data as UpdateUserDto)
}
@Delete(':id')
async delete(@Param('id') id: string) {
async delete(@Param('id') id: string): Promise<AdminUsersServiceDeleteResponseDto> {
return this.usersService.delete(id)
}
}
@@ -43,7 +43,7 @@ export class PosMiddleware implements NestMiddleware {
complex: {
business_activity: {
consumer: {
consumer_accounts: {
accounts: {
some: {
id: account_id,
},
@@ -0,0 +1,3 @@
import type { ApplicationAuthService } from '../auth.service'
export type ApplicationAuthServiceLoginResponseDto = Awaited<ReturnType<ApplicationAuthService['login']>>
@@ -1,3 +1,4 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import { ConsumerDevicesSelect } from '@/generated/prisma/models'
import { PrismaService } from '@/prisma/prisma.service'
import { BadRequestException, Injectable } from '@nestjs/common'
@@ -24,8 +25,7 @@ export class ConfigService {
consumer: {
select: {
id: true,
first_name: true,
last_name: true,
...QUERY_CONSTANTS.CONSUMER.infoSelect,
},
},
}
@@ -0,0 +1,4 @@
import type { ConfigService } from '../config.service'
export type ConfigServiceCreateResponseDto = Awaited<ReturnType<ConfigService['create']>>
export type ConfigServiceFindOneResponseDto = Awaited<ReturnType<ConfigService['findOne']>>
@@ -0,0 +1,3 @@
import type { AppService } from '../application.service'
export type AppServiceCheckVersionResponseDto = Awaited<ReturnType<AppService['checkVersion']>>
+2 -1
View File
@@ -4,6 +4,7 @@ import { ApiTags } from '@nestjs/swagger'
import { AuthService } from './auth.service'
import { reqTokenPayload } from './current-user.decorator'
import { LoginDto } from './dto/login.dto'
import type { AuthServiceMeResponseDto } from './dto/auth-response.dto'
@ApiTags('auth')
@Controller('auth')
@@ -44,7 +45,7 @@ export class AuthController {
}
@Get('me')
async me(@reqTokenPayload() user: any) {
async me(@reqTokenPayload() user: any): Promise<AuthServiceMeResponseDto> {
return this.auth.me(user.username)
}
}
+8 -5
View File
@@ -1,3 +1,5 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
import { PasswordUtil } from '@/common/utils/password.util'
import { Account } from '@/generated/prisma/client'
import { AccountType } from '@/generated/prisma/enums'
@@ -85,9 +87,8 @@ export class AuthUtils {
consumer: {
select: {
id: true,
first_name: true,
last_name: true,
mobile_number: true,
type: true,
...QUERY_CONSTANTS.CONSUMER.infoSelect,
},
},
},
@@ -99,12 +100,14 @@ export class AuthUtils {
throw new NotFoundException('متاسفانه کاربر شما یافت نشد')
const { consumer, id, role } = consumerAccount.consumer_account
const { legal, individual, id: userId, type, name } = consumer_mappersUtil(consumer)
return {
account_id: id,
role,
user: {
...consumer,
fullname: `${consumer.first_name} ${consumer.last_name}`,
id: userId,
type,
fullname: name,
},
}
}
@@ -0,0 +1,5 @@
import type { AuthService } from '../auth.service'
export type AuthServiceLoginResponseDto = Awaited<ReturnType<AuthService['login']>>
export type AuthServiceMeResponseDto = Awaited<ReturnType<AuthService['me']>>
export type AuthServiceRefreshResponseDto = Awaited<ReturnType<AuthService['refresh']>>
+6 -5
View File
@@ -2,6 +2,7 @@ import { PublicWithToken } from '@/common/decorators/withToken.decorator'
import { Controller, Get, Param } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { CatalogsService } from './catalog.service'
import type { CatalogsServiceGetDeviceBrandsResponseDto, CatalogsServiceGetDevicesResponseDto, CatalogsServiceGetGuildGoodCategoriesResponseDto, CatalogsServiceGetGuildsResponseDto, CatalogsServiceGetProvidersResponseDto } from './dto/catalog-response.dto'
@ApiTags('Catalog')
@Controller('catalog')
@@ -10,31 +11,31 @@ export class CatalogsController {
@Get('guilds')
@PublicWithToken()
async getGuilds() {
async getGuilds(): Promise<CatalogsServiceGetGuildsResponseDto> {
return this.catalogService.getGuilds()
}
@Get('providers')
@PublicWithToken()
async getProviders() {
async getProviders(): Promise<CatalogsServiceGetProvidersResponseDto> {
return this.catalogService.getProviders()
}
@Get('devices')
@PublicWithToken()
async getDevices() {
async getDevices(): Promise<CatalogsServiceGetDevicesResponseDto> {
return this.catalogService.getDevices()
}
@Get('device_brands')
@PublicWithToken()
async getDeviceBrands() {
async getDeviceBrands(): Promise<CatalogsServiceGetDeviceBrandsResponseDto> {
return this.catalogService.getDeviceBrands()
}
@Get('guilds/:guildId/good_categories')
@PublicWithToken()
async getGuildGoodCategories(@Param('guildId') guild_id: string) {
async getGuildGoodCategories(@Param('guildId') guild_id: string): Promise<CatalogsServiceGetGuildGoodCategoriesResponseDto> {
return this.catalogService.getGuildGoodCategories(guild_id)
}
}
@@ -0,0 +1,7 @@
import type { CatalogsService } from '../catalog.service'
export type CatalogsServiceGetDeviceBrandsResponseDto = Awaited<ReturnType<CatalogsService['getDeviceBrands']>>
export type CatalogsServiceGetDevicesResponseDto = Awaited<ReturnType<CatalogsService['getDevices']>>
export type CatalogsServiceGetGuildGoodCategoriesResponseDto = Awaited<ReturnType<CatalogsService['getGuildGoodCategories']>>
export type CatalogsServiceGetGuildsResponseDto = Awaited<ReturnType<CatalogsService['getGuilds']>>
export type CatalogsServiceGetProvidersResponseDto = Awaited<ReturnType<CatalogsService['getProviders']>>
@@ -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('ConsumerAccounts')
@Controller('consumer/accounts')
@@ -10,12 +11,12 @@ export class AccountsController {
constructor(private readonly accountsService: AccountsService) {}
@Get()
async findAll(@TokenAccount('userId') consumerId: string) {
async findAll(@TokenAccount('userId') consumerId: string): Promise<AccountsServiceFindAllResponseDto> {
return this.accountsService.findAll(consumerId)
}
@Get(':id')
async findOne(@Param('id') id: string) {
async findOne(@Param('id') id: string): Promise<AccountsServiceFindOneResponseDto> {
return this.accountsService.findOne(id)
}
@@ -28,7 +29,7 @@ export class AccountsController {
// }
@Patch(':id')
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
async update(@Param('id') id: string, @Body() data: UpdateAccountDto): Promise<AccountsServiceUpdateResponseDto> {
return this.accountsService.update(id, data)
}
@@ -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']>>
@@ -0,0 +1,4 @@
import type { AccountsService } from '../permissions.service'
export type AccountsServiceCreateResponseDto = Awaited<ReturnType<AccountsService['create']>>
export type AccountsServiceFindAllResponseDto = Awaited<ReturnType<AccountsService['findAll']>>
@@ -3,6 +3,7 @@ import { Body, Controller, Get, Param, Put } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { UpdatePermissionDto } from './dto/permission.dto'
import { AccountsService } from './permissions.service'
import type { AccountsServiceCreateResponseDto, AccountsServiceFindAllResponseDto } from './dto/permissions-response.dto'
@ApiTags('ConsumerAccountPermissions')
@Controller('consumer/accounts/:accountId/permissions')
@@ -13,7 +14,7 @@ export class AccountPermissionsController {
async findAll(
@TokenAccount('userId') userId: string,
@Param('accountId') accountId: string,
) {
): Promise<AccountsServiceFindAllResponseDto> {
return this.service.findAll(userId, accountId)
}
@@ -22,7 +23,7 @@ export class AccountPermissionsController {
@Param('userId') userId: string,
@Param('accountId') accountId: string,
@Body() data: UpdatePermissionDto,
) {
): Promise<AccountsServiceCreateResponseDto> {
return this.service.create(userId, accountId, data)
}
}
@@ -70,7 +70,7 @@ export class AccountsService {
complex: {
business_activity: {
consumer: {
consumer_accounts: {
accounts: {
some: {
id: account_id,
},
@@ -112,9 +112,9 @@ export class AccountsService {
const businessActivities = await this.prisma.businessActivity.findMany({
where: {
consumer: {
consumer_accounts: {
accounts: {
some: {
account_id,
id: account_id,
},
},
},
@@ -2,18 +2,19 @@ import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
import { BusinessActivitiesService } from './business-activities.service'
import { UpdateBusinessActivityDto } from './dto/create-business-activities.dto'
import type { BusinessActivitiesServiceFindAllResponseDto, BusinessActivitiesServiceFindOneResponseDto, BusinessActivitiesServiceUpdateResponseDto } from './dto/business-activities-response.dto'
@Controller('consumer/business_activities')
export class BusinessActivitiesController {
constructor(private readonly service: BusinessActivitiesService) {}
@Get()
async findAll(@TokenAccount('userId') userId: string) {
async findAll(@TokenAccount('userId') userId: string): Promise<BusinessActivitiesServiceFindAllResponseDto> {
return this.service.findAll(userId)
}
@Get(':id')
async findOne(@TokenAccount('userId') userId: string, @Param('id') id: string) {
async findOne(@TokenAccount('userId') userId: string, @Param('id') id: string): Promise<BusinessActivitiesServiceFindOneResponseDto> {
return this.service.findOne(userId, id)
}
@@ -22,7 +23,7 @@ export class BusinessActivitiesController {
@TokenAccount('userId') userId: string,
@Param('id') id: string,
@Body() data: UpdateBusinessActivityDto,
) {
): Promise<BusinessActivitiesServiceUpdateResponseDto> {
return this.service.update(userId, id, data)
}
}
@@ -3,9 +3,14 @@ import { Module } from '@nestjs/common'
import { BusinessActivitiesController } from './business-activities.controller'
import { BusinessActivitiesService } from './business-activities.service'
import { ConsumerBusinessActivityComplexesModule } from './complexes/complexes.module'
import { ConsumerBusinessActivityGoodsModule } from './goods/goods.module'
@Module({
imports: [PrismaModule, ConsumerBusinessActivityComplexesModule],
imports: [
PrismaModule,
ConsumerBusinessActivityComplexesModule,
ConsumerBusinessActivityGoodsModule,
],
controllers: [BusinessActivitiesController],
providers: [BusinessActivitiesService],
})
@@ -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 { CreateConsumerComplexDto, UpdateConsumerComplexDto } from './dto/complex.dto'
import type { BusinessActivityComplexesServiceCreateResponseDto, BusinessActivityComplexesServiceFindAllResponseDto, BusinessActivityComplexesServiceFindOneResponseDto, BusinessActivityComplexesServiceUpdateResponseDto } from './dto/complexes-response.dto'
@ApiTags('AdminBusinessActivityComplexes')
@Controller('consumer/business_activities/:businessActivityId/complexes')
@@ -13,7 +14,7 @@ export class BusinessActivityComplexesController {
async findAll(
@ConsumerInfo('id') consumerId: string,
@Param('businessActivityId') businessActivityId: string,
) {
): Promise<BusinessActivityComplexesServiceFindAllResponseDto> {
return this.service.findAll(consumerId, businessActivityId)
}
@@ -22,7 +23,7 @@ export class BusinessActivityComplexesController {
@ConsumerInfo('id') consumerId: string,
@Param('businessActivityId') businessActivityId: string,
@Param('id') id: string,
) {
): Promise<BusinessActivityComplexesServiceFindOneResponseDto> {
return this.service.findOne(consumerId, businessActivityId, id)
}
@@ -31,7 +32,7 @@ export class BusinessActivityComplexesController {
@ConsumerInfo('id') consumerId: string,
@Param('businessActivityId') businessActivityId: string,
@Body() data: CreateConsumerComplexDto,
) {
): Promise<BusinessActivityComplexesServiceCreateResponseDto> {
return this.service.create(consumerId, businessActivityId, data)
}
@@ -41,7 +42,7 @@ export class BusinessActivityComplexesController {
@Param('businessActivityId') businessActivityId: string,
@Param('id') id: string,
@Body() data: UpdateConsumerComplexDto,
) {
): Promise<BusinessActivityComplexesServiceUpdateResponseDto> {
return this.service.update(consumerId, businessActivityId, id, data)
}
}
@@ -2,11 +2,10 @@ import { PrismaModule } from '@/prisma/prisma.module'
import { Module } from '@nestjs/common'
import { BusinessActivityComplexesController } from './complexes.controller'
import { BusinessActivityComplexesService } from './complexes.service'
import { ConsumerComplexGoodsModule } from './goods/goods.module'
import { ConsumerComplexPosesModule } from './poses/poses.module'
@Module({
imports: [PrismaModule, ConsumerComplexPosesModule, ConsumerComplexGoodsModule],
imports: [PrismaModule, ConsumerComplexPosesModule],
controllers: [BusinessActivityComplexesController],
providers: [BusinessActivityComplexesService],
})
@@ -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']>>
@@ -1,51 +0,0 @@
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { CreateGoodDto, UpdateGoodDto } from './dto/good.dto'
import { ConsumerComplexGoodsService } from './goods.service'
@ApiTags('ConsumerComplexGoods')
@Controller('consumer/business_activities/:businessActivityId/complexes/:complexId/goods')
export class ConsumerComplexGoodsController {
constructor(private readonly service: ConsumerComplexGoodsService) {}
@Get()
async findAll(
@TokenAccount('userId') userId: string,
@Param('businessActivityId') businessActivityId: string,
@Param('complexId') complexId: string,
) {
return this.service.findAll(userId, businessActivityId, complexId)
}
@Get(':id')
async findOne(
@TokenAccount('userId') userId: string,
@Param('businessActivityId') businessActivityId: string,
@Param('complexId') complexId: string,
@Param('id') id: string,
) {
return this.service.findOne(userId, businessActivityId, complexId, id)
}
@Post()
async create(@Param('complexId') complexId: string, @Body() data: CreateGoodDto) {
return this.service.create(complexId, data)
}
@Patch(':id')
async update(
@TokenAccount('userId') userId: string,
@Param('businessActivityId') businessActivityId: string,
@Param('complexId') complexId: string,
@Param('id') id: string,
@Body() data: UpdateGoodDto,
) {
return this.service.update(userId, businessActivityId, complexId, id, data)
}
// @Delete(':id')
// async delete(@Param('id') id: string) {
// return this.businessActivityAccountsService.delete(id)
// }
}
@@ -1,12 +0,0 @@
import { PrismaModule } from '@/prisma/prisma.module'
import { Module } from '@nestjs/common'
import { ConsumerComplexGoodsController } from './goods.controller'
import { ConsumerComplexGoodsService } from './goods.service'
@Module({
imports: [PrismaModule],
controllers: [ConsumerComplexGoodsController],
providers: [ConsumerComplexGoodsService],
exports: [ConsumerComplexGoodsService],
})
export class ConsumerComplexGoodsModule {}
@@ -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']>>
@@ -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('ConsumerComplexPoses')
@Controller('consumer/business_activities/:businessActivityId/complexes/:complexId/poses')
@@ -14,7 +15,7 @@ export class ComplexPosesController {
@ConsumerInfo('id') consumerId: string,
@Param('businessActivityId') businessActivityId: string,
@Param('complexId') complexId: string,
) {
): Promise<ComplexPosesServiceFindAllResponseDto> {
return this.service.findAll(consumerId, 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(consumerId, 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(consumerId, 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(consumerId, businessActivityId, complexId, id, data)
}
@@ -0,0 +1,4 @@
import type { SalesInvoicesService } from '../sales-invoices.service'
export type SalesInvoicesServiceFindAllResponseDto = Awaited<ReturnType<SalesInvoicesService['findAll']>>
export type SalesInvoicesServiceFindOneResponseDto = Awaited<ReturnType<SalesInvoicesService['findOne']>>
@@ -0,0 +1,5 @@
import type { SalesInvoiceItemsService } from '../sales-invoice-items.service'
export type SalesInvoiceItemsServiceCreateResponseDto = Awaited<ReturnType<SalesInvoiceItemsService['create']>>
export type SalesInvoiceItemsServiceFindAllResponseDto = Awaited<ReturnType<SalesInvoiceItemsService['findAll']>>
export type SalesInvoiceItemsServiceFindOneResponseDto = Awaited<ReturnType<SalesInvoiceItemsService['findOne']>>
@@ -0,0 +1,5 @@
import type { SalesInvoicePaymentsService } from '../sales-invoice-payments.service'
export type SalesInvoicePaymentsServiceCreateResponseDto = Awaited<ReturnType<SalesInvoicePaymentsService['create']>>
export type SalesInvoicePaymentsServiceFindAllResponseDto = Awaited<ReturnType<SalesInvoicePaymentsService['findAll']>>
export type SalesInvoicePaymentsServiceFindOneResponseDto = Awaited<ReturnType<SalesInvoicePaymentsService['findOne']>>
@@ -71,7 +71,7 @@ export class SalesInvoicesService {
customer: {
select: {
type: true,
customer_individual: {
individual: {
select: {
economic_code: true,
first_name: true,
@@ -80,7 +80,7 @@ export class SalesInvoicesService {
national_id: true,
},
},
customer_legal: {
legal: {
select: {
economic_code: true,
postal_code: true,
@@ -0,0 +1,5 @@
import type { BusinessActivitiesService } from '../business-activities.service'
export type BusinessActivitiesServiceFindAllResponseDto = Awaited<ReturnType<BusinessActivitiesService['findAll']>>
export type BusinessActivitiesServiceFindOneResponseDto = Awaited<ReturnType<BusinessActivitiesService['findOne']>>
export type BusinessActivitiesServiceUpdateResponseDto = Awaited<ReturnType<BusinessActivitiesService['update']>>
@@ -0,0 +1,6 @@
import type { ConsumerBusinessActivityGoodsService } from '../goods.service'
export type ConsumerBusinessActivityGoodsServiceCreateResponseDto = Awaited<ReturnType<ConsumerBusinessActivityGoodsService['create']>>
export type ConsumerBusinessActivityGoodsServiceFindAllResponseDto = Awaited<ReturnType<ConsumerBusinessActivityGoodsService['findAll']>>
export type ConsumerBusinessActivityGoodsServiceFindOneResponseDto = Awaited<ReturnType<ConsumerBusinessActivityGoodsService['findOne']>>
export type ConsumerBusinessActivityGoodsServiceUpdateResponseDto = Awaited<ReturnType<ConsumerBusinessActivityGoodsService['update']>>
@@ -0,0 +1,54 @@
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { CreateGoodDto, UpdateGoodDto } from './dto/good.dto'
import { ConsumerBusinessActivityGoodsService } from './goods.service'
import type { ConsumerBusinessActivityGoodsServiceCreateResponseDto, ConsumerBusinessActivityGoodsServiceFindAllResponseDto, ConsumerBusinessActivityGoodsServiceFindOneResponseDto, ConsumerBusinessActivityGoodsServiceUpdateResponseDto } from './dto/goods-response.dto'
@ApiTags('ConsumerBusinessActivityGoods')
@Controller('consumer/business_activities/:businessActivityId/goods')
export class ConsumerBusinessActivityGoodsController {
constructor(private readonly service: ConsumerBusinessActivityGoodsService) {}
@Get()
async findAll(
@TokenAccount('userId') consumer_id: string,
@Param('businessActivityId') businessActivityId: string,
): Promise<ConsumerBusinessActivityGoodsServiceFindAllResponseDto> {
return this.service.findAll(consumer_id, businessActivityId)
}
@Get(':id')
async findOne(
@TokenAccount('userId') consumer_id: string,
@Param('businessActivityId') businessActivityId: string,
@Param('id') id: string,
): Promise<ConsumerBusinessActivityGoodsServiceFindOneResponseDto> {
return this.service.findOne(consumer_id, businessActivityId, id)
}
@Post()
async create(
@Param('businessActivityId') businessActivityId: string,
@Body() data: CreateGoodDto,
): Promise<ConsumerBusinessActivityGoodsServiceCreateResponseDto> {
return this.service.create(businessActivityId, data)
}
@Patch(':id')
async update(
@TokenAccount('userId') consumer_id: string,
@Param('businessActivityId') businessActivityId: string,
@Param('id') id: string,
@Body() data: UpdateGoodDto,
): Promise<ConsumerBusinessActivityGoodsServiceUpdateResponseDto> {
return this.service.update(consumer_id, businessActivityId, id, data)
}
// @Delete(':id')
// async delete(@Param('id') id: string) {
// return this.businessActivityAccountsService.delete(id)
// }
}
@@ -0,0 +1,12 @@
import { PrismaModule } from '@/prisma/prisma.module'
import { Module } from '@nestjs/common'
import { ConsumerBusinessActivityGoodsController } from './goods.controller'
import { ConsumerBusinessActivityGoodsService } from './goods.service'
@Module({
imports: [PrismaModule],
controllers: [ConsumerBusinessActivityGoodsController],
providers: [ConsumerBusinessActivityGoodsService],
exports: [ConsumerBusinessActivityGoodsService],
})
export class ConsumerBusinessActivityGoodsModule {}
@@ -5,7 +5,7 @@ import { ResponseMapper } from 'common/response/response-mapper'
import { CreateGoodDto, UpdateGoodDto } from './dto/good.dto'
@Injectable()
export class ConsumerComplexGoodsService {
export class ConsumerBusinessActivityGoodsService {
constructor(private readonly prisma: PrismaService) {}
defaultSelect: GoodSelect = {
@@ -26,16 +26,12 @@ export class ConsumerComplexGoodsService {
created_at: true,
}
async findAll(consumer_id: string, business_activity_id: string, complex_id: string) {
async findAll(consumer_id: string, business_activity_id: string) {
const goods = await this.prisma.good.findMany({
where: {
complex_id,
complex: {
id: complex_id,
business_activity: {
id: business_activity_id,
consumer_id,
},
business_activity: {
id: business_activity_id,
consumer_id,
},
},
select: this.defaultSelect,
@@ -44,20 +40,12 @@ export class ConsumerComplexGoodsService {
return ResponseMapper.list(goods)
}
async findOne(
consumer_id: string,
business_activity_id: string,
complex_id: string,
id: string,
) {
async findOne(consumer_id: string, business_activity_id: string, id: string) {
const good = await this.prisma.good.findUnique({
where: {
complex: {
id: complex_id,
business_activity: {
id: business_activity_id,
consumer_id,
},
business_activity: {
id: business_activity_id,
consumer_id,
},
id,
},
@@ -66,15 +54,15 @@ export class ConsumerComplexGoodsService {
return ResponseMapper.single(good)
}
async create(complex_id: string, data: CreateGoodDto) {
async create(business_activity_id: string, data: CreateGoodDto) {
const { category_id, ...rest } = data
const good = await this.prisma.good.create({
data: {
...rest,
complex: {
business_activity: {
connect: {
id: complex_id,
id: business_activity_id,
},
},
category: {
@@ -90,26 +78,22 @@ export class ConsumerComplexGoodsService {
async update(
consumer_id: string,
business_activity_id: string,
complex_id: string,
id: string,
data: UpdateGoodDto,
) {
const { category_id, ...rest } = data
const good = await this.prisma.good.update({
where: {
complex: {
id: complex_id,
business_activity: {
id: business_activity_id,
consumer_id,
},
business_activity: {
id: business_activity_id,
consumer_id,
},
id,
},
data: {
complex: {
business_activity: {
connect: {
id: complex_id,
id: business_activity_id,
},
},
category: {
+2 -1
View File
@@ -2,6 +2,7 @@ import { ConsumerInfo } from '@/common/decorators/consumerInfo.decorator'
import { Controller, Get } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { ConsumerService } from './consumer.service'
import type { ConsumerServiceGetInfoResponseDto } from './dto/consumer-response.dto'
@ApiTags('Consumer')
@Controller('consumer')
@@ -9,7 +10,7 @@ export class ConsumerController {
constructor(private service: ConsumerService) {}
@Get('')
async findOne(@ConsumerInfo('id') consumerId: string) {
async findOne(@ConsumerInfo('id') consumerId: string): Promise<ConsumerServiceGetInfoResponseDto> {
return this.service.getInfo(consumerId)
}
}
+4 -5
View File
@@ -1,7 +1,8 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import { ResponseMapper } from '@/common/response/response-mapper'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
import mapConsumerWithLicenseUtil from './utils/mapConsumerWithLicense.util'
import consumer_mappersUtil from '../../common/utils/mappers/consumer_mappers.util'
@Injectable()
export class ConsumerService {
@@ -14,13 +15,11 @@ export class ConsumerService {
},
select: {
id: true,
first_name: true,
last_name: true,
mobile_number: true,
status: true,
...QUERY_CONSTANTS.CONSUMER.infoSelect,
},
})
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
return ResponseMapper.single(consumer_mappersUtil(consumer))
}
}
@@ -11,12 +11,12 @@ export class consumerCustomersController {
constructor(private readonly service: consumerCustomersService) {}
@Get()
async findAll(@ConsumerInfo('id') consumerId: string) {
async findAll(@ConsumerInfo('id') consumerId: string): Promise<consumerCustomersServiceFindAllResponseDto> {
return this.service.findAll(consumerId)
}
@Get(':id')
async findOne(@ConsumerInfo('id') consumerId: string, @Param('id') id: string) {
async findOne(@ConsumerInfo('id') consumerId: string, @Param('id') id: string): Promise<consumerCustomersServiceFindOneResponseDto> {
return this.service.findOne(consumerId, id)
}
@@ -25,7 +25,7 @@ export class consumerCustomersController {
@ConsumerInfo('id') consumerId: string,
@Param('id') id: string,
@Body() data: UpdateCustomerLegalDto,
) {
): Promise<consumerCustomersServiceUpdateLegalResponseDto> {
return this.service.updateLegal(consumerId, id, data)
}
@@ -34,7 +34,9 @@ export class consumerCustomersController {
@ConsumerInfo('id') consumerId: string,
@Param('id') id: string,
@Body() data: UpdateCustomerIndividualDto,
) {
): Promise<consumerCustomersServiceUpdateIndividualResponseDto> {
return this.service.updateIndividual(consumerId, id, data)
}
}
import type { consumerCustomersServiceFindAllResponseDto, consumerCustomersServiceFindOneResponseDto, consumerCustomersServiceUpdateIndividualResponseDto, consumerCustomersServiceUpdateLegalResponseDto } from './dto/customers-response.dto'
@@ -16,7 +16,7 @@ export class consumerCustomersService {
type: true,
is_favorite: true,
created_at: true,
customer_individual: {
individual: {
select: {
first_name: true,
last_name: true,
@@ -25,7 +25,7 @@ export class consumerCustomersService {
economic_code: true,
},
},
customer_legal: {
legal: {
select: {
company_name: true,
registration_number: true,
@@ -39,20 +39,16 @@ export class consumerCustomersService {
return {
OR: [
{
customer_individual: {
complex: {
business_activity: {
consumer_id,
},
individual: {
business_activity: {
consumer_id,
},
},
},
{
customer_legal: {
complex: {
business_activity: {
consumer_id,
},
legal: {
business_activity: {
consumer_id,
},
},
},
@@ -95,17 +91,15 @@ export class consumerCustomersService {
const customer = await this.prisma.customer.update({
where: {
id: customer_id,
customer_legal: {
complex: {
business_activity: {
consumer_id,
},
legal: {
business_activity: {
consumer_id,
},
},
},
data: {
is_favorite: data.is_favorite,
customer_legal: {
legal: {
update: {
...data,
},
@@ -124,18 +118,16 @@ export class consumerCustomersService {
const customer = await this.prisma.customer.update({
where: {
id: customer_id,
customer_individual: {
complex: {
business_activity: {
consumer_id,
},
individual: {
business_activity: {
consumer_id,
},
},
},
data: {
is_favorite: data.is_favorite,
customer_individual: {
individual: {
update: {
...data,
},
@@ -0,0 +1,6 @@
import type { consumerCustomersService } from '../customers.service'
export type consumerCustomersServiceFindAllResponseDto = Awaited<ReturnType<consumerCustomersService['findAll']>>
export type consumerCustomersServiceFindOneResponseDto = Awaited<ReturnType<consumerCustomersService['findOne']>>
export type consumerCustomersServiceUpdateIndividualResponseDto = Awaited<ReturnType<consumerCustomersService['updateIndividual']>>
export type consumerCustomersServiceUpdateLegalResponseDto = Awaited<ReturnType<consumerCustomersService['updateLegal']>>
@@ -0,0 +1,4 @@
import type { CustomerSaleInvoicesService } from '../sale-invoices.service'
export type CustomerSaleInvoicesServiceFindAllResponseDto = Awaited<ReturnType<CustomerSaleInvoicesService['findAll']>>
export type CustomerSaleInvoicesServiceFindOneResponseDto = Awaited<ReturnType<CustomerSaleInvoicesService['findOne']>>
@@ -2,6 +2,7 @@ import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
import { Controller, Get, Param } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { CustomerSaleInvoicesService } from './sale-invoices.service'
import type { CustomerSaleInvoicesServiceFindAllResponseDto, CustomerSaleInvoicesServiceFindOneResponseDto } from './dto/sale-invoices-response.dto'
@ApiTags('customerSaleInvoices')
@Controller('consumer/customers/:customerId/sale-invoices')
@@ -12,7 +13,7 @@ export class CustomerSaleInvoicesController {
async findAll(
@TokenAccount('userId') userId: string,
@Param('customerId') customerId: string,
) {
): Promise<CustomerSaleInvoicesServiceFindAllResponseDto> {
return this.service.findAll(userId, customerId)
}
@@ -21,7 +22,7 @@ export class CustomerSaleInvoicesController {
@TokenAccount('userId') userId: string,
@Param('customerId') customerId: string,
@Param('id') id: string,
) {
): Promise<CustomerSaleInvoicesServiceFindOneResponseDto> {
return this.service.findOne(userId, customerId, id)
}
}
@@ -1,3 +1,5 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
import { SalesInvoiceSelect, SalesInvoiceWhereInput } from '@/generated/prisma/models'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
@@ -7,7 +9,7 @@ import { ResponseMapper } from 'common/response/response-mapper'
export class CustomerSaleInvoicesService {
constructor(private readonly prisma: PrismaService) {}
defaultSelect: SalesInvoiceSelect = {
private readonly defaultSelect: SalesInvoiceSelect = {
id: true,
code: true,
invoice_date: true,
@@ -36,8 +38,7 @@ export class CustomerSaleInvoicesService {
role: true,
consumer: {
select: {
first_name: true,
last_name: true,
...QUERY_CONSTANTS.CONSUMER.infoSelect,
},
},
account: {
@@ -62,7 +63,7 @@ export class CustomerSaleInvoicesService {
},
}
const [accounts, total] = await this.prisma.$transaction(async tx => [
const [saleInvoices, total] = await this.prisma.$transaction(async tx => [
await tx.salesInvoice.findMany({
where: salesWhere,
select: {
@@ -81,11 +82,17 @@ export class CustomerSaleInvoicesService {
}),
])
const mappedAccounts = accounts.map(account => {
const { _count, ...rest } = account
const mappedAccounts = saleInvoices.map(saleInvoice => {
const { _count, consumer_account, ...rest } = saleInvoice
const { consumer, ...restConsumerAccount } = consumer_account as any
const mappedConsumer = consumer_mappersUtil(consumer)
return {
...rest,
items_count: _count.items,
consumer_account: {
...restConsumerAccount,
consumer: mappedConsumer,
},
}
})
@@ -97,7 +104,7 @@ export class CustomerSaleInvoicesService {
}
async findOne(consumer_id: string, customer_id: string, id: string) {
const account = await this.prisma.salesInvoice.findUniqueOrThrow({
const saleInvoice = await this.prisma.salesInvoice.findUniqueOrThrow({
where: {
id,
customer_id,
@@ -111,7 +118,6 @@ export class CustomerSaleInvoicesService {
},
select: {
...this.defaultSelect,
items: {
select: {
id: true,
@@ -147,6 +153,17 @@ export class CustomerSaleInvoicesService {
},
},
})
return ResponseMapper.single(account)
const { _count, consumer_account, ...rest } = saleInvoice
const { consumer, ...restConsumerAccount } = consumer_account as any
const mappedConsumer = consumer_mappersUtil(consumer)
return ResponseMapper.single({
...rest,
items_count: _count.items,
consumer_account: {
...restConsumerAccount,
consumer: mappedConsumer,
},
})
}
}
@@ -0,0 +1,3 @@
import type { ConsumerService } from '../consumer.service'
export type ConsumerServiceGetInfoResponseDto = Awaited<ReturnType<ConsumerService['getInfo']>>
@@ -0,0 +1,5 @@
import type { PosesService } from '../poses.service'
export type PosesServiceFindAllResponseDto = Awaited<ReturnType<PosesService['findAll']>>
export type PosesServiceFindOneResponseDto = Awaited<ReturnType<PosesService['findOne']>>
export type PosesServiceUpdateResponseDto = Awaited<ReturnType<PosesService['update']>>
@@ -2,18 +2,19 @@ import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
import { Body, Controller, Get, Param, Patch } from '@nestjs/common'
import { UpdateBusinessActivityDto } from './dto/poses.dto'
import { PosesService } from './poses.service'
import type { PosesServiceFindAllResponseDto, PosesServiceFindOneResponseDto, PosesServiceUpdateResponseDto } from './dto/poses-response.dto'
@Controller('consumer/poses')
export class PosesController {
constructor(private readonly service: PosesService) {}
@Get()
async findAll(@TokenAccount('userId') userId: string) {
async findAll(@TokenAccount('userId') userId: string): Promise<PosesServiceFindAllResponseDto> {
return this.service.findAll(userId)
}
@Get(':id')
async findOne(@TokenAccount('userId') userId: string, @Param('id') id: string) {
async findOne(@TokenAccount('userId') userId: string, @Param('id') id: string): Promise<PosesServiceFindOneResponseDto> {
return this.service.findOne(userId, id)
}
@@ -22,7 +23,7 @@ export class PosesController {
@TokenAccount('userId') userId: string,
@Param('id') id: string,
@Body() data: UpdateBusinessActivityDto,
) {
): Promise<PosesServiceUpdateResponseDto> {
return this.service.update(userId, id, data)
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ import { ResponseMapper } from 'common/response/response-mapper'
export class PosesService {
constructor(private readonly prisma: PrismaService) {}
private readonly defaultSelect = QUERY_CONSTANTS.pos.select
private readonly defaultSelect = QUERY_CONSTANTS.POS.select
private readonly defaultWhere = (consumer_id: string) => ({
complex: {
business_activity: {
@@ -0,0 +1,4 @@
import type { SaleInvoicesService } from '../saleInvoices.service'
export type SaleInvoicesServiceFindAllResponseDto = Awaited<ReturnType<SaleInvoicesService['findAll']>>
export type SaleInvoicesServiceFindOneResponseDto = Awaited<ReturnType<SaleInvoicesService['findOne']>>
@@ -2,6 +2,7 @@ import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
import { Controller, Get, Param } from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { SaleInvoicesService } from './saleInvoices.service'
import type { SaleInvoicesServiceFindAllResponseDto, SaleInvoicesServiceFindOneResponseDto } from './dto/saleInvoices-response.dto'
@ApiTags('ConsumerSaleInvoices')
@Controller('consumer/sale-invoices')
@@ -9,12 +10,12 @@ export class StatisticsController {
constructor(private readonly service: SaleInvoicesService) {}
@Get('')
async findAll(@TokenAccount('userId') consumerId: string) {
async findAll(@TokenAccount('userId') consumerId: string): Promise<SaleInvoicesServiceFindAllResponseDto> {
return this.service.findAll(consumerId)
}
@Get(':id')
async findOne(@TokenAccount('userId') consumerId: string, @Param('id') id: string) {
async findOne(@TokenAccount('userId') consumerId: string, @Param('id') id: string): Promise<SaleInvoicesServiceFindOneResponseDto> {
return this.service.findOne(consumerId, id)
}
}

Some files were not shown because too many files have changed in this diff Show More