后端迁移领取基础服务
This commit is contained in:
+11
-3
@@ -3,11 +3,15 @@ import { createClaimToken } from '../../repositories/claim-token-repo.js'
|
||||
import { addHours, nowIso } from '../../utils/time.js'
|
||||
import { randomToken } from '../../utils/random.js'
|
||||
|
||||
export async function createTaskClaimToken(taskId) {
|
||||
type TaskClaimToken = NonNullable<Awaited<ReturnType<typeof createClaimToken>>> & {
|
||||
claimUrl: string
|
||||
}
|
||||
|
||||
export async function createTaskClaimToken(taskId: number | string): Promise<TaskClaimToken> {
|
||||
const createdAt = nowIso()
|
||||
const expiredAt = addHours(createdAt, Number(runtimeConfig.orders.tokenTtlHours || 24))
|
||||
const token = await createClaimToken({
|
||||
taskId,
|
||||
taskId: Number(taskId),
|
||||
token: randomToken(24),
|
||||
status: 'active',
|
||||
expiredAt,
|
||||
@@ -18,13 +22,17 @@ export async function createTaskClaimToken(taskId) {
|
||||
updatedAt: createdAt,
|
||||
})
|
||||
|
||||
if (!token) {
|
||||
throw new Error('领取 token 创建失败')
|
||||
}
|
||||
|
||||
return {
|
||||
...token,
|
||||
claimUrl: buildClaimUrl(token.token),
|
||||
}
|
||||
}
|
||||
|
||||
export function buildClaimUrl(token) {
|
||||
export function buildClaimUrl(token: string): string {
|
||||
const baseUrl = String(runtimeConfig.orders.claimBaseUrl || '').trim()
|
||||
return baseUrl ? `${baseUrl.replace(/\/+$/, '')}/${token}` : token
|
||||
}
|
||||
@@ -305,6 +305,13 @@
|
||||
- `npm run typecheck`
|
||||
- `npm run build`
|
||||
- `npm test` 共 128 个用例通过
|
||||
42. claim 基础服务迁移到 `.ts`:
|
||||
- `src/services/claim/claim-service.ts`
|
||||
43. 领取 token 创建与 claim URL 生成已显式类型化,并在 token 写入失败时显式抛错
|
||||
44. Docker 内验证通过:
|
||||
- `npm run typecheck`
|
||||
- `npm run build`
|
||||
- `npm test` 共 128 个用例通过
|
||||
|
||||
## 下一步建议
|
||||
|
||||
|
||||
Reference in New Issue
Block a user