Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): add special price in bundle, use id instead of name #865

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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