forked from houdunwang/v2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa2b0b2
commit fdc1882
Showing
173 changed files
with
18,884 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,9 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
import { Random } from 'mockjs' | ||
import { soft } from './seed/soft' | ||
import user from './seed/user' | ||
const prisma = new PrismaClient() | ||
|
||
async function run() { | ||
for (let i = 0; i < 30; i++) { | ||
await prisma.user.create({ | ||
data: { | ||
name: Random.cname(), | ||
password: Random.string(), | ||
App: { | ||
create: { | ||
title: Random.csentence(), | ||
content: Random.cparagraph(), | ||
preview: Random.image('300x300'), | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
await user() | ||
await soft() | ||
} | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { NestFactory } from '@nestjs/core' | ||
import { AppModule } from './app.module' | ||
import { ValidatePipeCustom } from './pipe/validate-pipe-custom' | ||
import { NestExpressApplication } from '@nestjs/platform-express' | ||
import { HttpStatus } from '@nestjs/common' | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule) | ||
const app = await NestFactory.create<NestExpressApplication>(AppModule) | ||
app.setGlobalPrefix('api') | ||
app.useGlobalPipes(new ValidatePipeCustom()) | ||
app.useStaticAssets('uploads', { prefix: '/uploads' }) | ||
app.useGlobalPipes(new ValidatePipeCustom({ errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY })) | ||
await app.listen(3000) | ||
} | ||
bootstrap() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
export class CreateSoftDto {} | ||
import { IsNotEmpty } from 'class-validator' | ||
|
||
export class CreateSoftDto { | ||
@IsNotEmpty() | ||
title: string | ||
|
||
@IsNotEmpty() | ||
content: string | ||
|
||
@IsNotEmpty() | ||
preview: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreateSoftDto } from './create-soft.dto'; | ||
import { PartialType } from '@nestjs/mapped-types' | ||
import { CreateSoftDto } from './create-soft.dto' | ||
|
||
export class UpdateSoftDto extends PartialType(CreateSoftDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateSoftDto } from './dto/create-soft.dto'; | ||
import { UpdateSoftDto } from './dto/update-soft.dto'; | ||
import { Inject, Injectable } from '@nestjs/common' | ||
import { User } from '@prisma/client' | ||
import { PrismaService } from 'src/common/prisma.service' | ||
import { CreateSoftDto } from './dto/create-soft.dto' | ||
import { UpdateSoftDto } from './dto/update-soft.dto' | ||
import { REQUEST } from '@nestjs/core' | ||
|
||
@Injectable() | ||
export class SoftService { | ||
create(createSoftDto: CreateSoftDto) { | ||
return 'This action adds a new soft'; | ||
constructor(private prisma: PrismaService) {} | ||
create(data: CreateSoftDto, user: User) { | ||
return this.prisma.soft.create({ | ||
data, | ||
}) | ||
} | ||
|
||
findAll() { | ||
return `This action returns all soft`; | ||
async findAll(page = 1) { | ||
const row = 10 | ||
const data = await this.prisma.soft.findMany({ | ||
skip: (page - 1) * row, | ||
take: row, | ||
}) | ||
|
||
return { | ||
meta: { page, row, total: await this.prisma.soft.count() }, | ||
data, | ||
} | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} soft`; | ||
return this.prisma.soft.findFirst({ where: { id } }) | ||
} | ||
|
||
update(id: number, updateSoftDto: UpdateSoftDto) { | ||
return `This action updates a #${id} soft`; | ||
update(id: number, dto: UpdateSoftDto) { | ||
return this.prisma.soft.update({ | ||
where: { id }, | ||
data: { ...dto }, | ||
}) | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} soft`; | ||
return this.prisma.soft.deleteMany({ where: { id } }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class CreateUploadDto {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreateUploadDto } from './create-upload.dto'; | ||
|
||
export class UpdateUploadDto extends PartialType(CreateUploadDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Controller, Post, UploadedFile } from '@nestjs/common' | ||
import { Uploader } from './upload.decorator' | ||
import { Auth } from 'src/auth/auth.decorator' | ||
|
||
@Controller('upload') | ||
export class UploadController { | ||
@Post('image') | ||
@Uploader('image') | ||
@Auth() | ||
image(@UploadedFile() file: Express.Multer.File) { | ||
return file | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { UnsupportedMediaTypeException, UseInterceptors, applyDecorators } from '@nestjs/common' | ||
import { FileInterceptor } from '@nestjs/platform-express' | ||
|
||
export function Uploader(mime: string, field = 'file') { | ||
return applyDecorators( | ||
UseInterceptors( | ||
FileInterceptor(field, { | ||
limits: { | ||
fileSize: Math.pow(1024, 2) * 2, | ||
}, | ||
fileFilter( | ||
req: Request, | ||
file: Express.Multer.File, | ||
callback: (error: Error | null, acceptFile: boolean) => void, | ||
) { | ||
if (!file.mimetype.includes(mime)) { | ||
callback(new UnsupportedMediaTypeException('文件类型错误'), false) | ||
} else { | ||
callback(null, true) | ||
} | ||
}, | ||
}), | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Module } from '@nestjs/common' | ||
import { UploadService } from './upload.service' | ||
import { UploadController } from './upload.controller' | ||
import { MulterModule } from '@nestjs/platform-express' | ||
import { diskStorage } from 'multer' | ||
import dayjs from 'dayjs' | ||
import { extname } from 'path' | ||
|
||
@Module({ | ||
imports: [ | ||
MulterModule.registerAsync({ | ||
useFactory() { | ||
return { | ||
storage: diskStorage({ | ||
//文件储存位置 | ||
destination: 'uploads/' + dayjs().format('YYYY/MM'), | ||
//文件名定制 | ||
filename: (req, file, callback) => { | ||
const path = Date.now() + '-' + Math.round(Math.random() * 1e10) + extname(file.originalname) | ||
callback(null, path) | ||
}, | ||
}), | ||
} | ||
}, | ||
}), | ||
], | ||
controllers: [UploadController], | ||
providers: [UploadService], | ||
}) | ||
export class UploadModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateUploadDto } from './dto/create-upload.dto'; | ||
import { UpdateUploadDto } from './dto/update-upload.dto'; | ||
|
||
@Injectable() | ||
export class UploadService { | ||
create(createUploadDto: CreateUploadDto) { | ||
return 'This action adds a new upload'; | ||
} | ||
|
||
findAll() { | ||
return `This action returns all upload`; | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} upload`; | ||
} | ||
|
||
update(id: number, updateUploadDto: UpdateUploadDto) { | ||
return `This action updates a #${id} upload`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} upload`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class CreateUserDto {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreateUserDto } from './create-user.dto'; | ||
|
||
export class UpdateUserDto extends PartialType(CreateUserDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class User {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Controller, Get } from '@nestjs/common' | ||
import { User } from '@prisma/client' | ||
import { Auth } from 'src/auth/auth.decorator' | ||
import { CurrentUser } from 'src/auth/current-user.decorator' | ||
import { UserService } from './user.service' | ||
|
||
@Controller('user') | ||
export class UserController { | ||
constructor(private readonly userService: UserService) {} | ||
|
||
@Get('current') | ||
@Auth() | ||
info(@CurrentUser() user: User) { | ||
return user | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { UserService } from './user.service'; | ||
import { UserController } from './user.controller'; | ||
|
||
@Module({ | ||
controllers: [UserController], | ||
providers: [UserService] | ||
}) | ||
export class UserModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateUserDto } from './dto/create-user.dto'; | ||
import { UpdateUserDto } from './dto/update-user.dto'; | ||
|
||
@Injectable() | ||
export class UserService { | ||
create(createUserDto: CreateUserDto) { | ||
return 'This action adds a new user'; | ||
} | ||
|
||
findAll() { | ||
return `This action returns all user`; | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} user`; | ||
} | ||
|
||
update(id: number, updateUserDto: UpdateUserDto) { | ||
return `This action updates a #${id} user`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} user`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] | ||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "vue"] | ||
} |
Oops, something went wrong.