Added database operation for room freedom update

This commit is contained in:
Dmitriy Shishkov 2021-09-04 15:55:37 +03:00
parent 73b3ee0a10
commit d10f1ece0f
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
2 changed files with 11 additions and 6 deletions

View File

@ -4,6 +4,8 @@ import fs from "fs";
import { Room } from "./model"; import { Room } from "./model";
import { config } from "./config"; import { config } from "./config";
export { Room };
export const connect = () => export const connect = () =>
createConnection({ createConnection({
...config, ...config,
@ -17,8 +19,11 @@ export const connect = () =>
entities: [Room], entities: [Room],
}); });
export const getRoomList = (connection: Connection) => { export const getRoomList = (connection: Connection) =>
return connection.manager.find(Room); connection.manager.find(Room);
};
export { Room }; export const updateFree = (
connection: Connection,
id: number,
value: boolean
) => connection.manager.update(Room, id, { free: value });

View File

@ -1,6 +1,6 @@
import "reflect-metadata"; import "reflect-metadata";
import { Server } from "ws"; import { Server } from "ws";
import { connect, getRoomList } from "./db"; import { connect, getRoomList, updateFree } from "./db";
import { isIdMessage, isMessage } from "./types"; import { isIdMessage, isMessage } from "./types";
(async () => { (async () => {
@ -18,7 +18,7 @@ import { isIdMessage, isMessage } from "./types";
if (!isMessage(message)) throw new Error("Message corrupted"); if (!isMessage(message)) throw new Error("Message corrupted");
if (isIdMessage(message)) if (isIdMessage(message))
updateFree(message.args.id, message.type === "freed"); updateFree(connection, message.args.id, message.type === "freed");
}); });
}); });
})(); })();