-
Notifications
You must be signed in to change notification settings - Fork 0
/
ship.entity.ts
93 lines (82 loc) · 1.92 KB
/
ship.entity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
import { v4 as uuidv4 } from 'uuid'
import {
Cooldown,
Ship,
ShipCargo,
ShipCrew,
ShipEngine,
ShipFrame,
ShipFuel,
ShipModule,
ShipMount,
ShipNav,
ShipReactor,
ShipRegistration,
} from '../../../api'
export enum ShipActionType {
SELL = 'SELL',
FILL = 'FILL',
}
type ShipAction = {
type?: ShipActionType
}
@Entity({ tableName: 'ship' })
export class ShipEntity {
@PrimaryKey({ type: 'uuid' })
id = uuidv4()
@Property()
resetDate: string
@Property()
createdAt = new Date()
@Property({ onUpdate: () => new Date() })
updatedAt = new Date()
@Property()
symbol: string
@Property({ type: 'json' })
registration: ShipRegistration
@Property({ type: 'json' })
nav: ShipNav
@Property({ type: 'json' })
crew: ShipCrew
@Property({ type: 'json' })
frame: ShipFrame
@Property({ type: 'json' })
reactor: ShipReactor
@Property({ type: 'json' })
engine: ShipEngine
@Property({ type: 'json' })
cooldown: Cooldown
@Property({ type: 'json' })
modules: Array<ShipModule>
@Property({ type: 'json' })
mounts: Array<ShipMount>
@Property({ type: 'json' })
cargo: ShipCargo
@Property({ type: 'json' })
fuel: ShipFuel
@Property({ type: 'json' })
action?: ShipAction
isCommanded = false
constructor(resetDate: string, ship: Ship) {
this.resetDate = resetDate
this.symbol = ship.symbol
this.cargo = ship.cargo
this.cooldown = ship.cooldown
this.registration = ship.registration
this.nav = ship.nav
this.crew = ship.crew
this.frame = ship.frame
this.reactor = ship.reactor
this.engine = ship.engine
this.cooldown = ship.cooldown
this.modules = ship.modules
this.mounts = ship.mounts
this.cargo = ship.cargo
this.fuel = ship.fuel
}
get label() {
const suffix = this.symbol.match(/-(.+$)/)?.[1] ?? ''
return `${this.registration.role}-${suffix}`
}
}