feat(core-cms): compose @repo/blog/cms into payload config
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import "reflect-metadata";
|
||||
import { injectable } from "inversify";
|
||||
import { getPayload } from "payload";
|
||||
import type { SanitizedConfig } from "payload";
|
||||
|
||||
import config from "@repo/core-cms";
|
||||
import type { IArticlesRepository } from "@/application/repositories/articles-repository.interface";
|
||||
import type { Article } from "@/entities/article";
|
||||
|
||||
@@ -38,8 +38,14 @@ function mapDoc(doc: PayloadArticleDoc): Article {
|
||||
|
||||
@injectable()
|
||||
export class PayloadArticlesRepository implements IArticlesRepository {
|
||||
private config: SanitizedConfig;
|
||||
|
||||
constructor(config: SanitizedConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
async getArticle(id: string): Promise<Article | undefined> {
|
||||
const payload = await getPayload({ config });
|
||||
const payload = await getPayload({ config: this.config });
|
||||
try {
|
||||
const doc = await payload.findByID({
|
||||
collection: "articles",
|
||||
@@ -53,7 +59,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
||||
}
|
||||
|
||||
async getArticleBySlug(slug: string): Promise<Article | undefined> {
|
||||
const payload = await getPayload({ config });
|
||||
const payload = await getPayload({ config: this.config });
|
||||
const result = await payload.find({
|
||||
collection: "articles",
|
||||
where: { slug: { equals: slug } },
|
||||
@@ -70,7 +76,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}): Promise<Article[]> {
|
||||
const payload = await getPayload({ config });
|
||||
const payload = await getPayload({ config: this.config });
|
||||
const where: Record<string, { equals: string }> = {};
|
||||
if (options?.status) where.status = { equals: options.status };
|
||||
if (options?.authorId) where.author = { equals: options.authorId };
|
||||
@@ -88,7 +94,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
||||
}
|
||||
|
||||
async createArticle(input: Article): Promise<Article> {
|
||||
const payload = await getPayload({ config });
|
||||
const payload = await getPayload({ config: this.config });
|
||||
const created = await payload.create({
|
||||
collection: "articles",
|
||||
data: {
|
||||
@@ -107,7 +113,7 @@ export class PayloadArticlesRepository implements IArticlesRepository {
|
||||
id: string,
|
||||
input: Partial<Article>,
|
||||
): Promise<Article | undefined> {
|
||||
const payload = await getPayload({ config });
|
||||
const payload = await getPayload({ config: this.config });
|
||||
try {
|
||||
const updated = await payload.update({
|
||||
collection: "articles",
|
||||
|
||||
Reference in New Issue
Block a user