Skip to content

Commit 6e1f3c5

Browse files
baboon-kingfengstats
authored andcommitted
chore: format all code
1 parent 6fed6af commit 6e1f3c5

File tree

204 files changed

+2411
-2677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+2411
-2677
lines changed

apps/api/ecosystem.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module.exports = {
22
apps: [
33
{
4-
name: 'earthworm_api',
5-
script: 'pnpm',
6-
args: 'start:prod',
7-
cwd: '.',
4+
name: "earthworm_api",
5+
script: "pnpm",
6+
args: "start:prod",
7+
cwd: ".",
88
instances: 1,
99
autorestart: true,
1010
watch: false,
11-
max_memory_restart: '1G',
11+
max_memory_restart: "1G",
1212
env: {
13-
NODE_ENV: 'production',
13+
NODE_ENV: "production",
1414
},
1515
},
1616
],

apps/api/jest.config.e2e.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { Config } from 'jest';
2-
import baseConfig from './jest.config';
1+
import type { Config } from "jest";
2+
3+
import baseConfig from "./jest.config";
34

45
const config: Config = {
56
...baseConfig,
6-
testRegex: '.*\\.e2e-spec\\.ts$',
7+
testRegex: ".*\\.e2e-spec\\.ts$",
78
};
89

910
export default config;

apps/api/jest.config.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import type { Config } from 'jest';
1+
import type { Config } from "jest";
22

33
const config: Config = {
44
verbose: true,
5-
moduleFileExtensions: ['js', 'json', 'ts'],
6-
rootDir: 'src',
7-
testRegex: '.*\\.spec\\.ts$',
5+
moduleFileExtensions: ["js", "json", "ts"],
6+
rootDir: "src",
7+
testRegex: ".*\\.spec\\.ts$",
88
transform: {
9-
'^.+\\.(t|j)s$': 'ts-jest',
9+
"^.+\\.(t|j)s$": "ts-jest",
1010
},
11-
collectCoverageFrom: ['**/*.(t|j)s'],
12-
coverageDirectory: '../coverage',
13-
testEnvironment: 'node',
11+
collectCoverageFrom: ["**/*.(t|j)s"],
12+
coverageDirectory: "../coverage",
13+
testEnvironment: "node",
1414
detectOpenHandles: true,
1515
forceExit: true,
1616
};

apps/api/src/app/app.module.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { RedisModule } from '@nestjs-modules/ioredis';
2-
import { Module } from '@nestjs/common';
3-
import { ScheduleModule } from '@nestjs/schedule';
4-
import { CourseHistoryModule } from '../course-history/course-history.module';
5-
import { CourseModule } from '../course/course.module';
6-
import { CronJobModule } from '../cron-job/cron-job.module';
7-
import { GameModule } from '../game/game.module';
8-
import { GlobalModule } from '../global/global.module';
9-
import { RankModule } from '../rank/rank.module';
10-
import { ToolModule } from '../tool/tool.module';
11-
import { UserLearnRecordModule } from '../user-learn-record/user-learn-record.module';
12-
import { UserProgressModule } from '../user-progress/user-progress.module';
13-
import { UserModule } from '../user/user.module';
1+
import { RedisModule } from "@nestjs-modules/ioredis";
2+
import { Module } from "@nestjs/common";
3+
import { ScheduleModule } from "@nestjs/schedule";
4+
5+
import { CourseHistoryModule } from "../course-history/course-history.module";
6+
import { CourseModule } from "../course/course.module";
7+
import { CronJobModule } from "../cron-job/cron-job.module";
8+
import { GameModule } from "../game/game.module";
9+
import { GlobalModule } from "../global/global.module";
10+
import { RankModule } from "../rank/rank.module";
11+
import { ToolModule } from "../tool/tool.module";
12+
import { UserLearnRecordModule } from "../user-learn-record/user-learn-record.module";
13+
import { UserProgressModule } from "../user-progress/user-progress.module";
14+
import { UserModule } from "../user/user.module";
1415

1516
@Module({
1617
imports: [
@@ -26,7 +27,7 @@ import { UserModule } from '../user/user.module';
2627
CourseHistoryModule,
2728
RedisModule.forRootAsync({
2829
useFactory: () => ({
29-
type: 'single',
30+
type: "single",
3031
url: process.env.REDIS_URL,
3132
options: {
3233
password: process.env.REDIS_PASSWORD,

apps/api/src/app/exception.filter.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
ArgumentsHost,
3-
Catch,
4-
ExceptionFilter,
5-
HttpException,
6-
} from '@nestjs/common';
1+
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from "@nestjs/common";
72

83
@Catch(HttpException)
94
export class HttpExceptionFilter implements ExceptionFilter {
@@ -12,17 +7,15 @@ export class HttpExceptionFilter implements ExceptionFilter {
127
const response = ctx.getResponse();
138
const status = exception.getStatus();
149

15-
const message =
16-
exception.message ??
17-
`${status >= 500 ? 'Service Error' : 'Client Error'}`;
10+
const message = exception.message ?? `${status >= 500 ? "Service Error" : "Client Error"}`;
1811

1912
const errorResponse = {
2013
data: {},
2114
message,
2215
};
2316

2417
response.status(status);
25-
response.header('Content-Type', 'application/json; charset=utf-8');
18+
response.header("Content-Type", "application/json; charset=utf-8");
2619
response.send(errorResponse);
2720
}
2821
}

apps/api/src/app/useGlobal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { INestApplication, ValidationPipe } from '@nestjs/common';
2-
import { HttpExceptionFilter } from './exception.filter';
1+
import { INestApplication, ValidationPipe } from "@nestjs/common";
2+
3+
import { HttpExceptionFilter } from "./exception.filter";
34

45
export const appGlobalMiddleware = (app: INestApplication) => {
56
app.useGlobalPipes(new ValidationPipe());

apps/api/src/auth/auth.guard.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,32 @@ import {
44
Injectable,
55
SetMetadata,
66
UnauthorizedException,
7-
} from '@nestjs/common';
8-
import { Request } from 'express';
9-
import { createRemoteJWKSet, jwtVerify } from 'jose';
7+
} from "@nestjs/common";
8+
import { Request } from "express";
9+
import { createRemoteJWKSet, jwtVerify } from "jose";
1010

11-
export const UncheckAuth = () => SetMetadata('uncheck', true);
11+
export const UncheckAuth = () => SetMetadata("uncheck", true);
1212

1313
@Injectable()
1414
export class AuthGuard implements CanActivate {
1515
private jwks: any;
1616
constructor() {
17-
this.jwks = createRemoteJWKSet(
18-
new URL('/oidc/jwks', process.env.LOGTO_ENDPOINT),
19-
);
17+
this.jwks = createRemoteJWKSet(new URL("/oidc/jwks", process.env.LOGTO_ENDPOINT));
2018
}
2119

2220
async canActivate(context: ExecutionContext): Promise<boolean> {
2321
const request = context.switchToHttp().getRequest();
2422
const token = this.extractTokenFromHeader(request);
25-
const uncheck = Reflect.getMetadata('uncheck', context.getHandler());
23+
const uncheck = Reflect.getMetadata("uncheck", context.getHandler());
2624

2725
if (!token && uncheck) {
28-
request['user'] = null;
26+
request["user"] = null;
2927
} else if (!token) {
3028
throw new UnauthorizedException();
3129
}
3230
try {
3331
const payload = await this.jwtVerify(token);
34-
request['userId'] = payload.sub;
32+
request["userId"] = payload.sub;
3533
} catch (e) {
3634
if (!uncheck) {
3735
throw new UnauthorizedException();
@@ -47,7 +45,7 @@ export class AuthGuard implements CanActivate {
4745
this.jwks,
4846
{
4947
// Expected issuer of the token, issued by the Logto server
50-
issuer: new URL('oidc', process.env.LOGTO_ENDPOINT).href,
48+
issuer: new URL("oidc", process.env.LOGTO_ENDPOINT).href,
5149
// Expected audience token, the resource indicator of the current API
5250
audience: process.env.BACKEND_ENDPOINT,
5351
},
@@ -57,7 +55,7 @@ export class AuthGuard implements CanActivate {
5755
}
5856

5957
private extractTokenFromHeader(request: Request): string | undefined {
60-
const [type, token] = request.headers.authorization?.split(' ') ?? [];
61-
return type === 'Bearer' ? token : undefined;
58+
const [type, token] = request.headers.authorization?.split(" ") ?? [];
59+
return type === "Bearer" ? token : undefined;
6260
}
6361
}

apps/api/src/common/db.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { schemas } from '@earthworm/schema';
2-
import { Logger } from '@nestjs/common';
3-
import { DefaultLogger, LogWriter } from 'drizzle-orm';
4-
import { drizzle } from 'drizzle-orm/postgres-js';
5-
import * as postgres from 'postgres';
1+
import { Logger } from "@nestjs/common";
2+
import { DefaultLogger, LogWriter } from "drizzle-orm";
3+
import { drizzle } from "drizzle-orm/postgres-js";
4+
import * as postgres from "postgres";
5+
6+
import { schemas } from "@earthworm/schema";
67

78
let connection: postgres.Sql;
89

910
async function createConnection() {
10-
return postgres(process.env.DATABASE_URL ?? '');
11+
return postgres(process.env.DATABASE_URL ?? "");
1112
}
1213

1314
export async function endDB() {
@@ -20,7 +21,7 @@ export async function endDB() {
2021
export async function setupDB() {
2122
if (connection) return;
2223

23-
const logger = new Logger('DB');
24+
const logger = new Logger("DB");
2425

2526
class CustomDbLogWriter implements LogWriter {
2627
write(message: string) {

apps/api/src/course-history/course-history.controller.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { Controller, Get, UseGuards } from '@nestjs/common';
2-
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
3-
import { AuthGuard } from '../auth/auth.guard';
4-
import { User, UserEntity } from '../user/user.decorators';
5-
import { CourseHistoryService } from './course-history.service';
1+
import { Controller, Get, UseGuards } from "@nestjs/common";
2+
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
3+
4+
import { AuthGuard } from "../auth/auth.guard";
5+
import { User, UserEntity } from "../user/user.decorators";
6+
import { CourseHistoryService } from "./course-history.service";
67

78
@ApiBearerAuth()
8-
@ApiTags('CourseHistory')
9-
@Controller('course-history')
9+
@ApiTags("CourseHistory")
10+
@Controller("course-history")
1011
export class CourseHistoryController {
1112
constructor(private readonly courseHistoryService: CourseHistoryService) {}
1213

1314
@ApiOperation({
14-
summary: '获取登陆用户的所有课程历史记录',
15+
summary: "获取登陆用户的所有课程历史记录",
1516
})
1617
@UseGuards(AuthGuard)
17-
@Get('')
18+
@Get("")
1819
courseCompletionCount(@User() user: UserEntity) {
1920
return this.courseHistoryService.findAll(user);
2021
}

apps/api/src/course-history/course-history.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Module } from '@nestjs/common';
2-
import { CourseHistoryController } from './course-history.controller';
3-
import { CourseHistoryService } from './course-history.service';
1+
import { Module } from "@nestjs/common";
2+
3+
import { CourseHistoryController } from "./course-history.controller";
4+
import { CourseHistoryService } from "./course-history.service";
45

56
@Module({
67
controllers: [CourseHistoryController],

0 commit comments

Comments
 (0)