Adds initial progress
This commit is contained in:
commit
a0b668cb90
34 changed files with 2680 additions and 0 deletions
60
source/Container/Services.ts
Normal file
60
source/Container/Services.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import {Environment} from "../Environment";
|
||||
import {Container} from "./Container";
|
||||
import {DatabaseConnection} from "../Database/DatabaseConnection";
|
||||
import {getLogger, configure, Logger} from "log4js";
|
||||
import path from "node:path";
|
||||
import {GroupRepository} from "../Repositories/GroupRepository";
|
||||
import {PlaydateRepository} from "../Repositories/PlaydateRepository";
|
||||
import {GuildEmojiRoleManager} from "discord.js";
|
||||
|
||||
export enum ServiceHint {
|
||||
App,
|
||||
Deploy
|
||||
}
|
||||
|
||||
export class Services {
|
||||
public static setup(container: Container, hint: ServiceHint) {
|
||||
const env = new Environment();
|
||||
env.setup();
|
||||
container.set<Environment>(env);
|
||||
|
||||
const database = new DatabaseConnection(env.database);
|
||||
container.set<DatabaseConnection>(database);
|
||||
|
||||
// @ts-ignore
|
||||
configure({
|
||||
appenders: {
|
||||
out: { type: "stdout" },
|
||||
appLogFile: { type: "file", filename: path.resolve("logs/run.log")},
|
||||
deployLogFile: { type: "file", filename: path.resolve("logs/deploy.log")},
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ['out'], level: 'debug' },
|
||||
app: { appenders: ["out", "appLogFile"], level: "debug" },
|
||||
deploy: { appenders: ["out", "deployLogFile"], level: "debug" },
|
||||
}
|
||||
})
|
||||
|
||||
let loggername = '';
|
||||
switch (hint) {
|
||||
case ServiceHint.App:
|
||||
loggername = "app";
|
||||
break;
|
||||
case ServiceHint.Deploy:
|
||||
loggername = "deploy";
|
||||
break;
|
||||
|
||||
}
|
||||
const logger = getLogger(loggername);
|
||||
|
||||
container.set<Logger>(logger, 'logger');
|
||||
|
||||
this.setupRepositories(container);
|
||||
}
|
||||
|
||||
private static setupRepositories(container: Container) {
|
||||
const db = container.get<DatabaseConnection>(DatabaseConnection.name);
|
||||
container.set<GroupRepository>(new GroupRepository(db));
|
||||
container.set<PlaydateRepository>(new PlaydateRepository(db, container.get<GroupRepository>(GroupRepository.name)))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue