[REV] Switch to use IDS over server names
This commit is contained in:
parent
e94aca7c96
commit
91587f66b2
21 changed files with 196 additions and 221 deletions
|
@ -9,32 +9,47 @@ const asExpressClientError = (e) => {
|
|||
|
||||
export async function createServerEntry(serverSpec) {
|
||||
const { name, host, version, serverType: server_type, memory } = serverSpec;
|
||||
const q = insertQuery(table, { name, host, version, server_type, memory });
|
||||
var q = insertQuery(table, { name, host, version, server_type, memory });
|
||||
q += "\n RETURNING *";
|
||||
try {
|
||||
const entries = await pg.query(q);
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
host,
|
||||
version,
|
||||
server_type: serverType,
|
||||
memory,
|
||||
} = entries[0];
|
||||
return { name, id, host, version, serverType, memory };
|
||||
} catch (e) {
|
||||
asExpressClientError(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteServerEntry(serverId) {
|
||||
if (!serverId) asExpressClientError({ message: "Server ID Required!" });
|
||||
const q = deleteQuery(table, { id: serverId });
|
||||
return pg.query(q).catch(asExpressClientError);
|
||||
}
|
||||
|
||||
export async function deleteServerEntry(serverName) {
|
||||
if (!serverName) asExpressClientError({ message: "Server Name Required!" });
|
||||
const q = deleteQuery(table, { name: serverName });
|
||||
return pg.query(q).catch(asExpressClientError);
|
||||
}
|
||||
|
||||
export async function getServerEntry(serverName) {
|
||||
if (!serverName) asExpressClientError({ message: "Server Name Required!" });
|
||||
const q = selectWhereQuery(table, { name: serverName });
|
||||
export async function getServerEntry(serverId) {
|
||||
if (!serverId) asExpressClientError({ message: "Server ID Required!" });
|
||||
const q = selectWhereQuery(table, { id: serverId });
|
||||
try {
|
||||
const serverSpecs = await pg.query(q);
|
||||
if (serverSpecs.length === 0) return [];
|
||||
if (!serverSpecs.length === 1)
|
||||
throw Error("Multiple servers found with the same name!");
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
host,
|
||||
version,
|
||||
server_type: serverType,
|
||||
memory,
|
||||
} = serverSpecs[0];
|
||||
return { name, host, version, serverType, memory };
|
||||
return { name, id, host, version, serverType, memory };
|
||||
} catch (e) {
|
||||
asExpressClientError(e);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue