New: READMEの開発環境の起動にURLの補助を追加 / Fix: 管理者アカウントの作成が出来ない問題 / Fix: setup/create-adminでエラーが発生した際も200を返す問題 / Del: 不要なimport / Chg: 管理者ユーザーはサーバーに1つしか存在しないので"最初の"や"first"という表記を訂正 / Fix: <Textarea>のサイズがおかしい問題
This commit is contained in:
@@ -68,6 +68,8 @@ pnpm i
|
||||
|
||||
# 起動
|
||||
# (バックエンド/フロントエンドどちらもwatchします)
|
||||
# http://localhost:5173 (デフォルトのフロントエンド)にアクセスしてください
|
||||
# 開発環境のhttp://localhost:3300 (デフォルトのバックエンド)にはフロントエンド機能がありません
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
|
||||
@@ -20,8 +20,11 @@ export class UserRepository extends EntityRepository<UserEntity> {
|
||||
async createUser(data: Pick<z.infer<typeof UserRepository.schema>, "userid" | "email" | "password" | "isAdmin"> & {
|
||||
invitationCode?: string;
|
||||
}) {
|
||||
const isThisAdmin = (await this.em.count(UserEntity)) === 0
|
||||
? true
|
||||
: false;
|
||||
const requiredInvitationCode = await this.em.getRepository(ConfigEntity).get("requiredInvitationCode", "true") as string;
|
||||
if (requiredInvitationCode && !data.invitationCode) {
|
||||
if (requiredInvitationCode && !data.invitationCode && !isThisAdmin) {
|
||||
return ErrorBase({
|
||||
bad: "client",
|
||||
code: "invitation_code_invalid",
|
||||
|
||||
@@ -3,7 +3,6 @@ import Logger from "@/lib/logger";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { UserRepository } from "@/modules/repositories/User";
|
||||
import { DatabaseError, ErrorBase, InputError } from "@/errors";
|
||||
import { UniqueConstraintViolationException } from "@mikro-orm/core";
|
||||
|
||||
export default function SetupCreateAdmin(fastify: FastifyInstance) {
|
||||
const logger = new Logger("Endpoint | setup/create-admin");
|
||||
@@ -27,8 +26,8 @@ export default function SetupCreateAdmin(fastify: FastifyInstance) {
|
||||
if (userCount > 0) {
|
||||
return res.code(409).send(ErrorBase({
|
||||
bad: "client",
|
||||
code: "first_admin_already_exists",
|
||||
message: "最初の管理者ユーザーは既に存在します。",
|
||||
code: "admin_already_exists",
|
||||
message: "管理者ユーザーは既に存在します。",
|
||||
}));
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -38,12 +37,16 @@ export default function SetupCreateAdmin(fastify: FastifyInstance) {
|
||||
}
|
||||
|
||||
try {
|
||||
await fastify.orm.em.getRepository(UserEntity).createUser({
|
||||
const error = await fastify.orm.em.getRepository(UserEntity).createUser({
|
||||
...result.data,
|
||||
isAdmin: true,
|
||||
});
|
||||
|
||||
logger.warn("First administrator account has been created.");
|
||||
if (error) {
|
||||
return res.code(400).send(error);
|
||||
}
|
||||
|
||||
logger.warn("Administrator account has been created.");
|
||||
|
||||
return res.code(200).send({
|
||||
success: true,
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
color: var(--text-color);
|
||||
font-size: 1rem;
|
||||
border: 1px solid transparent;
|
||||
width: 100%;
|
||||
max-height: 20rem;
|
||||
box-sizing: border-box;
|
||||
resize: none;
|
||||
outline: none;
|
||||
padding: 0.6rem;
|
||||
border-radius: 0.25rem;
|
||||
|
||||
Reference in New Issue
Block a user