1 import { Repository } from "./base";
2 import { v4 as uuid } from 'uuid';
3 import { City } 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: City, attacked_city: City, 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, c.location_x, c.location_y
55 join cities c on c.id = aq.attacked_city
56 join accounts o on o.id = c.owner
57 order by due asc`)) as ArmyQueueWithAttackedOwner[];
60 async listIncoming(city_id: string): Promise<ArmyQueue[]> {
61 return this.FindAll({attacked_city: city_id});