Skip to content

Commit

Permalink
feat(page)!: record images meta in text
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Jul 19, 2022
1 parent 45add39 commit 4bed5c2
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/modules/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isDefined } from "class-validator";
import { omit } from "lodash";
import { BusinessException } from "~/common/exceptions/business.excpetion";
import { ErrorCodeEnum } from "~/constants/error-code.constant";
import { ImageService } from "~/processors/helper/helper.image.service";

@Injectable()
export class PostService {
Expand All @@ -21,7 +22,9 @@ export class PostService {
private readonly postModel: MongooseModel<PostModel> &
AggregatePaginateModel<PostModel & Document>,
@Inject(forwardRef(() => CategoryService))
private readonly categoryService: CategoryService
private readonly categoryService: CategoryService,

private readonly imageService: ImageService,
) {}
get model() {
return this.postModel;
Expand Down Expand Up @@ -53,6 +56,11 @@ export class PostService {
created: new Date(),
modified: null,
});
process.nextTick(async () => { // 异步更新缓存
await Promise.all([
this.imageService.recordImageMeta(this.model as MongooseModel<PostModel>, res._id)
])
})
return res;
}

Expand Down Expand Up @@ -96,7 +104,13 @@ export class PostService {
}
Object.assign(originDocument, omit(data, PostModel.protectedKeys));
await originDocument.save();


process.nextTick(async () => {
await Promise.all([
this.imageService.recordImageMeta(this.model as MongooseModel<PostModel>, id)
])
})

return originDocument.toObject();
}

Expand Down

0 comments on commit 4bed5c2

Please sign in to comment.