Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- AlterTable
ALTER TABLE "application" ALTER COLUMN "created_at" SET DATA TYPE BIGINT,
ALTER COLUMN "updated_at" SET DATA TYPE BIGINT;

-- AlterTable
ALTER TABLE "position" ALTER COLUMN "deadline" SET DATA TYPE BIGINT,
ALTER COLUMN "created_at" SET DATA TYPE BIGINT,
ALTER COLUMN "updated_at" SET DATA TYPE BIGINT;

-- AlterTable
ALTER TABLE "user" ALTER COLUMN "created_at" SET DATA TYPE BIGINT,
ALTER COLUMN "updated_at" SET DATA TYPE BIGINT;
15 changes: 8 additions & 7 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// recruit-server 数据模型
// Node 侧驼峰, PostgreSQL 侧下划线, 通过 @map / @@map 映射
// 枚举英文标识与 @qnxg-recruit/shared 的 enums 保持一致
// 时间字段用 BigInt 存入毫秒级时间戳, 默认 Int -> INT4 会溢出, 契约与转换见 utils/time.ts 约定

generator client {
provider = "prisma-client-js"
Expand Down Expand Up @@ -40,8 +41,8 @@ model User {

// 简历 / 个人描述字段待业务补充

createdAt Int @map("created_at")
updatedAt Int @map("updated_at")
createdAt BigInt @map("created_at")
updatedAt BigInt @map("updated_at")
applications Application[]
admin Admin?

Expand All @@ -63,14 +64,14 @@ model Position {
title String
description String
/// 展示用招聘截止日期 (原 expiredAt 改名)
deadline Int
deadline BigInt
hot Boolean @default(false)
status PositionStatus @default(recruiting)
/// 软删除标记
disabled Boolean @default(false)

createdAt Int @map("created_at")
updatedAt Int @map("updated_at")
createdAt BigInt @map("created_at")
updatedAt BigInt @map("updated_at")
applications Application[]

@@map("position")
Expand All @@ -85,8 +86,8 @@ model Application {
/// 软删除标记
disabled Boolean @default(false)

createdAt Int @map("created_at")
updatedAt Int @map("updated_at")
createdAt BigInt @map("created_at")
updatedAt BigInt @map("updated_at")

user User @relation(fields: [userID], references: [id])
position Position @relation(fields: [positionID], references: [id])
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export const authService = {
if (!user)
throw new TRPCError({ code: "UNAUTHORIZED", message: "用户不存在" })
const isAdmin = await adminRepo.isAdmin(userID)
return { ...toUserDto(user), isAdmin, createdAt: user.createdAt }
return { ...toUserDto(user), isAdmin, createdAt: Number(user.createdAt) }
},
}
12 changes: 6 additions & 6 deletions server/src/utils/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { ApplicationDto, PositionDto, UserDto } from "@qnxg-recruit/shared"
import type { ApplicationWithRelations } from "@/repos/application"

/**
* Prisma 实体 → 对外 DTO 的映射. 移除内部字段 (外键 / 软删标记),
* 时间已是 ms 时间戳 (Int), 直接透传
* Prisma 实体 → 对外 DTO 的映射. 移除内部字段 (外键 / 软删标记).
* 时间字段 Prisma 返回 bigint, 按时间约定 (见 utils/time) 转回 number 毫秒
*/

export function toUserDto(user: User): UserDto {
Expand All @@ -20,8 +20,8 @@ export function toPositionDto(position: Position): PositionDto {
id: position.id,
title: position.title,
description: position.description,
createdAt: position.createdAt,
deadline: position.deadline,
createdAt: Number(position.createdAt),
deadline: Number(position.deadline),
hot: position.hot,
status: position.status,
}
Expand All @@ -31,8 +31,8 @@ export function toApplicationDto(app: ApplicationWithRelations): ApplicationDto
return {
id: app.id,
status: app.status,
createdAt: app.createdAt,
updatedAt: app.updatedAt,
createdAt: Number(app.createdAt),
updatedAt: Number(app.updatedAt),
user: toUserDto(app.user),
position: toPositionDto(app.position),
}
Expand Down
9 changes: 7 additions & 2 deletions server/src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/**
* 时间约定: 对外 / DTO 用毫秒级 Unix 时间戳 (number), DB 也存 Int (ms).
* 集中在此转换, 便于日后若改回 DateTime 只动一处
* 时间约定: 对外 / DTO 统一毫秒级 Unix 时间戳 (number), DB 存 BigInt (ms).
*
* DTO 选 number 而非 bigint 的理由:
* - 前端 `new Date(ms)` 直接按本地时区展示, 不涉 UTC 转换
* - bigint 无法被 JSON 序列化 (trpc 走默认 JSON, 无 superjson)
* - 毫秒量级远小于 number 安全上限 2^53, 精度无损
* 因此 Prisma 实体返回的 bigint 在 mapper 层 `Number()` 转回, 见 utils/mappers.
*/

/**
Expand Down
Loading