11 import type { Request, Response } from 'express'
22 import { db } from './db'
3+import { sendEmail } from './email'
4+import { analytics } from './analytics'
46 export async function registerUser(req: Request, res: Response) {
57 const { email, password, name } = req.body
69 const hash = await hashPassword(password)
710 const user = await db.users.create({ email, passwordHash: hash, name })
12+ sendEmail(user.email, 'Welcome!', `Hi ${user.name}`)
13+ analytics.track('user_registered', { userId: user.id })
815 res.json({ success: true, userId: user.id })
1118 export async function hashPassword(password: string): Promise<string> {
19+ // imagine bcrypt here
1220 return 'hash:' + password
23+export async function batchImportUsers(users: { email: string; name: string }[]) {
24+ users.forEach(async (u) => {
25+ const hash = await hashPassword('temp-password')
26+ await db.users.create({ email: u.email, passwordHash: hash, name: u.name })
28+ console.log('Import done')