update admin user business
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { AccountsService } from './accounts.service'
|
||||
import { CreateAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
@@ -19,17 +19,17 @@ export class AccountsController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() data: CreateAccountDto) {
|
||||
return this.accountsService.create(data)
|
||||
async create(@Param('userId') userId: string, @Body() data: CreateAccountDto) {
|
||||
return this.accountsService.create(userId, data)
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
|
||||
return this.accountsService.update(id, data)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param('id') id: string) {
|
||||
return this.accountsService.delete(id)
|
||||
}
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.accountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import { AccountStatus } from '@/generated/prisma/enums'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -29,9 +31,20 @@ export class AccountsService {
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(data: CreateAccountDto) {
|
||||
async create(userId: string, data: CreateAccountDto) {
|
||||
// Assuming password hashing is handled elsewhere or add bcrypt here
|
||||
const account = await this.prisma.account.create({ data })
|
||||
const account = await this.prisma.account.create({
|
||||
data: {
|
||||
...data,
|
||||
password: await PasswordUtil.hash(data.password),
|
||||
status: AccountStatus.ACTIVE,
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,8 @@ export class CreateAccountDto {
|
||||
@IsEnum(AccountType)
|
||||
type: AccountType
|
||||
|
||||
@IsEnum(AccountStatus)
|
||||
status: AccountStatus
|
||||
|
||||
@IsString()
|
||||
password: string
|
||||
|
||||
@IsString()
|
||||
user_id: string
|
||||
}
|
||||
|
||||
export class UpdateAccountDto {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { BusinessActivityAccountsService } from './accounts.service'
|
||||
import { CreateAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
|
||||
@ApiTags('AdminAccounts')
|
||||
@Controller('admin/users/:userId/business_activities/:businessActivityId/accounts')
|
||||
export class BusinessActivityAccountsController {
|
||||
constructor(
|
||||
private readonly businessActivityAccountsService: BusinessActivityAccountsService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@Param('userId') userId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
) {
|
||||
return this.businessActivityAccountsService.findAll(userId, businessActivityId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(
|
||||
@Param('id') id: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
) {
|
||||
return this.businessActivityAccountsService.findOne(id, businessActivityId)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('userId') userId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: CreateAccountDto,
|
||||
) {
|
||||
return this.businessActivityAccountsService.create(userId, businessActivityId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@Param('userId') userId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateAccountDto,
|
||||
) {
|
||||
return this.businessActivityAccountsService.update(
|
||||
userId,
|
||||
businessActivityId,
|
||||
id,
|
||||
data,
|
||||
)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.businessActivityAccountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { BusinessActivityAccountsController } from './accounts.controller'
|
||||
import { BusinessActivityAccountsService } from './accounts.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [BusinessActivityAccountsController],
|
||||
providers: [BusinessActivityAccountsService],
|
||||
exports: [BusinessActivityAccountsService],
|
||||
})
|
||||
export class AdminUserBusinessActivityAccountsModule {}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import { AccountStatus, AccountType } from '@/generated/prisma/enums'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
|
||||
@Injectable()
|
||||
export class BusinessActivityAccountsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll(userId: string, business_id: string) {
|
||||
const accounts = await this.prisma.account.findMany({
|
||||
where: { user_id: userId, business_id },
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
status: true,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.list(accounts)
|
||||
}
|
||||
|
||||
async findOne(business_id: string, id: string) {
|
||||
const account = await this.prisma.account.findUnique({
|
||||
where: { business_id, id },
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
status: true,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(userId: string, business_id: string, data: CreateAccountDto) {
|
||||
// Assuming password hashing is handled elsewhere or add bcrypt here
|
||||
const account = await this.prisma.account.create({
|
||||
data: {
|
||||
...data,
|
||||
password: await PasswordUtil.hash(data.password),
|
||||
status: AccountStatus.ACTIVE,
|
||||
type: AccountType.BUSINESS,
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
business: {
|
||||
connect: {
|
||||
id: business_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
|
||||
async update(user_id: string, business_id: string, id: string, data: UpdateAccountDto) {
|
||||
const account = await this.prisma.account.update({
|
||||
where: {
|
||||
user_id_business_id: {
|
||||
user_id,
|
||||
business_id,
|
||||
},
|
||||
id,
|
||||
},
|
||||
data,
|
||||
})
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
await this.prisma.account.delete({ where: { id } })
|
||||
return ResponseMapper.delete()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||
import { AccountStatus } from 'generated/prisma/enums'
|
||||
|
||||
export class CreateAccountDto {
|
||||
@IsString()
|
||||
username: string
|
||||
|
||||
@IsString()
|
||||
password: string
|
||||
}
|
||||
|
||||
export class UpdateAccountDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
username?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(AccountStatus)
|
||||
status?: AccountStatus
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
password?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
user_id?: string
|
||||
}
|
||||
@@ -2,9 +2,10 @@ import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { BusinessActivitiesController } from './business-activities.controller'
|
||||
import { BusinessActivitiesService } from './business-activities.service'
|
||||
import { AdminBusinessActivityComplexesModule } from './complexes/complexes.module'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
imports: [PrismaModule, AdminBusinessActivityComplexesModule],
|
||||
controllers: [BusinessActivitiesController],
|
||||
providers: [BusinessActivitiesService],
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { BusinessActivitySelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -7,11 +8,25 @@ import { CreateBusinessActivitiesDto } from './dto/create-business-activities.dt
|
||||
export class BusinessActivitiesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
defaultSelect = {
|
||||
guild: {
|
||||
select: {
|
||||
id: true,
|
||||
code: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
id: true,
|
||||
name: true,
|
||||
created_at: true,
|
||||
} as BusinessActivitySelect
|
||||
|
||||
async findAll(userId: string) {
|
||||
const businessActivities = await this.prisma.businessActivity.findMany({
|
||||
where: {
|
||||
owner_id: userId,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.list(businessActivities)
|
||||
}
|
||||
@@ -19,6 +34,7 @@ export class BusinessActivitiesService {
|
||||
async findOne(userId: string, id: string) {
|
||||
const businessActivity = await this.prisma.businessActivity.findUnique({
|
||||
where: { owner_id: userId, id },
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(businessActivity)
|
||||
}
|
||||
@@ -38,6 +54,7 @@ export class BusinessActivitiesService {
|
||||
},
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.create(businessActivity)
|
||||
}
|
||||
@@ -46,6 +63,7 @@ export class BusinessActivitiesService {
|
||||
const businessActivity = await this.prisma.businessActivity.update({
|
||||
where: { id },
|
||||
data,
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.update(businessActivity)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { BusinessActivityComplexesService } from './complexes.service'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
|
||||
@ApiTags('AdminBusinessActivityComplexes')
|
||||
@Controller('admin/users/:userId/business_activities/:businessActivityId/complexes')
|
||||
export class BusinessActivityComplexesController {
|
||||
constructor(private readonly service: BusinessActivityComplexesService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@Param('userId') userId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
) {
|
||||
return this.service.findAll(userId, businessActivityId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(
|
||||
@Param('userId') userId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.service.findOne(userId, businessActivityId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: CreateComplexDto,
|
||||
) {
|
||||
return this.service.create(businessActivityId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Param('userId') userId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: UpdateComplexDto,
|
||||
) {
|
||||
return this.service.update(userId, businessActivityId, id, data)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.businessActivityAccountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { BusinessActivityComplexesController } from './complexes.controller'
|
||||
import { BusinessActivityComplexesService } from './complexes.service'
|
||||
import { AdminComplexPosesModule } from './poses/poses.module'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, AdminComplexPosesModule],
|
||||
controllers: [BusinessActivityComplexesController],
|
||||
providers: [BusinessActivityComplexesService],
|
||||
exports: [BusinessActivityComplexesService],
|
||||
})
|
||||
export class AdminBusinessActivityComplexesModule {}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { ComplexSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
|
||||
@Injectable()
|
||||
export class BusinessActivityComplexesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
defaultSelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
address: true,
|
||||
tax_id: true,
|
||||
created_at: true,
|
||||
} as ComplexSelect
|
||||
|
||||
async findAll(user_id: string, business_activity_id: string) {
|
||||
const accounts = await this.prisma.complex.findMany({
|
||||
where: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
user: {
|
||||
id: user_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.list(accounts)
|
||||
}
|
||||
|
||||
async findOne(user_id: string, business_activity_id: string, id: string) {
|
||||
const account = await this.prisma.complex.findUnique({
|
||||
where: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
user: {
|
||||
id: user_id,
|
||||
},
|
||||
},
|
||||
id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(business_id: string, data: CreateComplexDto) {
|
||||
const account = await this.prisma.complex.create({
|
||||
data: {
|
||||
...data,
|
||||
business_activity: {
|
||||
connect: {
|
||||
id: business_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
|
||||
async update(
|
||||
user_id: string,
|
||||
business_activity_id: string,
|
||||
id: string,
|
||||
data: UpdateComplexDto,
|
||||
) {
|
||||
const account = await this.prisma.complex.update({
|
||||
where: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
user: {
|
||||
id: user_id,
|
||||
},
|
||||
},
|
||||
id,
|
||||
},
|
||||
data,
|
||||
})
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.complex.delete({ where: { id } })
|
||||
// return ResponseMapper.delete()
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsString } from 'class-validator'
|
||||
|
||||
export class CreateComplexDto {
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
tax_id: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
address: string
|
||||
}
|
||||
|
||||
export class UpdateComplexDto extends PartialType(CreateComplexDto) {}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { POSStatus, POSType } from '@/generated/prisma/enums'
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class CreatePosDto {
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
serial: string
|
||||
|
||||
// @IsString()
|
||||
// @IsOptional()
|
||||
// @ApiProperty({ required: false })
|
||||
// model: string
|
||||
|
||||
@IsEnum(POSType)
|
||||
@ApiProperty({ enum: POSType })
|
||||
pos_type: POSType
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({})
|
||||
device_id: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty()
|
||||
provider_id: string
|
||||
}
|
||||
|
||||
export class UpdatePosDto extends PartialType(CreatePosDto) {
|
||||
@IsEnum(POSStatus)
|
||||
@IsOptional()
|
||||
@ApiProperty({ enum: POSStatus })
|
||||
status: POSStatus
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
|
||||
import { ComplexPosesService } from './poses.service'
|
||||
|
||||
@ApiTags('AdminComplexPoses')
|
||||
@Controller('admin/business_activities/:businessActivityId/complexes/:complexId/poses')
|
||||
export class ComplexPosesController {
|
||||
constructor(private readonly service: ComplexPosesService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
) {
|
||||
return this.service.findAll(businessActivityId, complexId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.service.findOne(businessActivityId, complexId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Param('complexId') complexId: string, @Body() data: CreatePosDto) {
|
||||
return this.service.create(complexId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdatePosDto,
|
||||
) {
|
||||
return this.service.update(businessActivityId, complexId, id, data)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.businessActivityAccountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { ComplexPosesController } from './poses.controller'
|
||||
import { ComplexPosesService } from './poses.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [ComplexPosesController],
|
||||
providers: [ComplexPosesService],
|
||||
exports: [ComplexPosesService],
|
||||
})
|
||||
export class AdminComplexPosesModule {}
|
||||
@@ -0,0 +1,168 @@
|
||||
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
|
||||
}
|
||||
|
||||
async findAll(business_activity_id: string, complex_id: string) {
|
||||
const accounts = await this.prisma.pos.findMany({
|
||||
where: {
|
||||
complex: {
|
||||
id: complex_id,
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.list(accounts)
|
||||
}
|
||||
|
||||
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()
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user