Skip to content

Commit

Permalink
[optimize] simplify View Entity definations of Check Event model
Browse files Browse the repository at this point in the history
Signed-off-by: South Drifter <shiy2008@gmail.com>
  • Loading branch information
TechQuery committed Jan 7, 2025
1 parent 1da5ba4 commit 821d47d
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions src/model/CheckEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,12 @@ export class CheckEventChunk implements ListChunk<CheckEvent> {
connection
.createQueryBuilder()
.from(CheckEvent, 'ce')
.groupBy('ce.user.id, ce.activityId')
.groupBy('ce.activityId')
.select('ce.activityId', 'activityId')
.addSelect('ce.user.id', 'userId')
.addSelect('ce.activityName', 'activityName')
.addSelect('COUNT(ce.id)', 'checkCount')
})
export class UserActivityCheckInSummary {
@ViewColumn()
@IsInt()
@Min(1)
userId: number;

export class ActivityCheckInSummary {
@ViewColumn()
@IsString()
activityId: string;
Expand All @@ -121,35 +115,28 @@ export class UserActivityCheckInSummary {
@IsInt()
@Min(0)
checkCount: number;

@Type(() => User)
@ValidateNested()
user: User;
}

@ViewEntity({
expression: connection =>
connection
.createQueryBuilder()
.from(CheckEvent, 'ce')
.groupBy('ce.activityId')
.groupBy('ce.user.id, ce.activityId')
.select('ce.activityId', 'activityId')
.addSelect('ce.user.id', 'userId')
.addSelect('ce.activityName', 'activityName')
.addSelect('COUNT(ce.id)', 'checkCount')
})
export class ActivityCheckInSummary {
@ViewColumn()
@IsString()
activityId: string;

@ViewColumn()
@IsString()
activityName: string;

export class UserActivityCheckInSummary extends ActivityCheckInSummary {
@ViewColumn()
@IsInt()
@Min(0)
checkCount: number;
@Min(1)
userId: number;

@Type(() => User)
@ValidateNested()
user: User;
}

@ViewEntity({
Expand Down

0 comments on commit 821d47d

Please sign in to comment.