feat(F-071): completed feature
This commit is contained in:
@@ -42,6 +42,8 @@ const newCategorySchema = z.object({
|
||||
seoTitle: z.string().min(1).max(200).optional().nullable(),
|
||||
seoDescription: z.string().min(1).max(500).optional().nullable(),
|
||||
isParent: z.boolean().optional(),
|
||||
emoji: z.string().max(10).optional().nullable(),
|
||||
color: z.string().max(200).optional().nullable(),
|
||||
});
|
||||
|
||||
const categoryPatchSchema = newCategorySchema
|
||||
@@ -182,6 +184,8 @@ function serializeCategory(category: Category) {
|
||||
seoTitle: category.seoTitle,
|
||||
seoDescription: category.seoDescription,
|
||||
isParent: category.isParent,
|
||||
emoji: category.emoji,
|
||||
color: category.color,
|
||||
createdAt: category.createdAt.toISOString(),
|
||||
updatedAt: category.updatedAt.toISOString(),
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@ export interface Category {
|
||||
seoDescription: string | null;
|
||||
/** FIX-19: true = contenedor (puede tener hijos); false = hoja (child). */
|
||||
isParent: boolean;
|
||||
emoji?: string | null;
|
||||
color?: string | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -21,6 +23,8 @@ export interface NewCategory {
|
||||
seoTitle?: string | null;
|
||||
seoDescription?: string | null;
|
||||
isParent?: boolean;
|
||||
emoji?: string | null;
|
||||
color?: string | null;
|
||||
}
|
||||
|
||||
/** Fields a category update may set. Undefined = leave unchanged; parentId null = move to root. */
|
||||
|
||||
@@ -11,6 +11,8 @@ interface CategoryRow {
|
||||
seo_title: string | null;
|
||||
seo_description: string | null;
|
||||
is_parent: boolean;
|
||||
emoji: string | null;
|
||||
color: string | null;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
@@ -24,6 +26,8 @@ const UPDATABLE: ReadonlyArray<[keyof CategoryPatch, string]> = [
|
||||
['seoTitle', 'seo_title'],
|
||||
['seoDescription', 'seo_description'],
|
||||
['isParent', 'is_parent'],
|
||||
['emoji', 'emoji'],
|
||||
['color', 'color'],
|
||||
];
|
||||
|
||||
export class PgCategoryRepository implements CategoryRepository {
|
||||
@@ -57,8 +61,8 @@ export class PgCategoryRepository implements CategoryRepository {
|
||||
async create(input: NewCategory): Promise<Category> {
|
||||
try {
|
||||
const result = await this.pool.query<CategoryRow>(
|
||||
`INSERT INTO categories_categories (parent_id, name, slug, seo_title, seo_description, is_parent)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`INSERT INTO categories_categories (parent_id, name, slug, seo_title, seo_description, is_parent, emoji, color)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING *`,
|
||||
[
|
||||
input.parentId ?? null,
|
||||
@@ -67,6 +71,8 @@ export class PgCategoryRepository implements CategoryRepository {
|
||||
input.seoTitle ?? null,
|
||||
input.seoDescription ?? null,
|
||||
input.isParent ?? false,
|
||||
input.emoji ?? null,
|
||||
input.color ?? null,
|
||||
],
|
||||
);
|
||||
const row = result.rows[0];
|
||||
@@ -150,6 +156,8 @@ function toCategory(row: CategoryRow): Category {
|
||||
seoTitle: row.seo_title,
|
||||
seoDescription: row.seo_description,
|
||||
isParent: row.is_parent,
|
||||
emoji: row.emoji,
|
||||
color: row.color,
|
||||
createdAt: row.created_at,
|
||||
updatedAt: row.updated_at,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user