feat(pos): update POS controller and service to handle posId for stock and product categories
This commit is contained in:
@@ -16,19 +16,60 @@ export class PosService {
|
||||
return inventory?.id || null
|
||||
}
|
||||
|
||||
async getInfo() {
|
||||
const info = await this.prisma.inventory.findFirst({
|
||||
where: { isPointOfSale: true },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
async getDefaultPosId(inventoryId: number) {
|
||||
const pos = await this.prisma.posAccount.findFirst({
|
||||
where: { inventoryId },
|
||||
select: { id: true },
|
||||
})
|
||||
return pos?.id || null
|
||||
}
|
||||
|
||||
async getInfo(posId: number) {
|
||||
const info = await this.prisma.posAccount.findUniqueOrThrow({
|
||||
where: { id: posId },
|
||||
include: {
|
||||
inventory: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
bankAccount: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
accountNumber: true,
|
||||
branch: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
bank: { select: { id: true, name: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return ResponseMapper.single({ store: info })
|
||||
return ResponseMapper.single({ ...info })
|
||||
}
|
||||
|
||||
async getStock(inventoryId: number, isAvailable?: boolean, page = 1, pageSize = 50) {
|
||||
async getStock(
|
||||
posId: number,
|
||||
options: {
|
||||
isAvailable?: boolean
|
||||
page?: number
|
||||
pageSize?: number
|
||||
q?: string
|
||||
} = {},
|
||||
) {
|
||||
const { isAvailable, page = 1, pageSize = 50, q } = options
|
||||
const pos = await this.prisma.posAccount.findUniqueOrThrow({
|
||||
where: { id: posId },
|
||||
select: { inventoryId: true },
|
||||
})
|
||||
const inventoryId = pos.inventoryId
|
||||
|
||||
const query: Prisma.StockBalanceFindManyArgs = {
|
||||
where: {
|
||||
inventoryId,
|
||||
@@ -38,8 +79,17 @@ export class PosService {
|
||||
: isAvailable === false
|
||||
? { lte: 0 }
|
||||
: undefined,
|
||||
...(q && {
|
||||
product: {
|
||||
OR: [{ name: { contains: q } }, { sku: { contains: q } }],
|
||||
},
|
||||
}),
|
||||
},
|
||||
orderBy: {
|
||||
quantity: 'desc',
|
||||
},
|
||||
}
|
||||
|
||||
const [items, count] = await this.prisma.$transaction([
|
||||
this.prisma.stockBalance.findMany({
|
||||
where: query.where,
|
||||
@@ -74,7 +124,13 @@ export class PosService {
|
||||
return ResponseMapper.paginate(mapped, count, page, pageSize)
|
||||
}
|
||||
|
||||
async getProductCategories(inventoryId: number) {
|
||||
async getProductCategories(posId: number) {
|
||||
const pos = await this.prisma.posAccount.findUniqueOrThrow({
|
||||
where: { id: posId },
|
||||
select: { inventoryId: true },
|
||||
})
|
||||
const inventoryId = pos.inventoryId
|
||||
|
||||
const balances = await this.prisma.stockBalance.findMany({
|
||||
where: { inventoryId },
|
||||
select: {
|
||||
|
||||
Reference in New Issue
Block a user