update pos consumer module

This commit is contained in:
2026-03-29 18:06:41 +03:30
parent 63fa2bc67e
commit c870a43e35
53 changed files with 2145 additions and 671 deletions
+11 -11
View File
@@ -1,6 +1,6 @@
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
import { reqTokenPayload } from '../../auth/current-user.decorator'
import { CreateGoodDto } from './dto/create-good.dto'
import { PosInfo } from '@/common/decorators/posInfo.decorator'
import type { IPosPayload } from '@/common/models/posPayload.model'
import { Controller, Get, Param } from '@nestjs/common'
import { GoodsService } from './goods.service'
@Controller('pos/goods')
@@ -8,17 +8,17 @@ export class GoodsController {
constructor(private readonly goodsService: GoodsService) {}
@Get()
findAll(@reqTokenPayload() account) {
return this.goodsService.findAll(account.complex_id)
findAll(@PosInfo() { complex_id, guild_id }: IPosPayload) {
return this.goodsService.findAll(complex_id, guild_id)
}
@Get(':id')
findOne(@Param('id') goodId: string, @reqTokenPayload() account) {
return this.goodsService.findOne(goodId, account.complex_id)
findOne(@PosInfo() { complex_id, guild_id }: IPosPayload, @Param('id') goodId: string) {
return this.goodsService.findOne(goodId, complex_id, guild_id)
}
@Post()
create(@Body() data: CreateGoodDto, @reqTokenPayload() account) {
return this.goodsService.create(data, account.complex_id)
}
// @Post()
// create(@Body() data: CreateGoodDto, @PosInfo() { complex_id, guild_id }: IPosPayload) {
// return this.goodsService.create(data, complex_id, guild_id)
// }
}
+43 -17
View File
@@ -1,3 +1,4 @@
import { GoodSelect } from '@/generated/prisma/models'
import { Injectable } from '@nestjs/common'
import { ResponseMapper } from '../../../common/response/response-mapper'
import { PrismaService } from '../../../prisma/prisma.service'
@@ -7,31 +8,59 @@ import { CreateGoodDto } from './dto/create-good.dto'
export class GoodsService {
constructor(private prisma: PrismaService) {}
async findAll(complex_id: string) {
private readonly defaultSelect: GoodSelect = {
id: true,
name: true,
barcode: true,
created_at: true,
description: true,
sku: true,
local_sku: true,
is_default_guild_good: true,
pricing_model: true,
unit_type: true,
category: {
select: {
id: true,
name: true,
image_url: true,
},
},
}
async findAll(complex_id: string, guild_id: string) {
const goods = await this.prisma.good.findMany({
where: {
complex_id,
},
omit: {
complex_id: true,
deleted_at: true,
OR: [
{
is_default_guild_good: true,
category: {
guild_id,
},
},
{
complex_id,
},
],
},
select: this.defaultSelect,
})
return ResponseMapper.list(goods)
}
async findOne(good_id: string, complex_id: string) {
async findOne(good_id: string, complex_id: string, guild_id: string) {
const good = await this.prisma.good.findUnique({
where: {
complex_id,
id: good_id,
complex: {
id: complex_id,
business_activity: {
guild_id,
},
},
},
omit: {
complex_id: true,
deleted_at: true,
},
select: this.defaultSelect,
})
return ResponseMapper.single(good)
@@ -64,10 +93,7 @@ export class GoodsService {
},
},
},
omit: {
complex_id: true,
deleted_at: true,
},
select: this.defaultSelect,
})
return ResponseMapper.create(good)