优化组织和用户创建逻辑,简化插入数据结构并处理可选描述字段

This commit is contained in:
2026-02-07 02:04:17 +08:00
parent 7dfa96d165
commit 0bd634faf2
9 changed files with 302 additions and 947 deletions

View File

@@ -259,13 +259,19 @@ export class UserSecret {
userId = tokenUser.uid;
orgId = tokenUser.id;
}
const inserted = await db.insert(userSecretsTable).values({
const insertData: Partial<typeof userSecretsTable.$inferInsert> = {
userId,
orgId,
token,
title: tokenUser.title || randomString(6),
expiredTime: UserSecret.getExpiredTime(expireDays).toISOString(),
}).returning();
};
if (orgId !== null && orgId !== undefined) {
insertData.orgId = orgId;
}
const inserted = await db.insert(userSecretsTable).values(insertData).returning();
return new UserSecret(inserted[0]);
}