X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Fapi.ts;h=5f48de443d383b76ec6375fd80d9ef63f0088a08;hb=6e2f57a73eb2fa9a58d4304d13a688d9635b0ebd;hp=e5e155758823d74a42fdd6275c768254ccaf6714;hpb=eec9780142ca4cc052d9575528d6dc6f3bfc4fe6;p=browser-rts.git diff --git a/src/api.ts b/src/api.ts index e5e1557..5f48de4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -47,7 +47,7 @@ server.post<{ // lets create the city! await cityRepo.create(acct.id); - return `

You are all signed up! You can go ahead and log in

`; + return `
You are all signed up! You can go ahead and log in
`; }); server.post<{body: {username: string, password: string}}, void>('/login', async (req, raw, res) => { @@ -79,8 +79,8 @@ server.post<{body: { server.get<{params: { cityId: string }}, string>('/city/:cityId', async req => { const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token); - const yourCity = await cityRepo.FindOne({ owner: account.id }); - const city = await cityRepo.FindOne({ id: req.params.cityId }); + const yourCity = await cityRepo.getUsersCity(account.id); + const city = await cityRepo.findById(req.params.cityId); const acct = await accountRepo.FindOne({id: city.owner}); @@ -93,14 +93,14 @@ server.get<{params: { cityId: string }}, string>('/city/:cityId', async req => { server.get<{}, string>('/poll/overview', async req => { const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token); - const city = await cityRepo.FindOne({ owner: account.id }); + const city = await cityRepo.getUsersCity(account.id); return renderKingomOverview(city, account); }); server.get<{}, string>('/poll/construction', async req => { const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token); - const city = await cityRepo.FindOne({ owner: account.id }); + const city = await cityRepo.getUsersCity(account.id); const buildings = await cityRepo.buildingRepository.list(); const buildQueues = await cityRepo.getBuildQueues(account.id); @@ -109,7 +109,7 @@ server.get<{}, string>('/poll/construction', async req => { server.get<{}, string>('/poll/unit-training', async req => { const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token); - const city = await cityRepo.FindOne({ owner: account.id }); + const city = await cityRepo.getUsersCity(account.id); const unitTrainingQueues = await cityRepo.getUnitTrainingQueues(account.id); const units = await cityRepo.unitRepository.list(); @@ -119,9 +119,9 @@ server.get<{}, string>('/poll/unit-training', async req => { server.get<{}, string>('/poll/map', async req => { const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token); - const city = await cityRepo.FindOne({ owner: account.id }); + const city = await cityRepo.getUsersCity(account.id); - return renderOverworldMap(await cityRepo.FindAll(), city); + return renderOverworldMap(await cityRepo.findAllInSector(city.sector_id), city); }); server.get<{}, string>('/poll/mailroom', async req => { @@ -137,7 +137,12 @@ server.post<{ building_type: string } }, string>('/cost/construction', async req => { - const amount = parseInt(req.body.amount, 10); + const amount = parseInt(req.body.amount.trim(), 10); + console.log('checking amount', amount); + + if(isNaN(amount) || amount < 1) { + return ''; + } const building = await cityRepo.buildingRepository.findBySlug(req.body.building_type); if(!building) { @@ -234,7 +239,7 @@ server.post<{ >('/attack', async req => { const acct = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token); const city = await cityRepo.getUsersCity(acct.id); - const attackedCity = await cityRepo.FindOne({id: req.body.city}); + const attackedCity = await cityRepo.findById(req.body.city); const army = { soldiers: parseInt(req.body.soldiers), @@ -280,6 +285,4 @@ server.get('/attacks/outgoing', async req => { }); -server.start(); - -tick.trigger({lastTickAt: 0, lastTick: 0}); \ No newline at end of file +server.start(); \ No newline at end of file