Skip to content
/ core Public

Commit 71f4f91

Browse files
committed
fix(category): handle null category in category service
- Added a null check for the category in the CategoryService to return null if the category is not found. - Updated PostService to use category._id or category.id for categoryId assignment when creating a new post. - Imported extractDocumentContext in lexical-translation-parser tests for improved utility access. Signed-off-by: Innei <[email protected]>
1 parent e7c068c commit 71f4f91

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

apps/core/src/modules/category/category.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Injectable, OnApplicationBootstrap } from '@nestjs/common'
22
import { ModuleRef } from '@nestjs/core'
33
import type { DocumentType, ReturnModelType } from '@typegoose/typegoose'
4+
import { omit } from 'es-toolkit/compat'
5+
import type { QueryFilter } from 'mongoose'
6+
47
import { BizException } from '~/common/exceptions/biz.exception'
58
import { CannotFindException } from '~/common/exceptions/cant-find.exception'
69
import { NoContentCanBeModifiedException } from '~/common/exceptions/no-content-canbe-modified.exception'
@@ -12,8 +15,7 @@ import { POST_SERVICE_TOKEN } from '~/constants/injection.constant'
1215
import { EventManagerService } from '~/processors/helper/helper.event.service'
1316
import { InjectModel } from '~/transformers/model.transformer'
1417
import { scheduleManager } from '~/utils/schedule.util'
15-
import { omit } from 'es-toolkit/compat'
16-
import type { QueryFilter } from 'mongoose'
18+
1719
import type { PostModel } from '../post/post.model'
1820
import type { PostService } from '../post/post.service'
1921
import { SlugTrackerService } from '../slug-tracker/slug-tracker.service'
@@ -42,6 +44,9 @@ export class CategoryService implements OnApplicationBootstrap {
4244
this.model.findById(categoryId).lean(),
4345
this.postService.model.countDocuments({ categoryId }),
4446
])
47+
if (!category) {
48+
return null
49+
}
4550
return {
4651
...category,
4752
count,

apps/core/src/modules/post/post.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Injectable, OnApplicationBootstrap } from '@nestjs/common'
22
import { ModuleRef } from '@nestjs/core'
33
import { debounce, omit } from 'es-toolkit/compat'
44
import type { AggregatePaginateModel, Document } from 'mongoose'
5-
import { Types } from 'mongoose'
65
import slugify from 'slugify'
76

87
import {
@@ -92,7 +91,7 @@ export class PostService implements OnApplicationBootstrap {
9291
const newPost = await this.postModel.create({
9392
...post,
9493
slug,
95-
categoryId: new Types.ObjectId(String(categoryId)),
94+
categoryId: category._id ?? category.id,
9695
created: getLessThanNow(post.created),
9796
modified: null,
9897
meta: post.meta

apps/core/test/src/modules/ai/lexical-translation-parser.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { describe, expect, it } from 'vitest'
22

33
import {
4-
extractDocumentContext,
54
parseLexicalForTranslation,
65
restoreLexicalTranslation,
76
} from '~/modules/ai/ai-translation/lexical-translation-parser'
7+
import { extractDocumentContext } from '~/utils/content.util'
88

99
const makeEditorState = (children: any[]) =>
1010
JSON.stringify({ root: { children, type: 'root', direction: 'ltr' } })

0 commit comments

Comments
 (0)