diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index b2d6734..0000000 --- a/jest.config.js +++ /dev/null @@ -1,145 +0,0 @@ -"use strict"; -/* - * For a detailed explanation regarding each configuration property and type check, visit: - * https://jestjs.io/docs/configuration - */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = { - // All imported modules in your tests should be mocked automatically - // automock: false, - // Stop running tests after `n` failures - // bail: 0, - // The directory where Jest should store its cached dependency information - // cacheDirectory: "C:\\Users\\legon\\AppData\\Local\\Temp\\jest", - // Automatically clear mock calls, instances, contexts and results before every test - // clearMocks: false, - // Indicates whether the coverage information should be collected while executing the test - collectCoverage: true, - // An array of glob patterns indicating a set of files for which coverage information should be collected - // collectCoverageFrom: undefined, - // The directory where Jest should output its coverage files - coverageDirectory: "coverage", - // An array of regexp pattern strings used to skip coverage collection - // coveragePathIgnorePatterns: [ - // "\\\\node_modules\\\\" - // ], - // Indicates which provider should be used to instrument code for coverage - // coverageProvider: "babel", - // A list of reporter names that Jest uses when writing coverage reports - // coverageReporters: [ - // "json", - // "text", - // "lcov", - // "clover" - // ], - // An object that configures minimum threshold enforcement for coverage results - // coverageThreshold: undefined, - // A path to a custom dependency extractor - // dependencyExtractor: undefined, - // Make calling deprecated APIs throw helpful error messages - // errorOnDeprecated: false, - // The default configuration for fake timers - // fakeTimers: { - // "enableGlobally": false - // }, - // Force coverage collection from ignored files using an array of glob patterns - // forceCoverageMatch: [], - // A path to a module which exports an async function that is triggered once before all test suites - // globalSetup: undefined, - // A path to a module which exports an async function that is triggered once after all test suites - // globalTeardown: undefined, - // A set of global variables that need to be available in all test environments - // globals: {}, - // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. - // maxWorkers: "50%", - // An array of directory names to be searched recursively up from the requiring module's location - // moduleDirectories: [ - // "node_modules" - // ], - // An array of file extensions your modules use - // moduleFileExtensions: [ - // "js", - // "mjs", - // "cjs", - // "jsx", - // "ts", - // "tsx", - // "json", - // "node" - // ], - // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module - // moduleNameMapper: {}, - // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader - // modulePathIgnorePatterns: [], - // Activates notifications for test results - // notify: false, - // An enum that specifies notification mode. Requires { notify: true } - // notifyMode: "failure-change", - // A preset that is used as a base for Jest's configuration - // preset: undefined, - // Run tests from one or more projects - // projects: undefined, - // Use this configuration option to add custom reporters to Jest - // reporters: undefined, - // Automatically reset mock state before every test - // resetMocks: false, - // Reset the module registry before running each individual test - // resetModules: false, - // A path to a custom resolver - // resolver: undefined, - // Automatically restore mock state and implementation before every test - // restoreMocks: false, - // The root directory that Jest should scan for tests and modules within - // rootDir: undefined, - // A list of paths to directories that Jest should use to search for files in - // roots: [ - // "" - // ], - // Allows you to use a custom runner instead of Jest's default test runner - // runner: "jest-runner", - // The paths to modules that run some code to configure or set up the testing environment before each test - // setupFiles: [], - // A list of paths to modules that run some code to configure or set up the testing framework before each test - // setupFilesAfterEnv: [], - // The number of seconds after which a test is considered as slow and reported as such in the results. - // slowTestThreshold: 5, - // A list of paths to snapshot serializer modules Jest should use for snapshot testing - // snapshotSerializers: [], - // The test environment that will be used for testing - // testEnvironment: "jest-environment-node", - // Options that will be passed to the testEnvironment - // testEnvironmentOptions: {}, - // Adds a location field to test results - // testLocationInResults: false, - // The glob patterns Jest uses to detect test files - // testMatch: [ - // "**/__tests__/**/*.[jt]s?(x)", - // "**/?(*.)+(spec|test).[tj]s?(x)" - // ], - // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped - // testPathIgnorePatterns: [ - // "\\\\node_modules\\\\" - // ], - // The regexp pattern or array of patterns that Jest uses to detect test files - // testRegex: [], - // This option allows the use of a custom results processor - // testResultsProcessor: undefined, - // This option allows use of a custom test runner - // testRunner: "jest-circus/runner", - // A map from regular expressions to paths to transformers - // transform: undefined, - // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation - // transformIgnorePatterns: [ - // "\\\\node_modules\\\\", - // "\\.pnp\\.[^\\\\]+$" - // ], - // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them - // unmockedModulePathPatterns: undefined, - // Indicates whether each individual test should be reported during the run - // verbose: undefined, - // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode - // watchPathIgnorePatterns: [], - // Whether to use watchman for file crawling - // watchman: true, -}; -//# sourceMappingURL=jest.config.js.map \ No newline at end of file diff --git a/jest.config.js.map b/jest.config.js.map deleted file mode 100644 index 858ff38..0000000 --- a/jest.config.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["jest.config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,kBAAe;IACb,oEAAoE;IACpE,mBAAmB;IAEnB,wCAAwC;IACxC,WAAW;IAEX,0EAA0E;IAC1E,kEAAkE;IAElE,oFAAoF;IACpF,qBAAqB;IAErB,0FAA0F;IAC1F,eAAe,EAAE,IAAI;IAErB,yGAAyG;IACzG,kCAAkC;IAElC,4DAA4D;IAC5D,iBAAiB,EAAE,UAAU;IAE7B,sEAAsE;IACtE,gCAAgC;IAChC,2BAA2B;IAC3B,KAAK;IAEL,0EAA0E;IAC1E,6BAA6B;IAE7B,wEAAwE;IACxE,uBAAuB;IACvB,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,KAAK;IAEL,+EAA+E;IAC/E,gCAAgC;IAEhC,0CAA0C;IAC1C,kCAAkC;IAElC,4DAA4D;IAC5D,4BAA4B;IAE5B,4CAA4C;IAC5C,gBAAgB;IAChB,4BAA4B;IAC5B,KAAK;IAEL,+EAA+E;IAC/E,0BAA0B;IAE1B,mGAAmG;IACnG,0BAA0B;IAE1B,kGAAkG;IAClG,6BAA6B;IAE7B,+EAA+E;IAC/E,eAAe;IAEf,iOAAiO;IACjO,qBAAqB;IAErB,iGAAiG;IACjG,uBAAuB;IACvB,mBAAmB;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kBAAkB;CACnB,CAAC"} \ No newline at end of file diff --git a/src/db/db.ts b/src/db/db.ts index 421909a..b0cd11a 100644 --- a/src/db/db.ts +++ b/src/db/db.ts @@ -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({ - // 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 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() { diff --git a/src/db/migrations/2023-02-28-01.ts b/src/db/migrations/2023-02-28-01.ts index ec3d255..9340f83 100644 --- a/src/db/migrations/2023-02-28-01.ts +++ b/src/db/migrations/2023-02-28-01.ts @@ -27,8 +27,8 @@ export async function up(db: Kysely): Promise { 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): Promise { .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): Promise { export async function down(db: Kysely): Promise { 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() diff --git a/src/db/model.ts b/src/db/model.ts index 610dbaf..66d1b1f 100644 --- a/src/db/model.ts +++ b/src/db/model.ts @@ -3,7 +3,7 @@ import { ColumnType, Generated } from 'kysely' export interface KillTable { id: Generated 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 } diff --git a/src/index.ts b/src/index.ts index 3f0af2c..5c6d18f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 diff --git a/src/server.ts b/src/server.ts index 1297b71..93fffd0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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 diff --git a/tests/tess.test.js b/tests/tess.test.js deleted file mode 100644 index 42cd321..0000000 --- a/tests/tess.test.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const globals_1 = require("@jest/globals"); -(0, globals_1.describe)('integer module', () => { - (0, globals_1.test)('3', () => { - (0, globals_1.expect)(3).toBe(3); - }); -}); -//# sourceMappingURL=tess.test.js.map \ No newline at end of file diff --git a/tests/tess.test.js.map b/tests/tess.test.js.map deleted file mode 100644 index 326571b..0000000 --- a/tests/tess.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"tess.test.js","sourceRoot":"","sources":["tess.test.ts"],"names":[],"mappings":";;AAAA,2CAAsD;AAEtD,IAAA,kBAAQ,EAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAA,cAAI,EAAC,GAAG,EAAE,GAAG,EAAE;QACb,IAAA,gBAAM,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index d53fb6a..a6b7049 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -100,5 +100,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "compileOnSave": true + "compileOnSave": true, + "exclude": ["jest.config.ts", "./tests"] }