feat(permissions): Adds server permissions
This commit is contained in:
parent
d46bbd84c5
commit
cf9c88a2d6
24 changed files with 415 additions and 69 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue