@@ -9,47 +9,15 @@ import * as sk from "sqlkit";
99import { and , desc , eq , like , neq , or } from "sqlkit" ;
1010import { z } from "zod" ;
1111import { Article , User } from "../models/domain-models" ;
12- import { pgClient } from "../persistence/database-drivers/pg.client" ;
1312import { DatabaseTableName } from "../persistence/persistence-contracts" ;
13+ import { persistenceRepository } from "../persistence/persistence-repositories" ;
1414import {
1515 handleRepositoryException ,
1616 RepositoryException ,
1717} from "./RepositoryException" ;
1818import { ArticleRepositoryInput } from "./inputs/article.input" ;
1919import { getSessionUserId } from "./session.actions" ;
2020import { syncTagsWithArticles } from "./tag.action" ;
21- import { persistenceRepository } from "../persistence/persistence-repositories" ;
22-
23- /**
24- * Creates a new article in the database.
25- *
26- * @param _input - The article data to create, validated against ArticleRepositoryInput.createArticleInput schema
27- * @returns Promise<Article> - The newly created article
28- * @throws {RepositoryException } If article creation fails or validation fails
29- */
30- export async function createArticle (
31- _input : z . infer < typeof ArticleRepositoryInput . createArticleInput >
32- ) {
33- try {
34- const input =
35- await ArticleRepositoryInput . createArticleInput . parseAsync ( _input ) ;
36- const article = await persistenceRepository . article . insert ( [
37- {
38- title : input . title ,
39- handle : input . handle ,
40- excerpt : input . excerpt ?? null ,
41- body : input . body ?? null ,
42- cover_image : input . cover_image ?? null ,
43- is_published : input . is_published ?? false ,
44- published_at : input . is_published ? new Date ( ) : null ,
45- author_id : input . author_id ,
46- } ,
47- ] ) ;
48- return article ;
49- } catch ( error ) {
50- handleRepositoryException ( error ) ;
51- }
52- }
5321
5422export async function createMyArticle (
5523 _input : z . infer < typeof ArticleRepositoryInput . createMyArticleInput >
0 commit comments