diff --git a/src/Logger.ts b/src/Logger.ts index fae6c03..13f89f3 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -1,7 +1,6 @@ import config from "config"; import {v4 as uuid} from "uuid"; import Log from "./models/Log"; -import ModelFactory from "./db/ModelFactory"; import {bufferToUUID} from "./Utils"; export default class Logger { @@ -106,7 +105,7 @@ export default class Logger { } if (shouldSaveToDB) { - const log = ModelFactory.get(Log).make({}); + const log = Log.create({}); log.setLevel(level); log.message = computedMsg; log.setError(error); diff --git a/src/auth/AuthGuard.ts b/src/auth/AuthGuard.ts index d213089..46cf1e6 100644 --- a/src/auth/AuthGuard.ts +++ b/src/auth/AuthGuard.ts @@ -32,7 +32,7 @@ export default abstract class AuthGuard
> {
const callbacks: RegisterCallback[] = [];
await MysqlConnectionManager.wrapTransaction(async connection => {
- user = ModelFactory.get(User).make({});
+ user = User.create({});
if (onRegister) {
(await onRegister(connection, user)).forEach(c => callbacks.push(c));
}
diff --git a/src/auth/magic_link/MagicLinkAuthController.ts b/src/auth/magic_link/MagicLinkAuthController.ts
index b749afd..9d01242 100644
--- a/src/auth/magic_link/MagicLinkAuthController.ts
+++ b/src/auth/magic_link/MagicLinkAuthController.ts
@@ -9,7 +9,6 @@ import {AuthError, PendingApprovalAuthError, RegisterCallback} from "../AuthGuar
import geoip from "geoip-lite";
import AuthController from "../AuthController";
import NunjucksComponent from "../../components/NunjucksComponent";
-import ModelFactory from "../../db/ModelFactory";
export default abstract class MagicLinkAuthController extends AuthController {
@@ -23,7 +22,7 @@ export default abstract class MagicLinkAuthController extends AuthController {
await req.authGuard.authenticateOrRegister(req.session!, magicLink, undefined, async (connection, user) => {
const callbacks: RegisterCallback[] = [];
- const userEmail = ModelFactory.get(UserEmail).make({
+ const userEmail = UserEmail.create({
user_id: user.id,
email: magicLink.getEmail(),
});
@@ -84,7 +83,7 @@ export default abstract class MagicLinkAuthController extends AuthController {
if (!userEmail) {
isRegistration = true;
- userEmail = ModelFactory.get(UserEmail).make({
+ userEmail = UserEmail.create({
email: email,
main: true,
});
diff --git a/src/auth/magic_link/MagicLinkController.ts b/src/auth/magic_link/MagicLinkController.ts
index 879be42..0aa6643 100644
--- a/src/auth/magic_link/MagicLinkController.ts
+++ b/src/auth/magic_link/MagicLinkController.ts
@@ -14,7 +14,7 @@ export default abstract class MagicLinkController extends Controller {
Throttler.throttle('magic_link', 1, MagicLink.validityPeriod(), email, 0, 0);
const link = await MagicLink.bySessionID(sessionID, actionType) ||
- ModelFactory.get(MagicLink).make({
+ MagicLink.create({
session_id: sessionID,
action_type: actionType,
original_url: original_url,
diff --git a/src/db/Model.ts b/src/db/Model.ts
index 578705e..7843ab2 100644
--- a/src/db/Model.ts
+++ b/src/db/Model.ts
@@ -9,6 +9,10 @@ import ModelQuery, {ModelQueryResult} from "./ModelQuery";
import {Request} from "express";
export default abstract class Model {
+ public static create): Promise extends ModelRelation {
protected readonly dbProperties: RelationDatabaseProperties;
@@ -120,7 +118,6 @@ export class ManyModelRelation extends ModelRe
}
-
export class ManyThroughModelRelation extends ModelRelation {
protected readonly dbProperties: PivotRelationDatabaseProperties;
@@ -163,6 +160,9 @@ export class ManyThroughModelRelation extends
}
+
+export type QueryModifier