Skip to content

Commit

Permalink
chore: remove isdraft field
Browse files Browse the repository at this point in the history
  • Loading branch information
bs32g1038 committed Jul 27, 2023
1 parent 16e13c5 commit 2d83369
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 13 deletions.
4 changes: 0 additions & 4 deletions server/models/article.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const ArticleJoiSchema = {
post: (schema) => schema.required(),
}),
tags: Joi.array().items(Joi.string().max(20)),
isDraft: Joi.boolean().optional(),
};

export type ArticleDocument = Article & Document;
Expand Down Expand Up @@ -78,9 +77,6 @@ export class Article {
@Prop({ default: false, select: false })
isDeleted: boolean;

@Prop({ default: false })
isDraft: boolean;

@Prop([DayReadings])
dayReadings: DayReadings[];
}
Expand Down
6 changes: 0 additions & 6 deletions server/modules/article/article.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Roles } from '../../decorators/roles.decorator';
import { JoiQuery, JoiParam, JoiBody } from '../../decorators/joi.decorator';
import { RolesGuard } from '../../guards/roles.guard';
import Joi, { ObjectIdSchema, StandardPaginationSchema, generateObjectIdsSchema } from '../../joi';
import { auth } from '@blog/server/utils/auth.util';
import { Request } from 'express';
@Controller('/api')
@UseGuards(RolesGuard)
Expand All @@ -31,7 +30,6 @@ export class ArticleController {
cid: Joi.objectId(),
tag: Joi.string().max(20),
title: Joi.string().trim().max(80),
isDraft: Joi.boolean(),
...StandardPaginationSchema,
})
query: {
Expand All @@ -40,12 +38,8 @@ export class ArticleController {
cid: string;
tag: string;
title: string;
isDraft: boolean;
}
) {
if (!auth(req)) {
query.isDraft = false;
}
const { items, totalCount } = await this.articleService.getArticleList(query);
return {
items,
Expand Down
4 changes: 1 addition & 3 deletions server/modules/article/article.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ArticleService {
runValidators: true,
});
if (isEmpty(article)) {
if (this.draftModel.findById(_id)) {
if (await this.draftModel.findById(_id)) {
return await this.create({ _id, ...data });
}
throw new BadRequestException('找不到该文章!');
Expand All @@ -75,7 +75,6 @@ export class ArticleService {
limit?: number;
sort?: object;
title?: string;
isDraft?: boolean;
}) {
const { page = 1, limit = 10, sort = { createdAt: -1 } } = options;
const q = new QueryRules(options, {
Expand All @@ -86,7 +85,6 @@ export class ArticleService {
const query = {
isDeleted: false,
...q,
...(options.isDraft === false ? { isDraft: options.isDraft } : {}),
};
const { items, totalCount } = await this.articleModel.paginate(query, '', {
page,
Expand Down

0 comments on commit 2d83369

Please sign in to comment.