Feat: #10 サインアップ / Chg: server-infoでconfigの取得にconfigRepo.get()を使うように / Fix: アカウントが無効でもコミュニティを作成ボタンがある問題
This commit is contained in:
@@ -3,6 +3,8 @@ import Logger from "@/lib/logger";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { UserRepository } from "@/modules/repositories/User";
|
||||
import { DatabaseError, InputError } from "@/errors";
|
||||
import { ConfigEntity } from "@/modules/entities/Config";
|
||||
import z, { ZodObject } from "zod/v3";
|
||||
|
||||
export default function PrimarySignUp(fastify: FastifyInstance) {
|
||||
const logger = new Logger("Endpoint | primary/signup");
|
||||
@@ -10,23 +12,38 @@ export default function PrimarySignUp(fastify: FastifyInstance) {
|
||||
fastify.post("/", async (req, res) => {
|
||||
res.header("Content-Type", "application/json");
|
||||
|
||||
const result = UserRepository.schema.pick({
|
||||
userid: true,
|
||||
email: true,
|
||||
password: true,
|
||||
}).safeParse(req.body);
|
||||
|
||||
if (!result.success) {
|
||||
console.log(result.error.issues)
|
||||
return res.code(400).send(InputError(result.error.issues));
|
||||
}
|
||||
|
||||
try {
|
||||
await fastify.orm.em.getRepository(UserEntity).createUser({
|
||||
...result.data,
|
||||
const requiredInvitationCode = await fastify.orm.em.getRepository(ConfigEntity).get("requiredInvitationCode", "true") as string;
|
||||
|
||||
let reqInvCodeSchema: ZodObject<any>;
|
||||
if (requiredInvitationCode !== "true") {
|
||||
reqInvCodeSchema = z.object({});
|
||||
} else {
|
||||
reqInvCodeSchema = z.object({
|
||||
invitationCode: z.string().trim().min(1),
|
||||
});
|
||||
}
|
||||
|
||||
const result = UserRepository.schema.pick({
|
||||
userid: true,
|
||||
email: true,
|
||||
password: true,
|
||||
}).merge(reqInvCodeSchema).safeParse(req.body);
|
||||
|
||||
if (!result.success) {
|
||||
console.log(result.error.issues)
|
||||
return res.code(400).send(InputError(result.error.issues));
|
||||
}
|
||||
|
||||
const error = await fastify.orm.em.getRepository(UserEntity).createUser({
|
||||
...(result.data as any),
|
||||
isAdmin: false,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return res.code(400).send(error);
|
||||
}
|
||||
|
||||
return res.code(200).send({
|
||||
success: true,
|
||||
});
|
||||
|
||||
@@ -15,15 +15,15 @@ export default async function ServerInfo(fastify: FastifyInstance) {
|
||||
const configCount = await configRepo.count();
|
||||
const userCount = await userRepo.count();
|
||||
|
||||
const serverName = await configRepo.findOne({ name: "name" });
|
||||
const serverDescription = await configRepo.findOne({ name: "description" });
|
||||
const serverIcon = await configRepo.findOne({ name: "icon" });
|
||||
const serverName = await configRepo.get("name");
|
||||
const serverDescription = await configRepo.get("description");
|
||||
const serverIcon = await configRepo.get("icon");
|
||||
|
||||
return res.send({
|
||||
success: true,
|
||||
name: serverName?.value ?? null,
|
||||
description: serverDescription?.value ?? null,
|
||||
icon: serverIcon?.value ?? null,
|
||||
name: serverName ?? null,
|
||||
description: serverDescription ?? null,
|
||||
icon: serverIcon ?? null,
|
||||
isInitialized: configCount > 0,
|
||||
isFirstAdminExists: userCount > 0,
|
||||
userCount,
|
||||
|
||||
Reference in New Issue
Block a user