consumer pos

This commit is contained in:
2026-04-14 15:56:49 +03:30
parent 59da9585c4
commit d098ef10e1
21 changed files with 1651 additions and 75 deletions
@@ -0,0 +1,10 @@
import { ApiProperty, PartialType } from '@nestjs/swagger'
import { IsString } from 'class-validator'
export class CreateBusinessActivityDto {
@IsString()
@ApiProperty({ required: true })
name: string
}
export class UpdateBusinessActivityDto extends PartialType(CreateBusinessActivityDto) {}
@@ -0,0 +1,28 @@
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'
@Controller('consumer/poses')
export class PosesController {
constructor(private readonly service: PosesService) {}
@Get()
async findAll(@TokenAccount('userId') userId: string) {
return this.service.findAll(userId)
}
@Get(':id')
async findOne(@TokenAccount('userId') userId: string, @Param('id') id: string) {
return this.service.findOne(userId, id)
}
@Patch(':id')
async update(
@TokenAccount('userId') userId: string,
@Param('id') id: string,
@Body() data: UpdateBusinessActivityDto,
) {
return this.service.update(userId, id, data)
}
}
@@ -0,0 +1,11 @@
import { PrismaModule } from '@/prisma/prisma.module'
import { Module } from '@nestjs/common'
import { PosesController } from './poses.controller'
import { PosesService } from './poses.service'
@Module({
imports: [PrismaModule],
controllers: [PosesController],
providers: [PosesService],
})
export class ConsumerPosesModule {}
@@ -0,0 +1,43 @@
import { QUERY_CONSTANTS } from '@/common/queryConstants'
import { PrismaService } from '@/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
import { ResponseMapper } from 'common/response/response-mapper'
@Injectable()
export class PosesService {
constructor(private readonly prisma: PrismaService) {}
private readonly defaultSelect = QUERY_CONSTANTS.pos.select
private readonly defaultWhere = (consumer_id: string) => ({
complex: {
business_activity: {
consumer_id,
},
},
})
async findAll(consumer_id: string) {
const poses = await this.prisma.pos.findMany({
where: this.defaultWhere(consumer_id),
select: this.defaultSelect,
})
return ResponseMapper.list(poses)
}
async findOne(consumer_id: string, id: string) {
const pos = await this.prisma.pos.findUniqueOrThrow({
where: { ...this.defaultWhere(consumer_id), id },
select: this.defaultSelect,
})
return ResponseMapper.single(pos)
}
async update(consumer_id: string, id: string, data: any) {
const pos = await this.prisma.pos.update({
where: { ...this.defaultWhere(consumer_id), id },
data,
select: this.defaultSelect,
})
return ResponseMapper.update(pos)
}
}