1 import { Task } from './task';
2 import { BuildQueueRepository } from '../repository/build-queue';
3 import { CityRepository } from '../repository/city';
4 import { BuildingRepository } from '../repository/buildings';
5 import { MailRepository } from '../repository/mail';
8 const buildQueueRepo = new BuildQueueRepository();
9 const cityRepo = new CityRepository();
10 const buildingRepo = new BuildingRepository();
11 const mailRepo = new MailRepository();
15 building_type: string,
22 export const construction = new Task<Construction>('construction', async (task, job) => {
23 // validate that this is a real build queue item
24 const dbEntry = await buildQueueRepo.FindOne({id: job.data.id});
27 console.error(`Build queue ${job.data.id} is invalid`);
31 const building = await buildingRepo.findBySlug(dbEntry.building_type);
33 console.error(`Building type ${job.data.building_type} is not valid`);
38 const city = await cityRepo.getUsersCity(dbEntry.owner);
41 console.error(`City for owner ${job.data.owner} does not exist`);
45 // resource checks have already been done and resources have
46 // been removed from the city. so we're good to just give them
49 city[dbEntry.building_type] += dbEntry.amount;
51 // lets update the city
54 buildQueueRepo.Delete({id: dbEntry.id}),
55 mailRepo.createSystemMessage(
58 `Your ${building.display} (${dbEntry.amount}) were completed`,
60 <b>Congratulations!</b>
61 <p>The your people have toiled and constructed ${dbEntry.amount} ${building.display}!</p>