feat(permissions): Adds server permissions
This commit is contained in:
parent
d46bbd84c5
commit
cf9c88a2d6
24 changed files with 415 additions and 69 deletions
|
|
@ -28,7 +28,7 @@ export class DatabaseUpdater {
|
|||
);
|
||||
|
||||
if (!DBSQLColumns) {
|
||||
Container.get<Logger>("logger").log("Request failed...");
|
||||
Container.get<Logger>("logger").warn("Request for database columns failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ export class DatabaseUpdater {
|
|||
)
|
||||
|
||||
if (missingColumns.length < 1) {
|
||||
Container.get<Logger>("logger").log(`No new columns found for ${definition.name}`)
|
||||
Container.get<Logger>("logger").debug(`No new columns found for ${definition.name}`)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
6
source/Database/Models/ServerConfigurationModel.ts
Normal file
6
source/Database/Models/ServerConfigurationModel.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import {ConfigurationModel} from "./ConfigurationModel";
|
||||
import {Snowflake} from "discord.js";
|
||||
|
||||
export type ServerConfigurationModel = ConfigurationModel & {
|
||||
serverid: Snowflake
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
import {Repository} from "./Repository";
|
||||
import {Nullable} from "../../types/Nullable";
|
||||
import {DatabaseConnection} from "../DatabaseConnection";
|
||||
import {ServerConfigurationModel} from "../Models/ServerConfigurationModel";
|
||||
import ServerConfiguration, {DBServerConfiguration} from "../tables/ServerConfiguration";
|
||||
import {Snowflake} from "discord.js";
|
||||
|
||||
export class ServerConfigurationRepository extends Repository<ServerConfigurationModel, DBServerConfiguration> {
|
||||
|
||||
constructor(
|
||||
protected readonly database: DatabaseConnection,
|
||||
) {
|
||||
super(
|
||||
database,
|
||||
ServerConfiguration
|
||||
);
|
||||
}
|
||||
|
||||
public findServerConfigurations(server: Snowflake): ServerConfigurationModel[] {
|
||||
return this.database.fetchAll<number, DBServerConfiguration>(
|
||||
`SELECT * FROM serverConfiguration WHERE serverid = ?`,
|
||||
server
|
||||
).map((config) => {
|
||||
return this.convertToModelType(config);
|
||||
})
|
||||
}
|
||||
|
||||
public findConfigurationByPath(server: Snowflake, path: string): Nullable<ServerConfigurationModel> {
|
||||
const result = this.database.fetch<number, DBServerConfiguration>(
|
||||
`SELECT * FROM serverConfiguration WHERE serverid = ? AND key = ?`,
|
||||
server,
|
||||
path
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.convertToModelType(result);
|
||||
}
|
||||
|
||||
|
||||
protected convertToModelType(intermediateModel: DBServerConfiguration | undefined): ServerConfigurationModel {
|
||||
if (!intermediateModel) {
|
||||
throw new Error("No intermediate model provided");
|
||||
}
|
||||
|
||||
return {
|
||||
id: intermediateModel.id,
|
||||
serverid: intermediateModel.serverid,
|
||||
key: intermediateModel.key,
|
||||
value: intermediateModel.value,
|
||||
}
|
||||
}
|
||||
|
||||
protected convertToCreateObject(instance: Partial<ServerConfigurationModel>): object {
|
||||
return {
|
||||
serverid: instance.serverid ?? undefined,
|
||||
key: instance.key ?? undefined,
|
||||
value: instance.value ?? undefined,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,13 @@ import Groups from "./tables/Groups";
|
|||
import {DatabaseDefinition} from "./DatabaseDefinition";
|
||||
import Playdate from "./tables/Playdate";
|
||||
import GroupConfiguration from "./tables/GroupConfiguration";
|
||||
import ServerConfiguration from "./tables/ServerConfiguration";
|
||||
|
||||
const definitions = new Set<DatabaseDefinition>([
|
||||
Groups,
|
||||
Playdate,
|
||||
GroupConfiguration
|
||||
GroupConfiguration,
|
||||
ServerConfiguration
|
||||
]);
|
||||
|
||||
export default definitions;
|
||||
37
source/Database/tables/ServerConfiguration.ts
Normal file
37
source/Database/tables/ServerConfiguration.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import {DatabaseDefinition} from "../DatabaseDefinition";
|
||||
|
||||
export type DBServerConfiguration = {
|
||||
id: number;
|
||||
serverid: string;
|
||||
key: string,
|
||||
value: string
|
||||
}
|
||||
|
||||
const dbDefinition: DatabaseDefinition = {
|
||||
name: "serverConfiguration",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "INTEGER",
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
},
|
||||
{
|
||||
name: "serverid",
|
||||
type: "VARCHAR",
|
||||
size: 32
|
||||
},
|
||||
{
|
||||
name: "key",
|
||||
type: "VARCHAR",
|
||||
size: 32
|
||||
},
|
||||
{
|
||||
name: "value",
|
||||
type: "VARCHAR",
|
||||
size: 2 ^ 11
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export default dbDefinition;
|
||||
Loading…
Add table
Add a link
Reference in a new issue