minor cleanup
This commit is contained in:
@@ -5,7 +5,7 @@ export const activeGames: Array<Game> = [];
|
|||||||
|
|
||||||
// todo: join user and game relationship
|
// todo: join user and game relationship
|
||||||
|
|
||||||
const create = async (game: Game) => {
|
export const create = async (game: Game) => {
|
||||||
try {
|
try {
|
||||||
const res = await db.query(
|
const res = await db.query(
|
||||||
`INSERT INTO "game"(pgn, white_id, black_id, winner) VALUES($1, $2, $3, $4) RETURNING *`,
|
`INSERT INTO "game"(pgn, white_id, black_id, winner) VALUES($1, $2, $3, $4) RETURNING *`,
|
||||||
@@ -24,7 +24,7 @@ const create = async (game: Game) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const find = async (where?: string, limit = 1) => {
|
export const find = async (where?: string, limit = 1) => {
|
||||||
const query = where
|
const query = where
|
||||||
? `SELECT * FROM "game"`
|
? `SELECT * FROM "game"`
|
||||||
: {
|
: {
|
||||||
@@ -49,7 +49,7 @@ const find = async (where?: string, limit = 1) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const update = async (id: number, data: string) => {
|
export const update = async (id: number, data: string) => {
|
||||||
try {
|
try {
|
||||||
const res = await db.query(`UPDATE "game" SET $1 WHERE id = $2 RETURNING *`, [data, id]);
|
const res = await db.query(`UPDATE "game" SET $1 WHERE id = $2 RETURNING *`, [data, id]);
|
||||||
return {
|
return {
|
||||||
@@ -65,7 +65,7 @@ const update = async (id: number, data: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const remove = async (id: number) => {
|
export const remove = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
const res = await db.query(`DELETE FROM "game" WHERE id = $1 RETURNING *`, [id]);
|
const res = await db.query(`DELETE FROM "game" WHERE id = $1 RETURNING *`, [id]);
|
||||||
return {
|
return {
|
||||||
@@ -80,10 +80,3 @@ const remove = async (id: number) => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GameModel = {
|
|
||||||
create,
|
|
||||||
find,
|
|
||||||
update,
|
|
||||||
remove
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
const socketConnect = (socket: Socket) => {
|
const socketConnect = (socket: Socket) => {
|
||||||
const req = socket.request;
|
const req = socket.request;
|
||||||
|
|
||||||
// re-analyze if this is necessary, or if io.use will handle logout
|
// review if this is necessary, or if io.use will handle logout
|
||||||
socket.use((__, next) => {
|
socket.use((__, next) => {
|
||||||
req.session.reload((err) => {
|
req.session.reload((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
@@ -13,7 +13,7 @@ export interface Game {
|
|||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
id?: number | string; // string for guest IDs
|
id?: number | string; // string for guest IDs
|
||||||
name?: string;
|
name?: string | null;
|
||||||
email?: string;
|
email?: string;
|
||||||
connected?: boolean; // mainly for players, not spectators
|
connected?: boolean; // mainly for players, not spectators
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user