Added database operation for room freedom update
This commit is contained in:
parent
73b3ee0a10
commit
d10f1ece0f
@ -4,6 +4,8 @@ import fs from "fs";
|
||||
import { Room } from "./model";
|
||||
import { config } from "./config";
|
||||
|
||||
export { Room };
|
||||
|
||||
export const connect = () =>
|
||||
createConnection({
|
||||
...config,
|
||||
@ -17,8 +19,11 @@ export const connect = () =>
|
||||
entities: [Room],
|
||||
});
|
||||
|
||||
export const getRoomList = (connection: Connection) => {
|
||||
return connection.manager.find(Room);
|
||||
};
|
||||
export const getRoomList = (connection: Connection) =>
|
||||
connection.manager.find(Room);
|
||||
|
||||
export { Room };
|
||||
export const updateFree = (
|
||||
connection: Connection,
|
||||
id: number,
|
||||
value: boolean
|
||||
) => connection.manager.update(Room, id, { free: value });
|
||||
|
@ -1,6 +1,6 @@
|
||||
import "reflect-metadata";
|
||||
import { Server } from "ws";
|
||||
import { connect, getRoomList } from "./db";
|
||||
import { connect, getRoomList, updateFree } from "./db";
|
||||
import { isIdMessage, isMessage } from "./types";
|
||||
|
||||
(async () => {
|
||||
@ -18,7 +18,7 @@ import { isIdMessage, isMessage } from "./types";
|
||||
if (!isMessage(message)) throw new Error("Message corrupted");
|
||||
|
||||
if (isIdMessage(message))
|
||||
updateFree(message.args.id, message.type === "freed");
|
||||
updateFree(connection, message.args.id, message.type === "freed");
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user