chore: format
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
"fastify-swagger": "^4.8.3",
|
||||
"husky": "^7.0.1",
|
||||
"lint-staged": "^11.1.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mongoose": "^5.13.3",
|
||||
"mongoose-lean-virtuals": "^0.8.0",
|
||||
"nestjs-typegoose": "^7.1.38",
|
||||
@@ -72,6 +73,7 @@
|
||||
"@nestjs/testing": "^8.0.4",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/lodash": "^4.14.171",
|
||||
"@types/node": "^16.4.0",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "4.28.4",
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -15,6 +15,7 @@ specifiers:
|
||||
'@types/bcrypt': ^5.0.0
|
||||
'@types/express': ^4.17.13
|
||||
'@types/jest': ^26.0.24
|
||||
'@types/lodash': ^4.14.171
|
||||
'@types/node': ^16.4.0
|
||||
'@types/supertest': ^2.0.11
|
||||
'@typescript-eslint/eslint-plugin': 4.28.4
|
||||
@@ -32,6 +33,7 @@ specifiers:
|
||||
husky: ^7.0.1
|
||||
jest: 27.0.6
|
||||
lint-staged: ^11.1.0
|
||||
lodash: ^4.17.21
|
||||
mongoose: ^5.13.3
|
||||
mongoose-lean-virtuals: ^0.8.0
|
||||
nestjs-typegoose: ^7.1.38
|
||||
@@ -69,6 +71,7 @@ dependencies:
|
||||
fastify-swagger: 4.8.3
|
||||
husky: 7.0.1
|
||||
lint-staged: 11.1.0
|
||||
lodash: 4.17.21
|
||||
mongoose: 5.13.3
|
||||
mongoose-lean-virtuals: 0.8.0_mongoose@5.13.3
|
||||
nestjs-typegoose: 7.1.38_ad6502a9e63d94834e95766efca460e3
|
||||
@@ -87,6 +90,7 @@ devDependencies:
|
||||
'@nestjs/testing': 8.0.4_dbb23fa745e40b87eda38a58a66b6bd5
|
||||
'@types/express': 4.17.13
|
||||
'@types/jest': 26.0.24
|
||||
'@types/lodash': 4.14.171
|
||||
'@types/node': 16.4.0
|
||||
'@types/supertest': 2.0.11
|
||||
'@typescript-eslint/eslint-plugin': 4.28.4_b1648df9f9ba40bdeef3710a5a5af353
|
||||
@@ -1208,6 +1212,10 @@ packages:
|
||||
resolution: {integrity: sha512-YSBPTLTVm2e2OoQIDYx8HaeWJ5tTToLH67kXR7zYNGupXMEHa2++G8k+DczX2cFVgalypqtyZIcU19AFcmOpmg==}
|
||||
dev: true
|
||||
|
||||
/@types/lodash/4.14.171:
|
||||
resolution: {integrity: sha512-7eQ2xYLLI/LsicL2nejW9Wyko3lcpN6O/z0ZLHrEQsg280zIdCv1t/0m6UtBjUHokCGBQ3gYTbHzDkZ1xOBwwg==}
|
||||
dev: true
|
||||
|
||||
/@types/mime/1.3.2:
|
||||
resolution: {integrity: sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==}
|
||||
dev: true
|
||||
|
||||
@@ -4,8 +4,8 @@ import { AppController } from './app.controller'
|
||||
import { InitModule } from './modules/init/init.module'
|
||||
import { UserModule } from './modules/user/user.module'
|
||||
import { HelperModule } from './modules/helper/helper.module'
|
||||
import { PostModule } from './modules/post/post.module';
|
||||
import { CategoryModule } from './modules/category/category.module';
|
||||
import { PostModule } from './modules/post/post.module'
|
||||
import { CategoryModule } from './modules/category/category.module'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
15
src/common/exceptions/cant-find.exception.ts
Normal file
15
src/common/exceptions/cant-find.exception.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { NotFoundException } from '@nestjs/common'
|
||||
import { sample } from 'lodash'
|
||||
export const NotFoundMessage = [
|
||||
'真不巧, 内容走丢了 o(╥﹏╥)o',
|
||||
'电波无法到达 ωω',
|
||||
'数据..不小心丢失了啦 π_π',
|
||||
'404, 这也不是我的错啦 (๐•̆ ·̭ •̆๐)',
|
||||
'嘿, 这里空空如也, 不如别处走走?',
|
||||
]
|
||||
|
||||
export class CannotFindException extends NotFoundException {
|
||||
constructor() {
|
||||
super(sample(NotFoundMessage))
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PostController } from './post.controller';
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { PostController } from './post.controller'
|
||||
|
||||
describe('PostController', () => {
|
||||
let controller: PostController;
|
||||
let controller: PostController
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PostController],
|
||||
}).compile();
|
||||
}).compile()
|
||||
|
||||
controller = module.get<PostController>(PostController);
|
||||
});
|
||||
controller = module.get<PostController>(PostController)
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
expect(controller).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from '@nestjs/common'
|
||||
import { ReturnModelType } from '@typegoose/typegoose'
|
||||
import { InjectModel } from 'nestjs-typegoose'
|
||||
import { CannotFindException } from '~/common/exceptions/cant-find.exception'
|
||||
import { CategoryService } from '../category/category.service'
|
||||
import { PostModel } from './post.model'
|
||||
|
||||
@@ -27,7 +28,21 @@ export class PostService {
|
||||
if (!category) {
|
||||
throw new UnprocessableEntityException('分类丢失了 ಠ_ಠ')
|
||||
}
|
||||
const res = this.postModel.create(post)
|
||||
const res = await this.postModel.create({
|
||||
...post,
|
||||
categoryId: category.id,
|
||||
created: new Date(),
|
||||
modified: null,
|
||||
})
|
||||
// TODO: clean cache
|
||||
return res
|
||||
}
|
||||
|
||||
async findPostById(id: string) {
|
||||
const doc = await this.postModel.findById(id).populate('category')
|
||||
if (!doc) {
|
||||
throw new CannotFindException()
|
||||
}
|
||||
return doc
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ export abstract class WriteBaseModel extends BaseCommentIndexModel {
|
||||
@prop({ type: Image })
|
||||
images?: Image[]
|
||||
|
||||
@prop({ default: () => new Date() })
|
||||
modified: Date
|
||||
@prop({ default: null })
|
||||
modified: Date | null
|
||||
}
|
||||
|
||||
@modelOptions({
|
||||
|
||||
Reference in New Issue
Block a user