server.get<{}, string>('/poll/overview', async req => {
const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
const city = await cityRepo.getUsersCity(account.id);
+ const unreadMail = await mailRepo.countUnread(account.id);
+
const usage = {
foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
return renderKingomOverview({
...city,
...usage
- }, account) + topbar({...city, ...usage});
+ }, account) + topbar({...city, ...usage}, unreadMail);
});
server.get<{}, string>('/poll/construction', async req => {
const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
const city = await cityRepo.getUsersCity(account.id);
const buildings = await cityRepo.buildingRepository.list();
+ const unreadMail = await mailRepo.countUnread(account.id);
const buildQueues = await cityRepo.getBuildQueues(account.id);
const usage = {
energyUsagePerTick: await cityRepo.energyUsagePerTick(city),
energyProductionPerTick: await cityRepo.energyProductionPerTick(city)
}
- return renderLandDevelopment(city, buildings, buildQueues) + topbar({...city, ...usage});
+ return renderLandDevelopment(city, buildings, buildQueues) + topbar({...city, ...usage}, unreadMail);
});
server.get<{}, string>('/poll/unit-training', async req => {
const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
const city = await cityRepo.getUsersCity(account.id);
+ const unreadMail = await mailRepo.countUnread(account.id);
const unitTrainingQueues = await cityRepo.getUnitTrainingQueues(account.id);
const units = await cityRepo.unitRepository.list();
return renderUnitTraining(city, units, unitTrainingQueues) + topbar({
...city,
...usage
- });
+ }, unreadMail);
});
server.post<{body: {sector: string}}, string>('/poll/map', async req => {
const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
const city = await cityRepo.getUsersCity(account.id);
+ const unreadMail = await mailRepo.countUnread(account.id);
let sector = city.sector_id;
if(req.body.sector) {
return renderOverworldMap(await cityRepo.findAllInSector(sector), city, sector) + topbar({
...city,
...usage
- });
+ }, unreadMail);
});
server.get<{}, string>('/poll/mailroom', async req => {
const account = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
const city = await cityRepo.getUsersCity(account.id);
+ const unreadMail = await mailRepo.countUnread(account.id);
const usage = {
foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
return renderMailroom(await mailRepo.listReceivedMessages(account.id)) + topbar({
...city,
...usage
- });
+ }, unreadMail);
});
});
}, 'reload-outgoing-attacks');
-server.get<void, string>('/messages', async req => {
- const acct = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
- const msgs = await mailRepo.listReceivedMessages(acct.id);
-
- return JSON.stringify(msgs);
-});
-
server.get<{params: {id: string}}, string>('/messages/:id', async req => {
const acct = await accountRepo.validate(req.authInfo.accountId, req.authInfo.token);
+ const city = await cityRepo.getUsersCity(acct.id);
const msg = await mailRepo.getMessage(req.params.id, acct.id);
if(!msg) {
throw new NotFoundError('No such message', ERROR_CODE.DUPLICATE_CACHE_KEY);
}
+ const usage = {
+ foodUsagePerTick: await cityRepo.foodUsagePerTick(city),
+ foodProductionPerTick: await cityRepo.foodProductionPerTick(city),
+ energyUsagePerTick: await cityRepo.energyUsagePerTick(city),
+ energyProductionPerTick: await cityRepo.energyProductionPerTick(city)
+ }
+
await mailRepo.markAsRead(msg.id, msg.to_account);
+ const unreadMail = await mailRepo.countUnread(acct.id);
- return renderMessage(msg);
+ return renderMailroom(await mailRepo.listReceivedMessages(acct.id), msg) + topbar({
+ ...city,
+ ...usage
+ }, unreadMail);
});
server.get<void, string>('/attacks/outgoing', async req => {