Skip to content

Commit

Permalink
Merge pull request #432 from skyclouds2001/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
skyclouds2001 authored Sep 21, 2023
2 parents 13b06e5 + be3bb51 commit 202a8d1
Show file tree
Hide file tree
Showing 75 changed files with 3,332 additions and 2,294 deletions.
23 changes: 1 addition & 22 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,17 @@ module.exports = {
},
plugins: [],
overrides: [
{
files: ['**/*.md'],
customSyntax: 'postcss-markdown',
},
{
files: ['**/*.html'],
extends: ['stylelint-config-html'],
},
{
files: ['**/*.vue'],
extends: ['stylelint-config-standard-vue'],
},
{
files: ['**/*.sass'],
customSyntax: 'postcss-sass',
},
{
files: ['**/*.scss'],
extends: ['stylelint-config-standard-scss', 'stylelint-config-prettier-scss'],
},
{
files: ['**/*.less'],
extends: ['stylelint-config-recommended-less'],
customSyntax: 'postcss-less',
},
{
files: ['**/*.styl', '**/*.stylus'],
extends: ['stylelint-stylus/standard'],
},
{
files: ['**/*.sss'],
customSyntax: 'sugarss',
extends: ['stylelint-config-standard-less'],
},
],
}
32 changes: 16 additions & 16 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@
"dependencies": {
"@nestjs/axios": "^3.0.0",
"@nestjs/cache-manager": "^2.1.0",
"@nestjs/common": "^10.2.4",
"@nestjs/config": "^3.0.1",
"@nestjs/core": "^10.2.4",
"@nestjs/common": "^10.2.5",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.5",
"@nestjs/devtools-integration": "^0.1.5",
"@nestjs/jwt": "^10.1.1",
"@nestjs/passport": "^10.0.1",
"@nestjs/platform-express": "^10.2.4",
"@nestjs/platform-socket.io": "^10.2.4",
"@nestjs/passport": "^10.0.2",
"@nestjs/platform-express": "^10.2.5",
"@nestjs/platform-socket.io": "^10.2.5",
"@nestjs/schedule": "^3.0.3",
"@nestjs/swagger": "^7.1.10",
"@nestjs/websockets": "^10.2.4",
"@prisma/client": "4.16.2",
"@nestjs/swagger": "^7.1.11",
"@nestjs/websockets": "^10.2.5",
"@prisma/client": "5.3.1",
"axios": "^1.5.0",
"bcryptjs": "^2.4.3",
"cache-manager": "^5.2.3",
Expand All @@ -64,7 +64,7 @@
"express-session": "^1.17.3",
"hbs": "^4.2.0",
"joi": "^17.10.1",
"nestjs-prisma": "^0.20.1",
"nestjs-prisma": "^0.22.0",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"reflect-metadata": "^0.1.13",
Expand All @@ -74,17 +74,17 @@
"devDependencies": {
"@nestjs/cli": "^10.1.17",
"@nestjs/schematics": "^10.0.2",
"@nestjs/testing": "^10.2.4",
"@types/bcryptjs": "^2.4.3",
"@types/compression": "^1.7.2",
"@types/cookie-parser": "^1.4.3",
"@nestjs/testing": "^10.2.5",
"@types/bcryptjs": "^2.4.4",
"@types/compression": "^1.7.3",
"@types/cookie-parser": "^1.4.4",
"@types/express": "^4.17.17",
"@types/express-session": "^1.17.7",
"@types/multer": "^1.4.7",
"@types/node": "^20.5.9",
"@types/node": "^20.6.2",
"@types/passport-jwt": "^3.0.9",
"@types/supertest": "^2.0.12",
"prisma": "^4.16.2",
"prisma": "^5.3.1",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-node": "^10.9.1",
Expand Down
4 changes: 4 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { FilesModule } from './files/files.module'
import { WsModule } from './ws/ws.module'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { RolesModule } from './roles/roles.module'
import { DepartmentsModule } from './departments/departments.module'

@Module({
imports: [
Expand Down Expand Up @@ -46,6 +48,8 @@ import { AppService } from './app.service'
ProjectModule,
WsModule,
FilesModule,
RolesModule,
DepartmentsModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
2 changes: 1 addition & 1 deletion backend/src/articles/articles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ArticlesService } from './articles.service'
import { CreateArticleDto } from './dto/create-article.dto'
import { UpdateArticleDto } from './dto/update-article.dto'
import { ArticleEntity } from './entities/article.entity'
import { Pagination } from './../entities/pagination.entity'
import { Pagination } from './../common/pagination.entity'

@Controller('articles')
@UseInterceptors(CacheInterceptor)
Expand Down
22 changes: 11 additions & 11 deletions backend/src/articles/dto/create-article.dto.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { ApiProperty } from '@nestjs/swagger'
import { ArticleStatus } from '@prisma/client'
import { IsEnum, IsInt, IsNotEmpty, IsOptional, IsPositive, IsString, Max, MaxLength, Min, MinLength } from 'class-validator'
import { IsEnum, IsInt, IsOptional, IsPositive, IsString, Max, MaxLength, Min, MinLength } from 'class-validator'

export class CreateArticleDto {
@IsString()
@IsNotEmpty()
@MinLength(5)
@MaxLength(25)
@ApiProperty({
description: '文章标题',
minLength: 5,
maxLength: 25,
})
title: string

@IsString()
@IsOptional()
@IsNotEmpty()
@MaxLength(250)
@IsOptional()
@ApiProperty({
description: '文章描述',
required: false,
maxLength: 250,
required: false,
})
description?: string

@IsInt()
@IsNotEmpty()
@IsPositive()
@ApiProperty({
description: '文章作者ID',
minimum: 0,
exclusiveMinimum: true,
})
authorId: number

@IsInt()
@IsNotEmpty()
@Min(0)
@Max(5)
@ApiProperty({
Expand All @@ -43,21 +43,21 @@ export class CreateArticleDto {
star: number

@IsInt()
@IsNotEmpty()
@IsPositive()
@ApiProperty({
description: '文章阅读量',
minimum: 0,
exclusiveMinimum: true,
})
read: number

@IsEnum(ArticleStatus)
@IsOptional()
@IsNotEmpty()
@ApiProperty({
description: '文章发布状态',
required: false,
default: 'Drafted',
enum: ArticleStatus,
default: 'Drafted',
required: false,
})
status: ArticleStatus = 'Drafted'
}
5 changes: 4 additions & 1 deletion backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import * as bcyptjs from 'bcryptjs'

@Injectable()
export class AuthService {
constructor(private readonly prisma: PrismaService, private readonly jwtService: JwtService) {}
constructor(
private readonly prisma: PrismaService,
private readonly jwtService: JwtService
) {}

async login(email: string, password: string) {
const user = await this.prisma.user.findUnique({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArgumentsHost, Catch, ExceptionFilter, HttpStatus, Logger } from '@nestjs/common'
import { Request, Response } from 'express'
import { Result } from './../entities/result.entity'
import { Result } from '../common/result.entity'

@Catch()
export class ExceptionsFilter implements ExceptionFilter<unknown> {
Expand All @@ -16,6 +16,8 @@ Request original url: ${request.originalUrl}
Method: ${request.method}
IP: ${request.ip}
Code: ${HttpStatus.INTERNAL_SERVER_ERROR}
${String((exception as Error).stack)}
-----------------------------------------------------------------------
`
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArgumentsHost, Catch, ExceptionFilter, HttpException, Logger } from '@nestjs/common'
import { Request, Response } from 'express'
import { Result } from './../entities/result.entity'
import { Result } from './result.entity'

@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter<HttpException> {
Expand All @@ -17,6 +17,8 @@ Request original url: ${request.originalUrl}
Method: ${request.method}
IP: ${request.ip}
Code: ${status}
${String(exception.stack)}
-----------------------------------------------------------------------
`
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'
import { Observable, map } from 'rxjs'
import { Result } from './../entities/result.entity'
import { Result } from './result.entity'

@Injectable()
export class TransformResultInterceptor implements NestInterceptor {
Expand Down
21 changes: 21 additions & 0 deletions backend/src/departments/departments.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Test, TestingModule } from '@nestjs/testing'
import { beforeEach, describe, expect, it } from 'vitest'
import { DepartmentsController } from './departments.controller'
import { DepartmentsService } from './departments.service'

describe('DepartmentsController', () => {
let controller: DepartmentsController

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [DepartmentsController],
providers: [DepartmentsService],
}).compile()

controller = module.get<DepartmentsController>(DepartmentsController)
})

it('should be defined', () => {
expect(controller).toBeDefined()
})
})
99 changes: 99 additions & 0 deletions backend/src/departments/departments.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Controller, Get, Post, Body, Param, Delete, HttpStatus, HttpCode, Query, DefaultValuePipe, ParseIntPipe, Put } from '@nestjs/common'
import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'
import { DepartmentsService } from './departments.service'
import { CreateDepartmentDto } from './dto/create-department.dto'
import { UpdateDepartmentDto } from './dto/update-department.dto'
import { DepartmentEntity } from './entities/department.entity'
import { Pagination } from './../common/pagination.entity'

@Controller('departments')
@ApiTags('departments')
export class DepartmentsController {
constructor(private readonly departmentsService: DepartmentsService) {}

@Post()
@HttpCode(HttpStatus.OK)
@ApiBody({
type: CreateDepartmentDto,
description: '待添加的部门信息',
})
@ApiCreatedResponse({
type: DepartmentEntity,
description: '部门信息',
})
create(@Body() createDepartmentDto: CreateDepartmentDto) {
return this.departmentsService.create(createDepartmentDto)
}

@Get()
@ApiOkResponse({
type: DepartmentEntity,
isArray: true,
description: '部门信息列表',
})
findAll() {
return this.departmentsService.findAll()
}

@Get('')
@ApiQuery({
name: 'page',
description: '分页页码',
required: false,
})
@ApiQuery({
name: 'size',
description: '分页容量',
required: false,
})
@ApiOkResponse({
type: Pagination<DepartmentEntity>,
description: '部门信息分页列表',
})
async findPage(@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number, @Query('size', new DefaultValuePipe(10), ParseIntPipe) size: number) {
return new Pagination(await this.departmentsService.findPage(page, size), page, size, await this.departmentsService.count())
}

@Get(':id')
@ApiParam({
name: 'id',
description: '部门ID',
})
@ApiOkResponse({
type: DepartmentEntity,
description: '部门信息',
})
findOne(@Param('id', ParseIntPipe) id: number) {
return this.departmentsService.findOne(id)
}

@Put(':id')
@ApiParam({
name: 'id',
description: '部门ID',
})
@ApiBody({
type: UpdateDepartmentDto,
description: '待更新的部门信息',
})
@ApiOkResponse({
type: DepartmentEntity,
description: '部门信息',
})
update(@Param('id', ParseIntPipe) id: number, @Body() updateDepartmentDto: UpdateDepartmentDto) {
return this.departmentsService.update(id, updateDepartmentDto)
}

@Delete(':id')
@ApiParam({
name: 'id',
description: '部门ID',
})
@ApiOkResponse({
type: DepartmentEntity,
description: '部门信息',
})
remove(@Param('id', ParseIntPipe) id: number) {
return this.departmentsService.remove(id)
}
}
12 changes: 12 additions & 0 deletions backend/src/departments/departments.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common'
import { PrismaModule } from 'nestjs-prisma'
import { DepartmentsService } from './departments.service'
import { DepartmentsController } from './departments.controller'

@Module({
controllers: [DepartmentsController],
providers: [DepartmentsService],
imports: [PrismaModule],
exports: [DepartmentsService],
})
export class DepartmentsModule {}
Loading

0 comments on commit 202a8d1

Please sign in to comment.