consumer pos
This commit is contained in:
@@ -6,6 +6,7 @@ import { ConsumerController } from './consumer.controller'
|
||||
import { ConsumerMiddleware } from './consumer.middleware'
|
||||
import { ConsumerService } from './consumer.service'
|
||||
import { ConsumerCustomersModule } from './customers/customers.module'
|
||||
import { ConsumerPosesModule } from './poses/poses.module'
|
||||
import { ConsumerStatisticsModule } from './statistics/statistics.module'
|
||||
|
||||
@Module({
|
||||
@@ -15,6 +16,7 @@ import { ConsumerStatisticsModule } from './statistics/statistics.module'
|
||||
ConsumerBusinessActivitiesModule,
|
||||
ConsumerCustomersModule,
|
||||
ConsumerStatisticsModule,
|
||||
ConsumerPosesModule,
|
||||
],
|
||||
providers: [JwtService, ConsumerService],
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user