Skip to content

Commit

Permalink
#123 Модуль Game и его тесты переведены на TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
gbagretsov committed May 12, 2022
1 parent e3029e4 commit b89de0e
Show file tree
Hide file tree
Showing 13 changed files with 629 additions and 698 deletions.
1 change: 1 addition & 0 deletions app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module.exports = {
'**/daily.test.ts',
'**/holidays.test.ts',
'**/statistics.test.ts',
'**/game.test.ts',
], // TODO: add all test files when they are fixed
};
2 changes: 2 additions & 0 deletions app/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {Client, QueryResult, types} from 'pg';

types.setTypeParser(types.builtins.INT8, val => parseInt(val, 10));

export const DUPLICATE_KEY_PG_ERROR = '23505';

async function getClient(): Promise<Client> {
const client = new Client({
connectionString: process.env.DATABASE_URL,
Expand Down
21 changes: 0 additions & 21 deletions app/src/game/admin.js

This file was deleted.

24 changes: 24 additions & 0 deletions app/src/game/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import db, {DUPLICATE_KEY_PG_ERROR} from '../db';
import {AddWordResult} from './model/AddWordResult';

async function addWord(word: string, approved: boolean): Promise<AddWordResult> {
try {
await db.query(`INSERT INTO friends_vk_bot.words (name, approved) VALUES ('${ word }', ${ approved });`);
return AddWordResult.SUCCESS;
} catch (error) {
return (error as any).code === DUPLICATE_KEY_PG_ERROR ? AddWordResult.DUPLICATE_WORD : AddWordResult.ERROR;
}
}

async function deleteWord(word: string): Promise<void> {
try {
await db.query(`DELETE FROM friends_vk_bot.words WHERE name = '${ word }';`);
} catch (error) {
console.log(error);
}
}

export default {
deleteWord,
addWord,
};
294 changes: 0 additions & 294 deletions app/src/game/game.js

This file was deleted.

Loading

0 comments on commit b89de0e

Please sign in to comment.