1 import { Repository } from "./base";
2 import { v4 as uuid } from 'uuid';
3 import { CityWithLocation } from "./city";
13 export type ArmyQueue = {
19 attacked_city: string;
22 export type ArmyQueueWithAttackedOwner = {
23 attacked_account: string;
28 export class ArmyRepository extends Repository<ArmyQueue> {
33 async create(owner: string, city: CityWithLocation, attacked_city: CityWithLocation, army: Army, distance: number): Promise<ArmyQueue> {
34 // figure out the distance to the attacked city
36 const info: ArmyQueue = {
40 attacked_city: attacked_city.id,
42 due: (distance * 1000) + Date.now(),
46 await this.Insert(info);
51 async listOutgoing(city_id: string): Promise<ArmyQueueWithAttackedOwner[]> {
52 return await (this.db.raw(`select
53 aq.*, o.username as attacked_account, l.location_x, l.location_y, l.sector_id
55 join cities c on c.id = aq.attacked_city
56 join locations l on l.city_id = aq.attacked_city
57 join accounts o on o.id = c.owner
58 order by due asc`)) as ArmyQueueWithAttackedOwner[];
61 async listIncoming(city_id: string): Promise<ArmyQueue[]> {
62 return this.FindAll({attacked_city: city_id});