cca-blog-module
v0.0.37
Published
Blog module
Readme
CCA Blog Module
This repository contains the Blog module. It is a module only and is integrated into a larger system (no standalone Express server inside this module).
Features
- Create a post (with categories).
- Get a single post.
- Get a paginated list of posts.
- Update a post.
- Delete a post.
Integration (container + controller)
import express from "express";
import { createPostContainer } from "cca-blog-module/dist/infrastructure/container/createPostContainer";
import { BaseDatabase } from "cca-core";
const app = express();
app.use(express.json());
// BaseDatabase instance is provided by the main API
const database = new BaseDatabase(/* ... */);
const { postController } = createPostContainer(database);
app.post("/posts", postController.createPost);
app.get("/posts/:id", postController.getPost);
app.get("/posts", postController.getAllPosts);
app.put("/posts/:id", postController.updatePost);
app.delete("/posts/:id", postController.deletePost);Endpoints
POST /posts
Create a post.
- Body:
title,content,categoryIds(optional), other fields fromPostDTO - Auth:
req.user.idmust be set
GET /posts/:id
Get one post by ID.
- Param:
id
GET /posts
Get paginated posts.
- Query:
page,limit,orderBy,order orderBywhitelist:createdAt,publishedAt,title
PUT /posts/:id
Update a post.
- Param:
id - Auth:
req.user.idmust be set
DELETE /posts/:id
Delete a post.
- Param:
id
Response format
type ApiResponse<T> = {
success: boolean;
message: string;
data?: T;
meta?: {
timestamp: string;
};
};Post DTO (excerpt)
export type PostImageUrlsDTO = {
imageId?: string;
originalUrl?: string;
thumbUrl?: string;
smUrl?: string;
mdUrl?: string;
lgUrl?: string;
xlUrl?: string;
title?: string;
description?: string;
};
export class PostDTO {
id!: string;
title!: string;
slug!: string;
content!: string;
excerpt!: string;
published!: boolean;
publishedAt?: Date;
authorId!: string;
adminAuthorId?: string;
categoryIds?: string[];
imageIds?: string[];
imageUrls?: PostImageUrlsDTO[];
}Validation
Inputs are validated with yup schemas in src/application/validators/postValidation.ts:
- required fields
title,content - unique
slug - category existence checks
Caching
Uses BaseCacheService (in-memory). PostsCacheService provides:
posts:list:*keys for listsposts:detail:*keys for post detailinvalidateAllPostsCachesandinvalidatePostCache
Build / test
pnpm install
pnpm build:tsup
pnpm testTesting
There are no tests in this module yet; pnpm test will fail by design.
Recommended minimal tests:
- PostController create + get (integration)
- GetAllPosts returns
data: []for empty list
Notes
- This module does not provide a logger; use the main API logger in integration.
- API response payloads always wrap the result inside
data.
