Skip to content

Commit

Permalink
chore: rename api with server
Browse files Browse the repository at this point in the history
  • Loading branch information
kuizuo committed Feb 2, 2024
1 parent 8b25956 commit 309ffe8
Show file tree
Hide file tree
Showing 213 changed files with 2,097 additions and 2,419 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 4 additions & 6 deletions apps/api/package.json → apps/server/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "api",
"name": "server",
"version": "0.1.0",
"private": true,
"packageManager": "pnpm@8.15.1",
Expand Down Expand Up @@ -120,11 +120,9 @@
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
},
"overrides": {
"@liaoliaots/nestjs-redis": {
"@nestjs/common": "10.2.9",
"@nestjs/core": "10.2.9"
}
"resolutions": {
"@nestjs/common@^9.0.0": "^10.3.1",
"@nestjs/core@^9.0.0": "^10.3.1"
},
"jest": {
"moduleFileExtensions": [
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions apps/api/src/app.module.ts → apps/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ClassSerializerInterceptor, Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'

import * as config from '~/config'
import { SharedModule } from '~/shared/shared.module'
import * as config from '@server/config'
import { SharedModule } from '@server/shared/shared.module'

import { AllExceptionsFilter } from './common/filters/any-exception.filter'

Expand Down Expand Up @@ -58,4 +58,4 @@ import { SocketModule } from './socket/socket.module'
{ provide: APP_GUARD, useClass: RbacGuard },
],
})
export class AppModule {}
export class AppModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INestApplication } from '@nestjs/common'
import { IoAdapter } from '@nestjs/platform-socket.io'
import { createAdapter } from '@socket.io/redis-adapter'

import { REDIS_PUBSUB } from '~/shared/redis/redis.constant'
import { REDIS_PUBSUB } from '@server/shared/redis/redis.constant'

export const RedisIoAdapterKey = 'm-shop-socket'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpStatus, Type, applyDecorators } from '@nestjs/common'
import { ApiExtraModels, ApiResponse, getSchemaPath } from '@nestjs/swagger'

import { ResOp } from '~/common/model/response.model'
import { ResOp } from '@server/common/model/response.model'

const baseTypeNames = ['String', 'Number', 'Boolean']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cluster from 'node:cluster'

import { Cron } from '@nestjs/schedule'

import { isMainProcess } from '~/global/env'
import { isMainProcess } from '@server/global/env'

export const CronOnce: typeof Cron = (...rest): MethodDecorator => {
// If not in cluster mode, and PM2 main worker
Expand All @@ -14,6 +14,6 @@ export const CronOnce: typeof Cron = (...rest): MethodDecorator => {
// eslint-disable-next-line no-useless-call
return Cron.call(null, ...rest)

const returnNothing: MethodDecorator = () => {}
const returnNothing: MethodDecorator = () => { }
return returnNothing
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ExecutionContext } from '@nestjs/common'
import { createParamDecorator } from '@nestjs/common'
import type { FastifyRequest } from 'fastify'

import { getIp } from '~/utils/ip.util'
import { getIp } from '@server/utils/ip.util'

/**
* 快速获取IP
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpException, HttpStatus } from '@nestjs/common'

import { ErrorEnum } from '~/constants/error-code.constant'
import { RESPONSE_SUCCESS_CODE } from '~/constants/response.constant'
import { ErrorEnum } from '@server/constants/error-code.constant'
import { RESPONSE_SUCCESS_CODE } from '@server/constants/response.constant'

export class BusinessException extends HttpException {
private errorCode: number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpException } from '@nestjs/common'
import { WsException } from '@nestjs/websockets'

import { ErrorEnum } from '~/constants/error-code.constant'
import { ErrorEnum } from '@server/constants/error-code.constant'

export class SocketException extends WsException {
private errorCode: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
} from '@nestjs/common'
import { FastifyReply, FastifyRequest } from 'fastify'

import { BusinessException } from '~/common/exceptions/biz.exception'
import { ErrorEnum } from '~/constants/error-code.constant'
import { BusinessException } from '@server/common/exceptions/biz.exception'
import { ErrorEnum } from '@server/constants/error-code.constant'

import { isDev } from '~/global/env'
import { isDev } from '@server/global/env'

interface myError {
readonly status: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { Reflector } from '@nestjs/core'
import type { FastifyRequest } from 'fastify'
import { catchError, tap } from 'rxjs'

import { CacheService } from '~/shared/redis/cache.service'
import { hashString } from '~/utils'
import { getIp } from '~/utils/ip.util'
import { getRedisKey } from '~/utils/redis.util'
import { CacheService } from '@server/shared/redis/cache.service'
import { hashString } from '@server/utils'
import { getIp } from '@server/utils/ip.util'
import { getRedisKey } from '@server/utils/redis.util'

import { HTTP_IDEMPOTENCE_KEY, HTTP_IDEMPOTENCE_OPTIONS } from '../decorators/idempotence.decorator'

Expand Down Expand Up @@ -54,7 +54,7 @@ export class IdempotenceInterceptor implements NestInterceptor {
constructor(
private readonly reflector: Reflector,
private readonly cacheService: CacheService,
) {}
) { }

async intercept(context: ExecutionContext, next: CallHandler) {
const request = context.switchToHttp().getRequest<FastifyRequest>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Reflector } from '@nestjs/core'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'

import { ResOp } from '~/common/model/response.model'
import { ResOp } from '@server/common/model/response.model'

import { BYPASS_KEY } from '../decorators/bypass.decorator'

Expand All @@ -18,7 +18,7 @@ import { BYPASS_KEY } from '../decorators/bypass.decorator'
*/
@Injectable()
export class TransformInterceptor implements NestInterceptor {
constructor(private readonly reflector: Reflector) {}
constructor(private readonly reflector: Reflector) { }

intercept(
context: ExecutionContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiProperty } from '@nestjs/swagger'
import {
RESPONSE_SUCCESS_CODE,
RESPONSE_SUCCESS_MSG,
} from '~/constants/response.constant'
} from '@server/constants/response.constant'

export class ResOp<T = any> {
@ApiProperty({ type: 'object' })
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigType, registerAs } from '@nestjs/config'

import { env, envNumber } from '~/global/env'
import { env, envNumber } from '@server/global/env'

export const AppConfig = registerAs('app', () => ({
name: env('APP_NAME'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ConfigType, registerAs } from '@nestjs/config'

import { DataSource, DataSourceOptions } from 'typeorm'

import { env, envBoolean, envNumber } from '~/global/env'
import { env, envBoolean, envNumber } from '@server/global/env'

// eslint-disable-next-line import/order
import dotenv from 'dotenv'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigType, registerAs } from '@nestjs/config'

import { env, envNumber } from '~/global/env'
import { env, envNumber } from '@server/global/env'

export const MailerConfig = registerAs('mailer', () => ({
host: env('SMTP_HOST'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigType, registerAs } from '@nestjs/config'

import { env, envNumber } from '~/global/env'
import { env, envNumber } from '@server/global/env'

export const RedisConfig = registerAs('redis', () => ({
host: env('REDIS_HOST', '127.0.0.1'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigType, registerAs } from '@nestjs/config'

import { env, envNumber } from '~/global/env'
import { env, envNumber } from '@server/global/env'

export const SecurityConfig = registerAs('security', () => ({
jwtSecret: env('JWT_SECRET'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigType, registerAs } from '@nestjs/config'

import { env, envBoolean } from '~/global/env'
import { env, envBoolean } from '@server/global/env'

export const SwaggerConfig = registerAs('swagger', () => ({
enable: envBoolean('SWAGGER_ENABLE'),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NotFoundException } from '@nestjs/common'
import { ObjectLiteral, Repository } from 'typeorm'

import { PagerDto } from '~/common/dto/pager.dto'
import { PagerDto } from '@server/common/dto/pager.dto'

import { paginate } from '../paginate'
import { Pagination } from '../paginate/pagination'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
import { ApiBody, IntersectionType, PartialType } from '@nestjs/swagger'
import pluralize from 'pluralize'

import { ApiResult } from '~/common/decorators/api-result.decorator'
import { IdParam } from '~/common/decorators/id-param.decorator'
import { PagerDto } from '~/common/dto/pager.dto'
import { ApiResult } from '@server/common/decorators/api-result.decorator'
import { IdParam } from '@server/common/decorators/id-param.decorator'
import { PagerDto } from '@server/common/dto/pager.dto'

import { PermissionMap } from '~/modules/auth/decorators/permission.decorator'
import { PermissionMap } from '@server/modules/auth/decorators/permission.decorator'

import { BaseService } from './base.service'

Expand All @@ -27,11 +27,11 @@ export function BaseCrudFactory<
const prefix = entity.name.toLowerCase().replace(/entity$/, '')
const pluralizeName = pluralize(prefix) as string

dto = dto ?? class extends entity {}
dto = dto ?? class extends entity { }

class Dto extends dto {}
class UpdateDto extends PartialType(Dto) {}
class QueryDto extends IntersectionType(PagerDto, PartialType(Dto)) {}
class Dto extends dto { }
class UpdateDto extends PartialType(Dto) { }
class QueryDto extends IntersectionType(PagerDto, PartialType(Dto)) { }

permissions = permissions ?? {
LIST: `${prefix}:list`,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Body, Controller, Headers, Post, UseGuards } from '@nestjs/common'
import { ApiOperation, ApiTags } from '@nestjs/swagger'

import { ApiResult } from '~/common/decorators/api-result.decorator'
import { Ip } from '~/common/decorators/http.decorator'
import { ApiResult } from '@server/common/decorators/api-result.decorator'
import { Ip } from '@server/common/decorators/http.decorator'

import { UserService } from '../user/user.service'

Expand All @@ -20,7 +20,7 @@ export class AuthController {
constructor(
private authService: AuthService,
private userService: UserService,
) {}
) { }

@Post('login')
@ApiOperation({ summary: '登录' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { JwtModule } from '@nestjs/jwt'
import { PassportModule } from '@nestjs/passport'
import { TypeOrmModule } from '@nestjs/typeorm'

import { ISecurityConfig } from '~/config'
import { isDev } from '~/global/env'
import { ISecurityConfig } from '@server/config'
import { isDev } from '@server/global/env'

import { LogModule } from '../system/log/log.module'
import { MenuModule } from '../system/menu/menu.module'
Expand Down Expand Up @@ -61,4 +61,4 @@ const strategies = [LocalStrategy, JwtStrategy]
providers: [...providers, ...strategies],
exports: [TypeOrmModule, JwtModule, ...providers],
})
export class AuthModule {}
export class AuthModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Injectable } from '@nestjs/common'
import Redis from 'ioredis'
import { isEmpty } from 'lodash'

import { BusinessException } from '~/common/exceptions/biz.exception'
import { BusinessException } from '@server/common/exceptions/biz.exception'

import { ErrorEnum } from '~/constants/error-code.constant'
import { ErrorEnum } from '@server/constants/error-code.constant'

import { UserService } from '~/modules/user/user.service'
import { UserService } from '@server/modules/user/user.service'

import { md5 } from '~/utils'
import { md5 } from '@server/utils'

import { LoginLogService } from '../system/log/services/login-log.service'
import { MenuService } from '../system/menu/menu.service'
Expand All @@ -27,7 +27,7 @@ export class AuthService {
private userService: UserService,
private loginLogService: LoginLogService,
private tokenService: TokenService,
) {}
) { }

async validateUser(credential: string, password: string): Promise<any> {
const user = await this.userService.findUserByUserName(credential)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Body, Controller, Get, Post, Put, UseGuards } from '@nestjs/common'
import { ApiExtraModels, ApiOperation, ApiTags } from '@nestjs/swagger'

import { ApiResult } from '~/common/decorators/api-result.decorator'
import { ApiResult } from '@server/common/decorators/api-result.decorator'

import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator'
import { AllowAnon } from '~/modules/auth/decorators/allow-anon.decorator'
import { AuthUser } from '~/modules/auth/decorators/auth-user.decorator'
import { ApiSecurityAuth } from '@server/common/decorators/swagger.decorator'
import { AllowAnon } from '@server/modules/auth/decorators/allow-anon.decorator'
import { AuthUser } from '@server/modules/auth/decorators/auth-user.decorator'

import { MenuEntity } from '~/modules/system/menu/menu.entity'
import { MenuEntity } from '@server/modules/system/menu/menu.entity'

import { PasswordUpdateDto } from '~/modules/user/dto/password.dto'
import { PasswordUpdateDto } from '@server/modules/user/dto/password.dto'

import { AccountInfo } from '../../user/user.model'
import { UserService } from '../../user/user.service'
Expand All @@ -26,7 +26,7 @@ export class AccountController {
constructor(
private userService: UserService,
private authService: AuthService,
) {}
) { }

@Get('profile')
@ApiOperation({ summary: '获取账户资料' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Redis from 'ioredis'
import { isEmpty } from 'lodash'
import * as svgCaptcha from 'svg-captcha'

import { ApiResult } from '~/common/decorators/api-result.decorator'
import { generateUUID } from '~/utils'
import { ApiResult } from '@server/common/decorators/api-result.decorator'
import { generateUUID } from '@server/utils'

import { Public } from '../decorators/public.decorator'

Expand All @@ -20,7 +20,7 @@ import { ImageCaptcha } from '../models/auth.model'
@UseGuards(ThrottlerGuard)
@Controller('auth/captcha')
export class CaptchaController {
constructor(@InjectRedis() private redis: Redis) {}
constructor(@InjectRedis() private redis: Redis) { }

@Get('img')
@ApiOperation({ summary: '获取登录图片验证码' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ApiOperation, ApiTags } from '@nestjs/swagger'

import { Throttle, ThrottlerGuard } from '@nestjs/throttler'

import { Ip } from '~/common/decorators/http.decorator'
import { Ip } from '@server/common/decorators/http.decorator'

import { MailerService } from '~/shared/mailer/mailer.service'
import { MailerService } from '@server/shared/mailer/mailer.service'

import { Public } from '../decorators/public.decorator'

Expand All @@ -15,7 +15,7 @@ import { SendEmailCodeDto } from '../dto/captcha.dto'
@UseGuards(ThrottlerGuard)
@Controller('auth/email')
export class EmailController {
constructor(private mailerService: MailerService) {}
constructor(private mailerService: MailerService) { }

@Post('send')
@ApiOperation({ summary: '发送邮箱验证码' })
Expand Down
File renamed without changes.
Loading

0 comments on commit 309ffe8

Please sign in to comment.