Chg: トークンの入力形式をBearerに変更 / Feat: ユニークなIDを生成する関数を作成 / Feat: userテーブルにプロフィールを作成 / Chg: ユーザー作成でのユーザー名を任意に変更 / Fix: meエンドポイントで成功時にもsuccessをレスポンスに含める / Fix: signupエンドポイントで入力が重複したときにデータベースエラーではなく入力エラーとしてレスポンス / Fix: setup/initializationエンドポイントでデータベースエラーが出る問題を修正 / Fix: L.jsの型を実際の値に更新
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Entity, EntityRepositoryType, OptionalProps, PrimaryKey, Property } from "@mikro-orm/core";
|
||||
import { UserRepository } from "@/modules/repositories/User";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import generateUniqueId from "@/lib/id";
|
||||
|
||||
@Entity({
|
||||
tableName: "user",
|
||||
@@ -8,13 +8,14 @@ import { v4 as uuid } from "uuid";
|
||||
})
|
||||
export class UserEntity {
|
||||
[EntityRepositoryType]?: UserRepository;
|
||||
[OptionalProps]?: "uuid" | "isSuspended" | "createdAt";
|
||||
[OptionalProps]?: "profile" | "isSuspended" | "createdAt";
|
||||
|
||||
@PrimaryKey({
|
||||
type: "string",
|
||||
length: 36
|
||||
length: 10,
|
||||
onCreate: () => generateUniqueId(),
|
||||
})
|
||||
uuid: string = uuid();
|
||||
id!: string;
|
||||
|
||||
@Property({
|
||||
type: "string",
|
||||
@@ -29,6 +30,13 @@ export class UserEntity {
|
||||
})
|
||||
username!: string;
|
||||
|
||||
@Property({
|
||||
type: "string",
|
||||
length: 4096,
|
||||
default: "",
|
||||
})
|
||||
profile!: string;
|
||||
|
||||
@Property({
|
||||
type: "string",
|
||||
unique: true,
|
||||
@@ -52,7 +60,7 @@ export class UserEntity {
|
||||
isSuspended: boolean = false;
|
||||
|
||||
@Property({
|
||||
type: "date",
|
||||
type: "datetime",
|
||||
onCreate: () => new Date(),
|
||||
})
|
||||
createdAt!: Date;
|
||||
|
||||
@@ -8,12 +8,13 @@ export class UserRepository extends EntityRepository<UserEntity> {
|
||||
public static schema = z.object({
|
||||
userid: z.string().trim().min(3).max(20),
|
||||
username: z.string().trim().min(3).max(30),
|
||||
profile: z.string().max(4096).optional(),
|
||||
email: z.string().min(6).trim().max(254).regex(EmailRegex),
|
||||
password: z.string().trim().min(8),
|
||||
isAdmin: z.boolean(),
|
||||
});
|
||||
|
||||
async createUser(data: z.infer<typeof UserRepository.schema>) {
|
||||
async createUser(data: Pick<z.infer<typeof UserRepository.schema>, "userid" | "email" | "password" | "isAdmin">) {
|
||||
const hashed = await hash(data.password, {
|
||||
type: argon2id,
|
||||
memoryCost: 2 ** 16,
|
||||
@@ -23,6 +24,7 @@ export class UserRepository extends EntityRepository<UserEntity> {
|
||||
|
||||
const user = this.create({
|
||||
...data,
|
||||
username: data.userid,
|
||||
password: hashed,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user