Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions backend/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Config } from "drizzle-kit"
import env from "env-var"
import type { Config } from 'drizzle-kit'
import env from 'env-var'

const DATABASE_URL = env.get("DATABASE_URL").required().asString()
const DATABASE_URL = env.get('DATABASE_URL').required().asString()

export default {
schema: "./src/db/schema",
out: "./drizzle",
dialect: "postgresql",
casing: "snake_case",
schema: './src/db/schema',
out: './drizzle',
dialect: 'postgresql',
casing: 'snake_case',
dbCredentials: {
url: DATABASE_URL,
},
Expand Down
30 changes: 30 additions & 0 deletions backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import antfu from '@antfu/eslint-config'

export default antfu(
{
stylistic: {
indent: 2,
quotes: 'single',
},
},
{
files: ['**/*.js', '**/*.ts'],
rules: {
'node/prefer-global/process': 'off',
'no-console': 'off',
'antfu/no-top-level-await': 'off',
'antfu/consistent-chaining': 'error', // Explicitly set the rule
// Or potentially use the stylistic rule if it's managed there
'antfu/top-level-function': 'off',
// "style/newlice-per-chained-call": ["error", { ignoreChainWithDepth: 2 }],
'style/object-curly-newline': [
'error',
{
ImportDeclaration: { multiline: true, minProperties: 3 },
ExportDeclaration: { multiline: true, minProperties: 3 },
},
],
},
plugins: {},
},
)
31 changes: 0 additions & 31 deletions backend/eslint.config.mjs

This file was deleted.

4 changes: 4 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
"prepare": "husky"
},
"dependencies": {
"elysia": "^1.4.22",
"@bogeychan/elysia-logger": "^0.1.10",
"@elysiajs/cors": "^1.4.1",
"@elysiajs/openapi": "^1.4.14",
"@elysiajs/server-timing": "^1.4.0",
"@typescript-eslint/eslint-plugin": "^8.54.0",
"@typescript-eslint/parser": "^8.54.0",
"better-auth": "^1.4.17",
"cloudinary": "^2.9.0",
"drizzle-orm": "^0.45.1",
"drizzle-zod": "^0.8.3",
"env-var": "^7.5.0",
"ioredis": "^5.9.2",
"isomorphic-dompurify": "2.16.0",
"nanoid": "^5.1.6",
"postgres": "^3.4.8",
"uuid": "^13.0.0",
Expand Down
22 changes: 11 additions & 11 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import env from "env-var"
import env from 'env-var'

export const config = {
NODE_ENV: env
.get("NODE_ENV")
.default("development")
.asEnum(["production", "test", "development"]),
.get('NODE_ENV')
.default('development')
.asEnum(['production', 'test', 'development']),

PORT: env.get("PORT").default(3000).asPortNumber(),
DATABASE_URL: env.get("DATABASE_URL").required().asString(),
REDIS_HOST: env.get("REDIS_HOST").default("localhost").asString(),
GITHUB_CLIENT_ID: env.get("GITHUB_CLIENT_ID").required().asString(),
GITHUB_CLIENT_SECRET: env.get("GITHUB_CLIENT_SECRET").required().asString(),
UI_CLIENT_URL: env.get("UI_CLIENT_URL").required().asString(),
CLOUDINARY_URL: env.get("CLOUDINARY_URL").required().asString(),
PORT: env.get('PORT').default(3000).asPortNumber(),
DATABASE_URL: env.get('DATABASE_URL').required().asString(),
REDIS_HOST: env.get('REDIS_HOST').default('localhost').asString(),
GITHUB_CLIENT_ID: env.get('GITHUB_CLIENT_ID').required().asString(),
GITHUB_CLIENT_SECRET: env.get('GITHUB_CLIENT_SECRET').required().asString(),
UI_CLIENT_URL: env.get('UI_CLIENT_URL').required().asString(),
CLOUDINARY_URL: env.get('CLOUDINARY_URL').required().asString(),
}
22 changes: 12 additions & 10 deletions backend/src/controllers/article.controller.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
import { authMiddleware } from "@backend/middlewares/auth.middleware.ts"
import { authMiddleware } from '@backend/middlewares/auth.middleware.ts'
import {
CreatePost,
DeletePost,
GetPostBySlug,
GetPosts,
UpdatePost,
} from "@backend/services/article.service.ts"
} from '@backend/services/article.service.ts'
import {
CreatePostBody,
GetPostsQuery,
UpdatePostBody,
} from "@backend/shared/article.model.ts"
import { Elysia } from "elysia"
} from '@backend/shared/article.model.ts'
import { Elysia } from 'elysia'

export const articleController = new Elysia({ prefix: "/article" })
export const articleController = new Elysia({ prefix: '/article' })
.use(authMiddleware)
.post(
"/",
'/',
async ({ body, user }) => await CreatePost(body, user),
{
body: CreatePostBody,
isAuth: true,
},
)
.get("/", async ({ query }) => await GetPosts(query), {
.get('/', async ({ query }) => await GetPosts(query), {
query: GetPostsQuery,
})
.get("/:slug", async ({ params: { slug } }) => await GetPostBySlug(slug))
.get('/:slug', async ({ params: { slug }, user }) => await GetPostBySlug(slug, user), {
isAuthOptional: true,
})
.put(
"/:id",
'/id/:id',
async ({ params: { id }, body, user }) => await UpdatePost(id, body, user),
{
body: UpdatePostBody,
isAuth: true,
},
)
.delete(
"/:id",
'/id/:id',
async ({ params: { id }, user }) => await DeletePost(id, user),
{
isAuth: true,
Expand Down
18 changes: 9 additions & 9 deletions backend/src/controllers/comment.controller.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { authMiddleware } from "@backend/middlewares/auth.middleware.ts"
import { authMiddleware } from '@backend/middlewares/auth.middleware.ts'
import {
CreateComment,
DeleteComment,
GetComments,
UpdateComment,
} from "@backend/services/comment.service.ts"
} from '@backend/services/comment.service.ts'
import {
CreateCommentBody,
GetCommentsQuery,
UpdateCommentBody,
} from "@backend/shared/comment.model.ts"
import { Elysia } from "elysia"
} from '@backend/shared/comment.model.ts'
import { Elysia } from 'elysia'

export const commentController = new Elysia({ prefix: "/comments" })
export const commentController = new Elysia({ prefix: '/comments' })
.use(authMiddleware)
.post("/", async ({ body, user }) => {
.post('/', async ({ body, user }) => {
return await CreateComment(body, user)
}, {
body: CreateCommentBody,
isAuth: true,
})
.get("/:articleId", async ({ params: { articleId }, query }) => {
.get('/:articleId', async ({ params: { articleId }, query }) => {
return await GetComments(articleId, query)
}, {
query: GetCommentsQuery,
})
.patch("/:id", async ({ params: { id }, body, user }) => {
.patch('/:id', async ({ params: { id }, body, user }) => {
return await UpdateComment(id, body, user)
}, {
body: UpdateCommentBody,
isAuth: true,
})
.delete("/:id", async ({ params: { id }, user }) => {
.delete('/:id', async ({ params: { id }, user }) => {
return await DeleteComment(id, user)
}, {
isAuth: true,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/controllers/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpError, SetupOnErorr } from "@backend/services/error.service.ts"
import { Elysia } from "elysia"
import { HttpError, SetupOnErorr } from '@backend/services/error.service.ts'
import { Elysia } from 'elysia'

// Base controller with error handling - for reference only
// Controllers now directly use authMiddleware
Expand All @@ -9,7 +9,7 @@ export const baseErrorHandler = new Elysia()
})
.onError(({ error, set, code }) => {
switch (code) {
case "HttpError":
case 'HttpError':
return SetupOnErorr(error, set)
}
})
12 changes: 6 additions & 6 deletions backend/src/controllers/like.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { authMiddleware } from "@backend/middlewares/auth.middleware.ts"
import { ToggleLike } from "@backend/services/like.service.ts"
import { ToggleLikeBody } from "@backend/shared/like.model.ts"
import { Elysia } from "elysia"
import { authMiddleware } from '@backend/middlewares/auth.middleware.ts'
import { ToggleLike } from '@backend/services/like.service.ts'
import { ToggleLikeBody } from '@backend/shared/like.model.ts'
import { Elysia } from 'elysia'

export const likeController = new Elysia({ prefix: "/like" })
export const likeController = new Elysia({ prefix: '/like' })
.use(authMiddleware)
.post(
"/",
'/',
async ({ body, user }) => await ToggleLike(body, user),
{
body: ToggleLikeBody,
Expand Down
12 changes: 6 additions & 6 deletions backend/src/controllers/upload.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { authMiddleware } from "@backend/middlewares/auth.middleware.ts"
import { ImageUploadService } from "@backend/services/upload.service.ts"
import { UploadBody } from "@backend/shared/models.ts"
import { Elysia } from "elysia"
import { z } from "zod"
import { authMiddleware } from '@backend/middlewares/auth.middleware.ts'
import { ImageUploadService } from '@backend/services/upload.service.ts'
import { UploadBody } from '@backend/shared/models.ts'
import { Elysia } from 'elysia'
import { z } from 'zod'

export const uploadController = new Elysia()
.use(authMiddleware)
.post(
"/upload",
'/upload',
async ({ body: { file } }) => await ImageUploadService(file as File),
{
body: UploadBody,
Expand Down
10 changes: 5 additions & 5 deletions backend/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { config } from "@backend/config.ts"
import * as schema from "@backend/db/schema/index.ts"
import { drizzle } from "drizzle-orm/postgres-js"
import postgres from "postgres"
import { config } from '@backend/config.ts'
import * as schema from '@backend/db/schema/index.ts'
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

const client = postgres(config.DATABASE_URL)
export const db = drizzle({
client,
schema,
casing: "snake_case",
casing: 'snake_case',
})
52 changes: 26 additions & 26 deletions backend/src/db/schema/article.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
import { relations } from "drizzle-orm"
import { relations } from 'drizzle-orm'
import {
index,
pgTable,
text,
uniqueIndex,
} from "drizzle-orm/pg-core"
import { user } from "./auth.ts"
import { baseColumns } from "./base.ts"
} from 'drizzle-orm/pg-core'
import { user } from './auth.ts'
import { baseColumns } from './base.ts'

export const article = pgTable("article", {
export const article = pgTable('article', {
...baseColumns,
title: text("title").notNull(),
preview_image: text("preview_image").notNull(),
preview_text: text("preview_text").notNull(),
content: text("content").notNull(),
slug: text("slug").notNull().unique(),
tags: text("tags").array().notNull().default([]),
author_id: text("author_id")
title: text('title').notNull(),
preview_image: text('preview_image').notNull(),
preview_text: text('preview_text').notNull(),
content: text('content').notNull(),
slug: text('slug').notNull().unique(),
tags: text('tags').array().notNull().default([]),
author_id: text('author_id')
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
.references(() => user.id, { onDelete: 'cascade' }),
})

export const comment = pgTable("comment", {
export const comment = pgTable('comment', {
...baseColumns,
content: text("content").notNull(),
author_id: text("author_id")
content: text('content').notNull(),
author_id: text('author_id')
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
article_id: text("article_id")
.references(() => user.id, { onDelete: 'cascade' }),
article_id: text('article_id')
.notNull()
.references(() => article.id, { onDelete: "cascade" }),
.references(() => article.id, { onDelete: 'cascade' }),
})

export const like = pgTable(
"like",
'like',
{
...baseColumns,
liker_id: text("author_id")
liker_id: text('author_id')
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
article_id: text("article_id")
.references(() => user.id, { onDelete: 'cascade' }),
article_id: text('article_id')
.notNull()
.references(() => article.id, { onDelete: "cascade" }),
.references(() => article.id, { onDelete: 'cascade' }),
},

t => [
uniqueIndex("unique_like").on(t.article_id, t.liker_id),
index("article_id_idx").on(t.article_id),
uniqueIndex('unique_like').on(t.article_id, t.liker_id),
index('article_id_idx').on(t.article_id),
],
)

Expand Down
Loading