working kill posts
This commit is contained in:
+5
-3
@@ -4,9 +4,7 @@ import migrateToLatest from './migrations'
|
||||
import Database, { KillTable } from './model'
|
||||
|
||||
const migration = migrateToLatest()
|
||||
// You'd create one of these when you start your app.
|
||||
const db = new Kysely<Database>({
|
||||
// Use MysqlDialect for MySQL and SqliteDialect for SQLite.
|
||||
dialect: new PostgresDialect({
|
||||
pool: new Pool({
|
||||
host: process.env.POSTGRES_HOST,
|
||||
@@ -25,7 +23,11 @@ interface RemoveFromKill {
|
||||
type KillRecord = Omit<KillTable, keyof RemoveFromKill>
|
||||
|
||||
export async function CreateKillRecord(data: KillRecord) {
|
||||
await db.insertInto('kill').values({ ...data })
|
||||
//TODO : Handle server foreign key crashes
|
||||
await db
|
||||
.insertInto('kill')
|
||||
.values({ ...data })
|
||||
.execute()
|
||||
}
|
||||
/*
|
||||
async function demo() {
|
||||
|
||||
@@ -27,8 +27,8 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
|
||||
await db.schema
|
||||
.createTable('server')
|
||||
.addColumn('id', 'integer')
|
||||
.addColumn('name', 'varchar', (col) => col.unique().primaryKey())
|
||||
.addColumn('id', 'serial', (col) => col.primaryKey())
|
||||
.addColumn('name', 'varchar', (col) => col.unique())
|
||||
.addColumn('description', 'varchar')
|
||||
.addColumn('token', 'varchar')
|
||||
.execute()
|
||||
@@ -39,27 +39,41 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.addColumn('server', 'integer', (col) =>
|
||||
col.references('server.id').notNull().onDelete('cascade')
|
||||
)
|
||||
.addColumn('damage_source', 'varchar')
|
||||
.addColumn('attacker', 'integer')
|
||||
.addColumn('attacker_type', 'varchar')
|
||||
.addColumn('attacker_weapon', 'varchar')
|
||||
.addColumn('attacker_weapon_2', 'varchar')
|
||||
.addColumn('attacker_weapon_3', 'varchar')
|
||||
.addColumn('attacker_ordnance', 'varchar')
|
||||
.addColumn('attacker_ability', 'varchar')
|
||||
.addColumn('attacker_kit_1', 'varchar')
|
||||
.addColumn('attacker_kit_2', 'varchar')
|
||||
.addColumn('victim', 'integer')
|
||||
.addColumn('victim_weapon', 'varchar')
|
||||
.addColumn('victim_weapon_2', 'integer')
|
||||
.addColumn('victim_weapon_3', 'integer')
|
||||
.addColumn('victim_ordnance', 'integer')
|
||||
.addColumn('victim_ability', 'integer')
|
||||
.addColumn('victim_kit_1', 'integer')
|
||||
.addColumn('victim_kit_2', 'integer')
|
||||
.addColumn('killstat_version', 'varchar')
|
||||
.addColumn('match_id', 'varchar')
|
||||
.addColumn('game_mode', 'varchar')
|
||||
.addColumn('map', 'varchar')
|
||||
.addColumn('distance', 'integer')
|
||||
.addColumn('date', 'varchar', (col) => col.defaultTo(sql`now()`).notNull())
|
||||
.addColumn('unix_time', 'timestamp', (col) =>
|
||||
col.defaultTo(sql`now()`).notNull()
|
||||
)
|
||||
.addColumn('game_time', 'decimal')
|
||||
.addColumn('player_count', 'integer')
|
||||
.addColumn('attacker_name', 'varchar')
|
||||
.addColumn('attacker_id', 'varchar')
|
||||
.addColumn('attacker_current_weapon', 'varchar')
|
||||
.addColumn('attacker_current_weapon_mods', 'integer')
|
||||
.addColumn('attacker_weapon_1', 'varchar')
|
||||
.addColumn('attacker_weapon_1_mods', 'integer')
|
||||
.addColumn('attacker_weapon_2', 'varchar')
|
||||
.addColumn('attacker_weapon_2_mods', 'integer')
|
||||
.addColumn('attacker_weapon_3', 'varchar')
|
||||
.addColumn('attacker_weapon_3_mods', 'integer')
|
||||
.addColumn('attacker_offhand_weapon_1', 'integer')
|
||||
.addColumn('attacker_offhand_weapon_2', 'integer')
|
||||
.addColumn('victim_name', 'varchar')
|
||||
.addColumn('victim_id', 'varchar')
|
||||
.addColumn('victim_current_weapon', 'varchar')
|
||||
.addColumn('victim_current_weapon_mods', 'integer')
|
||||
.addColumn('victim_weapon_1', 'varchar')
|
||||
.addColumn('victim_weapon_1_mods', 'integer')
|
||||
.addColumn('victim_weapon_2', 'varchar')
|
||||
.addColumn('victim_weapon_2_mods', 'integer')
|
||||
.addColumn('victim_weapon_3', 'varchar')
|
||||
.addColumn('victim_weapon_3_mods', 'integer')
|
||||
.addColumn('victim_offhand_weapon_1', 'integer')
|
||||
.addColumn('victim_offhand_weapon_2', 'integer')
|
||||
.addColumn('cause_of_death', 'varchar')
|
||||
.addColumn('distance', 'decimal')
|
||||
.execute()
|
||||
|
||||
/*await db.schema
|
||||
@@ -81,7 +95,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropTable('kill').execute()
|
||||
await db.schema.dropTable('entity').execute()
|
||||
await db.schema.dropTable('player').execute()
|
||||
await db.schema.dropTable('weapon').execute()
|
||||
await db.schema.dropTable('map').execute()
|
||||
await db.schema.dropTable('server').execute()
|
||||
|
||||
+14
-14
@@ -3,7 +3,7 @@ import { ColumnType, Generated } from 'kysely'
|
||||
export interface KillTable {
|
||||
id: Generated<number>
|
||||
server: number
|
||||
tone_version: string
|
||||
killstat_version: string
|
||||
match_id: string
|
||||
game_mode: string
|
||||
map: string
|
||||
@@ -11,29 +11,29 @@ export interface KillTable {
|
||||
game_time: number
|
||||
player_count: number
|
||||
attacker_name: string
|
||||
attacker_id: number
|
||||
attacker_id: string
|
||||
attacker_current_weapon: string
|
||||
attacker_current_weapon_mods: string
|
||||
attacker_current_weapon_mods: number
|
||||
attacker_weapon_1: string
|
||||
attacker_weapon_1_mods: string
|
||||
attacker_weapon_1_mods: number
|
||||
attacker_weapon_2: string
|
||||
attacker_weapon_2_mods: string
|
||||
attacker_weapon_2_mods: number
|
||||
attacker_weapon_3: string
|
||||
attacker_weapon_3_mods: string
|
||||
attacker_offhand_weapon_1: string
|
||||
attacker_offhand_weapon_2: string
|
||||
attacker_weapon_3_mods: number
|
||||
attacker_offhand_weapon_1: number
|
||||
attacker_offhand_weapon_2: number
|
||||
victim_name: string
|
||||
victim_id: number
|
||||
victim_id: string
|
||||
victim_current_weapon: string
|
||||
victim_current_weapon_mods: string
|
||||
victim_current_weapon_mods: number
|
||||
victim_weapon_1: string
|
||||
victim_weapon_1_mods: string
|
||||
victim_weapon_1_mods: number
|
||||
victim_weapon_2: string
|
||||
victim_weapon_2_mods: string
|
||||
victim_weapon_2_mods: number
|
||||
victim_weapon_3: string
|
||||
victim_weapon_3_mods: string
|
||||
victim_offhand_weapon_1: string
|
||||
victim_offhand_weapon_2: string
|
||||
victim_offhand_weapon_1: number
|
||||
victim_offhand_weapon_2: number
|
||||
cause_of_death: string
|
||||
distance: number
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import client from './client'
|
||||
import { dbReady } from './db/db'
|
||||
import server from './server'
|
||||
|
||||
console.log('dotenv')
|
||||
|
||||
const app = express()
|
||||
const port = 3001
|
||||
|
||||
|
||||
+28
-21
@@ -8,43 +8,48 @@ router.post('/*', (req, res, next) => {
|
||||
next()
|
||||
})
|
||||
router.post(
|
||||
'/servers/:serverId/kills',
|
||||
body(
|
||||
['attacker_id', 'victim_id'],
|
||||
'attacker and victim must be player UIDs'
|
||||
).isInt(),
|
||||
'/servers/:serverId/kill',
|
||||
body([
|
||||
'attacker_current_weapon_mods',
|
||||
'attacker_weapon_1_mods',
|
||||
'attacker_weapon_2_mods',
|
||||
'attacker_weapon_3_mods',
|
||||
'attacker_offhand_weapon_1',
|
||||
'attacker_offhand_weapon_2',
|
||||
'distance',
|
||||
'player_count',
|
||||
'victim_current_weapon_mods',
|
||||
'victim_weapon_1_mods',
|
||||
'victim_weapon_2_mods',
|
||||
'victim_weapon_3_mods',
|
||||
'victim_offhand_weapon_1',
|
||||
'victim_offhand_weapon_2'
|
||||
])
|
||||
.toInt()
|
||||
.isInt(),
|
||||
body('game_time').toFloat().isFloat(),
|
||||
body(
|
||||
[
|
||||
'tone_version',
|
||||
'attacker_id',
|
||||
'victim_id',
|
||||
'killstat_version',
|
||||
'match_id',
|
||||
'game_mode',
|
||||
'map',
|
||||
'player_count',
|
||||
'attacker_name',
|
||||
'attacker_current_weapon',
|
||||
'attacker_current_weapon_mods',
|
||||
'attacker_weapon_1',
|
||||
'attacker_weapon_1_mods',
|
||||
'attacker_weapon_2',
|
||||
'attacker_weapon_2_mods',
|
||||
'attacker_weapon_3',
|
||||
'attacker_weapon_3_mods',
|
||||
'attacker_offhand_weapon_1',
|
||||
'attacker_offhand_weapon_2',
|
||||
'victim_name',
|
||||
'victim_current_weapon',
|
||||
'victim_current_weapon_mods',
|
||||
'victim_weapon_1',
|
||||
'victim_weapon_1_mods',
|
||||
'victim_weapon_2',
|
||||
'victim_weapon_2_mods',
|
||||
'victim_weapon_3',
|
||||
'victim_weapon_3_mods',
|
||||
'victim_offhand_weapon_1',
|
||||
'victim_offhand_weapon_2',
|
||||
'cause_of_death'
|
||||
],
|
||||
'values must be composed of a maximum of 50 valid ascii characters'
|
||||
'string values must be composed of a maximum of 50 valid ascii characters'
|
||||
)
|
||||
.isString()
|
||||
.isLength({ max: 50 })
|
||||
@@ -60,9 +65,10 @@ router.post(
|
||||
'cause_of_death and victim_id are mandatory'
|
||||
).notEmpty(),
|
||||
(req, res, next) => {
|
||||
console.log(req.body)
|
||||
const server = 1 // set server ID here
|
||||
const {
|
||||
tone_version,
|
||||
killstat_version,
|
||||
match_id,
|
||||
game_mode,
|
||||
map,
|
||||
@@ -96,7 +102,7 @@ router.post(
|
||||
distance
|
||||
} = req.body
|
||||
CreateKillRecord({
|
||||
tone_version,
|
||||
killstat_version,
|
||||
server,
|
||||
match_id,
|
||||
game_mode,
|
||||
@@ -131,6 +137,7 @@ router.post(
|
||||
distance
|
||||
})
|
||||
res.send(200)
|
||||
return
|
||||
}
|
||||
)
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user