// ① バリデーション const { email, password, age } = req.body; if (!email || password.length < 8) { return res.status(400).json({ message: 'Invalid input' }); } // ④ DB アクセス ( 存在確認) const existingUser = await prisma.user.findUnique({ where: { email } }); if (existingUser) { return res.status(409).json({ message: 'Email exists' }); } // ③ ビジネスロジック const hashedPassword = await bcrypt.hash(password, 10); let initialPoints = 50; if (age < 25) { initialPoints = 100; // キャンペーン適用! } // ... ( さらに複雑なロジックが続く) ... // ④ DB アクセス ( 作成) const newUser = await prisma.user.create({ data: { email, password: hashedPassword, points: initialPoints }, }); // ⑤ 外部連携 ( 副作用) await sendWelcomeEmail(newUser.email); // ① レスポンス res.status(201).json(newUser); }); 2025/10/23 | BuiLT 7