initial commit
[browser-rts.git] / src / repository / build-queue.ts
1 import { v4 as uuid } from 'uuid';
2 import { Repository } from './base';
3 export enum Buildings {
4     FARMS = 'FARMS',
5     BARRACKS = 'BARRACKS',
6     SPECIAL_ATTACKER_TRAINER = 'SPECIAL_ATTACKER_TRAINER',
7     SPECIAL_DEFENDER_TRAINER = 'SPECIAL_DEFENDER_TRAINER'
8 }
9 export type BuildQueue = {
10     id: string;
11     owner: string;
12     building_type: string,
13     amount: number,
14     created: number;
15     due: number;
16 };
17
18 export class BuildQueueRepository extends Repository<BuildQueue> {
19     constructor() {
20         super('build_queues');
21     }
22
23     async create(owner: string, due: number, type: string, amount: number): Promise<BuildQueue> {
24         const data: BuildQueue = {
25             id: uuid(),
26             building_type: type,
27             created: Date.now(),
28             amount,
29             due,
30             owner
31         };
32
33         await this.Insert(data);
34
35         return data;
36     }
37
38     async list(owner: string): Promise<BuildQueue[]> {
39         return this.FindAll({owner});
40     }
41 }