Skip to content

Commit

Permalink
feat(server): add special price in bundle, use id instead of name (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Mar 7, 2023
1 parent 72ba470 commit 7e81c0b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
30 changes: 16 additions & 14 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,29 @@ type BundleResource {
}

model Bundle {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
displayName String
regionId String @db.ObjectId
resource BundleResource
priority Int @default(0)
state String @default("Active") // Active, Inactive
price Int @default(0)
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
displayName String
regionId String @db.ObjectId
resource BundleResource
priority Int @default(0)
state String @default("Active") // Active, Inactive
price Int @default(0)
specialPrice Int @default(0)
region Region @relation(fields: [regionId], references: [id])
@@unique([regionId, name])
}

model ApplicationBundle {
id String @id @default(auto()) @map("_id") @db.ObjectId
appid String @unique
name String
displayName String
resource BundleResource
price Int @default(0)
id String @id @default(auto()) @map("_id") @db.ObjectId
appid String @unique
name String
displayName String
resource BundleResource
price Int @default(0)
specialPrice Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
9 changes: 3 additions & 6 deletions server/src/application/application.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,19 @@ export class ApplicationController {
}

// check app count limit
const bundle = await this.bundleService.findOneByName(
dto.bundleName,
dto.region,
)
const bundle = await this.bundleService.findOne(dto.bundleId)
const LIMIT_COUNT = bundle?.resource?.limitCountPerUser || 0
const count = await this.prisma.application.count({
where: {
createdBy: user.id,
bundle: {
name: dto.bundleName,
id: dto.bundleId,
},
},
})
if (count >= LIMIT_COUNT) {
return ResponseUtil.error(
`application count limit is ${LIMIT_COUNT} for bundle ${dto.bundleName}`,
`application count limit is ${LIMIT_COUNT} for bundle ${bundle.name}`,
)
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/application/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ApplicationService {
// get bundle
const bundle = await this.prisma.bundle.findFirstOrThrow({
where: {
name: dto.bundleName,
id: dto.bundleId,
region: {
name: dto.region,
},
Expand Down
5 changes: 3 additions & 2 deletions server/src/application/dto/create-application.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { ApplicationState } from '@prisma/client'
import { IsEnum, IsNotEmpty, Length } from 'class-validator'
import { IsEnum, IsNotEmpty, IsString, Length } from 'class-validator'

enum CreateApplicationState {
Running = 'Running',
Expand All @@ -27,7 +27,8 @@ export class CreateApplicationDto {

@ApiProperty()
@IsNotEmpty()
bundleName: string
@IsString()
bundleId: string

@ApiProperty()
@IsNotEmpty()
Expand Down

0 comments on commit 7e81c0b

Please sign in to comment.