Skip to content

Commit

Permalink
[fix] single quote
Browse files Browse the repository at this point in the history
  • Loading branch information
Soecka committed Jan 4, 2025
1 parent 36e0682 commit 9645160
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 125 deletions.
71 changes: 36 additions & 35 deletions src/controller/CheckEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
JsonController,
Param,
Post,
QueryParams,
} from "routing-controllers";
import { ResponseSchema } from "routing-controllers-openapi";
QueryParams
} from 'routing-controllers';
import { ResponseSchema } from 'routing-controllers-openapi';

import {
ActivityAgendaCheckInListChunk,
Expand All @@ -25,20 +25,20 @@ import {
dataSource,
User,
UserActivityCheckInListChunk,
UserActivityCheckInSummary,
} from "../model";
import { ActivityLogController } from "./ActivityLog";
import { FindOptionsWhere } from "typeorm";
UserActivityCheckInSummary
} from '../model';
import { ActivityLogController } from './ActivityLog';
import { FindOptionsWhere } from 'typeorm';

@JsonController("/event/check")
@JsonController('/event/check')
export class CheckEventController {
store = dataSource.getRepository(CheckEvent);
userStore = dataSource.getRepository(User);
userActivityCheckInStore = dataSource.getRepository(
UserActivityCheckInSummary,
UserActivityCheckInSummary
);
activityAgendaCheckInStore = dataSource.getRepository(
ActivityAgendaCheckInSummary,
ActivityAgendaCheckInSummary
);
activityCheckInStore = dataSource.getRepository(ActivityCheckInSummary);

Expand All @@ -47,64 +47,65 @@ export class CheckEventController {
@ResponseSchema(CheckEvent)
async createOne(
@CurrentUser() createdBy: User,
@Body() { user: id, ...data }: CheckEventInput,
@Body() { user: id, ...data }: CheckEventInput
) {
// if (createdBy.id === id) throw new ForbiddenError("No self-checking");

const user = await this.userStore.findOne({ where: { id } });

if (!user) throw new BadRequestError("Invalid user: " + id);
if (!user) throw new BadRequestError('Invalid user: ' + id);

const checked = await this.store.findOne({
where: { ...data, user: { id } },
where: { ...data, user: { id } }
});

if (checked) throw new ForbiddenError("No duplicated check");
if (checked) throw new ForbiddenError('No duplicated check');

const saved = await this.store.save({ ...data, createdBy, user });

await ActivityLogController.logCreate(
createdBy,
"CheckEvent",
saved.id,
'CheckEvent',
saved.id
);
return saved;
}

@Get()
@ResponseSchema(CheckEventChunk)
async getSessionList(
@QueryParams() {
@QueryParams()
{
user: id,
activityId,
agendaId,
pageSize = 10,
pageIndex = 1,
}: CheckEventFilter,
pageIndex = 1
}: CheckEventFilter
) {
const [list, count] = await this.store.findAndCount({
where: {
...(id ? { user: { id } } : {}),
activityId,
agendaId,
agendaId
},
relations: ["user"],
relations: ['user'],
skip: pageSize * (pageIndex - 1),
take: pageSize,
take: pageSize
});
return { list, count };
}

@Get("/user/:id")
@Get('/user/:id')
@ResponseSchema(UserActivityCheckInListChunk)
async getCheckEventList(
@Param("id") id: number,
@QueryParams() { pageSize = 10, pageIndex = 1 }: BaseFilter,
@Param('id') id: number,
@QueryParams() { pageSize = 10, pageIndex = 1 }: BaseFilter
) {
const [list, count] = await this.userActivityCheckInStore.findAndCount({
where: { userId: id },
skip: pageSize * (pageIndex - 1),
take: pageSize,
take: pageSize
});

for (
Expand All @@ -117,29 +118,29 @@ export class CheckEventController {
return { list, count };
}

@Get("/activity/:id")
@Get('/activity/:id')
@ResponseSchema(ActivityAgendaCheckInListChunk)
async getActivityCheckEventList(
@Param("id") id: string,
@QueryParams() { pageSize = 10, pageIndex = 1 }: BaseFilter,
@Param('id') id: string,
@QueryParams() { pageSize = 10, pageIndex = 1 }: BaseFilter
) {
const [list, count] = await this.activityAgendaCheckInStore
.findAndCount({
const [list, count] =
await this.activityAgendaCheckInStore.findAndCount({
where: { activityId: id },
skip: pageSize * (pageIndex - 1),
take: pageSize,
take: pageSize
});
return { list, count };
}

@Get("/activity")
@Get('/activity')
@ResponseSchema(ActivityCheckInListChunk)
async getAgendaCheckEventList(
@QueryParams() { pageSize = 10, pageIndex = 1 }: BaseFilter,
@QueryParams() { pageSize = 10, pageIndex = 1 }: BaseFilter
) {
const [list, count] = await this.activityCheckInStore.findAndCount({
skip: pageSize * (pageIndex - 1),
take: pageSize,
take: pageSize
});
return { list, count };
}
Expand Down
42 changes: 22 additions & 20 deletions src/model/ActivityLog.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { Type } from "class-transformer";
import { Type } from 'class-transformer';
import {
IsEnum,
IsInt,
IsObject,
IsOptional,
Min,
ValidateNested,
} from "class-validator";
import { Column, Entity, ViewColumn, ViewEntity } from "typeorm";
ValidateNested
} from 'class-validator';
import { Column, Entity, ViewColumn, ViewEntity } from 'typeorm';

import { Base, BaseFilter, InputData, ListChunk } from "./Base";
import { CheckEvent } from "./CheckEvent";
import { User, UserBase } from "./User";
import { Base, BaseFilter, InputData, ListChunk } from './Base';
import { CheckEvent } from './CheckEvent';
import { User, UserBase } from './User';

export enum Operation {
Create = "create",
Update = "update",
Delete = "delete",
Create = 'create',
Update = 'update',
Delete = 'delete'
}

export const LogableTable = { User, CheckEvent };

const LogableTableEnum = Object.fromEntries(
Object.entries(LogableTable).map(([key]) => [key, key]),
Object.entries(LogableTable).map(([key]) => [key, key])
);

@Entity()
export class ActivityLog extends UserBase {
@IsEnum(Operation)
@Column({ type: "simple-enum", enum: Operation })
@Column({ type: 'simple-enum', enum: Operation })
operation: Operation;

@IsEnum(LogableTableEnum)
@Column({ type: "simple-enum", enum: LogableTableEnum })
@Column({ type: 'simple-enum', enum: LogableTableEnum })
tableName: keyof typeof LogableTable;

@IsInt()
Expand All @@ -45,8 +45,10 @@ export class ActivityLog extends UserBase {
record?: Base;
}

export class ActivityLogFilter extends BaseFilter
implements Partial<InputData<ActivityLog>> {
export class ActivityLogFilter
extends BaseFilter
implements Partial<InputData<ActivityLog>>
{
@IsEnum(Operation)
@IsOptional()
operation?: Operation;
Expand All @@ -63,13 +65,13 @@ export class ActivityLogListChunk implements ListChunk<ActivityLog> {
}

@ViewEntity({
expression: (connection) =>
expression: connection =>
connection
.createQueryBuilder()
.from(ActivityLog, "al")
.groupBy("al.createdBy")
.select("al.createdBy.id", "userId")
.addSelect("COUNT(al.id)", "score"),
.from(ActivityLog, 'al')
.groupBy('al.createdBy')
.select('al.createdBy.id', 'userId')
.addSelect('COUNT(al.id)', 'score')
})
export class UserRank {
@IsInt()
Expand Down
16 changes: 8 additions & 8 deletions src/model/Base.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Type } from "class-transformer";
import { Type } from 'class-transformer';
import {
IsDateString,
IsEnum,
IsInt,
IsOptional,
IsString,
Min,
} from "class-validator";
import { NewData } from "mobx-restful";
Min
} from 'class-validator';
import { NewData } from 'mobx-restful';
import {
CreateDateColumn,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
UpdateDateColumn
} from 'typeorm';

export enum Sort {
DESC = "DESC",
ASC = "ASC",
DESC = 'DESC',
ASC = 'ASC'
}

export abstract class Base {
Expand Down
Loading

0 comments on commit 9645160

Please sign in to comment.