From f26efb61bd2bc7c9b25db34ce4eeb47780c79ddd Mon Sep 17 00:00:00 2001 From: xion Date: Wed, 5 Mar 2025 18:55:55 +0800 Subject: [PATCH] feat: ren js save js --- src/models/user.ts | 8 +++----- src/scripts/user-list.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/scripts/user-list.ts diff --git a/src/models/user.ts b/src/models/user.ts index 684e0c5..f0d0bf3 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -13,6 +13,8 @@ const config = useConfig<{ tokenSecret: string }>(); type UserData = { orgs?: string[]; + wxUnionId?: string; + phone?: string; }; export enum UserTypes { 'user' = 'user', @@ -26,7 +28,6 @@ export class User extends Model { declare id: string; declare username: string; declare nickname: string; // 昵称 - // declare alias: string; // 别名 declare password: string; declare salt: string; declare needChangePassword: boolean; @@ -187,10 +188,7 @@ export const UserInit = async (newSequelize?: any, tableName?: string, sync?: Sy type: DataTypes.TEXT, allowNull: true, }, - // alias: { - // type: DataTypes.TEXT, - // allowNull: true, // 别名,网络请求的别名,需要唯一,不能和username重复 - // }, + password: { type: DataTypes.STRING, allowNull: true, diff --git a/src/scripts/user-list.ts b/src/scripts/user-list.ts new file mode 100644 index 0000000..aa18118 --- /dev/null +++ b/src/scripts/user-list.ts @@ -0,0 +1,33 @@ +import '../modules/init.ts'; +import { User, UserInit } from '../models/user.ts'; +import { Org, OrgInit } from '../models/org.ts'; +import { useContextKey } from '@kevisual/use-config/context'; +const sequelize = useContextKey('sequelize'); + +export const main = async () => { + // await UserInit(null ,null, { + // alter: true, + // }); + await UserInit(); + await OrgInit(); + + const userList = await User.findAll(); + for (const user of userList) { + console.log('user', user.id, user.username, user.data); + } + process.exit(0); + + // const userlist = await User.findAll(); + // for (const user of userlist) { + // // console.log('user', user.id, user.username, user.type, 'alias', user.alias); + // if (user.username.startsWith('o-')) { + // user.data = { + // ...user.data, + // wxUnionId: user.username, + // }; + // await user.save(); + // } + // } + process.exit(0); +}; +main();