1 import { server } from '../../lib/server';
2 import { Static, Type } from '@sinclair/typebox';
3 import { prisma } from '../../lib/db';
4 import { BadInputError } from '../../lib/http-errors';
5 import { random } from 'lodash';
6 import { maxHp, maxStamina } from '../../formulas';
7 import {Biome, Player} from '@prisma/client';
9 const AccountInput = Type.Object({
11 username: Type.String(),
12 password: Type.String(),
13 confirmation: Type.String()
17 type AccountInputType = Static<typeof AccountInput>
19 export type AccountCreateType = {
27 export const createAccount = server.post<AccountInputType, AccountCreateType>('/v1/accounts', {
30 const {username, password, confirmation} = req.body;
32 if(username.length < 3) {
33 throw new BadInputError('Username must be at least 3 characters');
36 if(password !== confirmation) {
37 throw new BadInputError('Password and confirmation did not match');
40 // we should get the default zone that the player will be in!
58 data.hp = maxHp(1, data.zest);
59 data.stamina = maxStamina(1, data.woosh);
61 // create a new biome for this player!
62 const biome = await prisma.zoneBiomes.create({
69 data.zoneBiomeId = biome.id;
71 const player = await prisma.player.create({ data });