2026-03-16 17:56:51 +03:30
|
|
|
import { POSStatus } from '@/generated/prisma/enums'
|
|
|
|
|
import { PosCreateInput, PosSelect } from '@/generated/prisma/models'
|
|
|
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
|
|
|
|
import { Injectable } from '@nestjs/common'
|
|
|
|
|
import { ResponseMapper } from 'common/response/response-mapper'
|
|
|
|
|
import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ComplexPosesService {
|
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
|
|
|
|
|
|
defaultSelect = {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
model: true,
|
|
|
|
|
serial: true,
|
|
|
|
|
status: true,
|
|
|
|
|
created_at: true,
|
|
|
|
|
pos_type: true,
|
|
|
|
|
|
|
|
|
|
provider: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
device: {
|
|
|
|
|
select: {
|
|
|
|
|
name: true,
|
|
|
|
|
id: true,
|
|
|
|
|
brand: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
complex: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
business_activity: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} as PosSelect
|
|
|
|
|
|
|
|
|
|
defaultInsert = (data: CreatePosDto, complex_id: string) => {
|
|
|
|
|
const { device_id, provider_id, ...rest } = data
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...rest,
|
|
|
|
|
complex: {
|
|
|
|
|
connect: {
|
|
|
|
|
id: complex_id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
provider: provider_id
|
|
|
|
|
? {
|
|
|
|
|
connect: {
|
|
|
|
|
id: provider_id,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
device: device_id
|
|
|
|
|
? {
|
|
|
|
|
connect: {
|
|
|
|
|
id: device_id,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
} as PosCreateInput
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-11 14:47:05 +03:30
|
|
|
async findAll(consumer_id: string, business_activity_id: string, complex_id: string) {
|
2026-03-16 17:56:51 +03:30
|
|
|
const poses = await this.prisma.pos.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
complex: {
|
|
|
|
|
id: complex_id,
|
|
|
|
|
business_activity: {
|
|
|
|
|
id: business_activity_id,
|
2026-04-11 14:47:05 +03:30
|
|
|
consumer_id,
|
2026-03-16 17:56:51 +03:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
select: this.defaultSelect,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ResponseMapper.list(poses)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async findOne(business_activity_id: string, complex_id: string, id: string) {
|
|
|
|
|
const account = await this.prisma.pos.findUnique({
|
|
|
|
|
where: {
|
|
|
|
|
complex: {
|
|
|
|
|
id: complex_id,
|
|
|
|
|
business_activity: {
|
|
|
|
|
id: business_activity_id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
id,
|
|
|
|
|
},
|
|
|
|
|
select: this.defaultSelect,
|
|
|
|
|
})
|
|
|
|
|
return ResponseMapper.single(account)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async create(complex_id: string, data: CreatePosDto) {
|
|
|
|
|
const account = await this.prisma.pos.create({
|
|
|
|
|
data: {
|
|
|
|
|
...this.defaultInsert(data, complex_id),
|
|
|
|
|
status: POSStatus.ACTIVE,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
return ResponseMapper.create(account)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async update(
|
|
|
|
|
business_activity_id: string,
|
|
|
|
|
complex_id: string,
|
|
|
|
|
id: string,
|
|
|
|
|
data: UpdatePosDto,
|
|
|
|
|
) {
|
|
|
|
|
const { device_id, provider_id, ...rest } = data
|
|
|
|
|
const account = await this.prisma.pos.update({
|
|
|
|
|
where: {
|
|
|
|
|
complex: {
|
|
|
|
|
id: complex_id,
|
|
|
|
|
business_activity: {
|
|
|
|
|
id: business_activity_id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
id,
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
complex: {
|
|
|
|
|
connect: {
|
|
|
|
|
id: complex_id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
provider: provider_id
|
|
|
|
|
? {
|
|
|
|
|
connect: {
|
|
|
|
|
id: provider_id,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
device: device_id
|
|
|
|
|
? {
|
|
|
|
|
connect: {
|
|
|
|
|
id: device_id,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
...rest,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
return ResponseMapper.update(account)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// async delete(id: string) {
|
|
|
|
|
// await this.prisma.complex.delete({ where: { id } })
|
|
|
|
|
// return ResponseMapper.delete()
|
|
|
|
|
// }
|
|
|
|
|
}
|