WIP: update to include sectors!
[browser-rts.git] / src / api.ts
index e5e155758823d74a42fdd6275c768254ccaf6714..76873678c2d2741723ddcb932c702439760f9c08 100644 (file)
@@ -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 => {
@@ -234,7 +234,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 +280,4 @@ server.get<void, string>('/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