Additional assorted layering cleanups

This commit is contained in:
Tau
2019-10-27 11:38:34 -04:00
parent 6a4ac795b2
commit 82bd9ad7bb
22 changed files with 14 additions and 15 deletions

View File

@@ -3,8 +3,6 @@ import logger from "debug";
import { Repositories } from "./repo";
import * as Req from "./request";
import * as Res from "./response";
import { Transaction } from "../sql";
import { SqlRepositories } from "./db";
const debug = logger("app:aimedb:ops");
@@ -103,12 +101,10 @@ function log(
}
export async function dispatch(
txn: Transaction,
rep: Repositories,
req: Req.AimeRequest,
now: Date
): Promise<Res.AimeResponse | undefined> {
const rep = new SqlRepositories(txn);
switch (req.type) {
case "hello":
return hello(rep, req, now);

View File

@@ -2,9 +2,9 @@ import logger from "debug";
import { Socket } from "net";
import { dispatch } from "./handler";
import { AimeRequest } from "./request";
import { setup } from "./pipeline";
import { DataSource } from "../sql/api";
import { SqlRepositories } from "./sql";
const debug = logger("app:aimedb:session");
@@ -17,8 +17,10 @@ export default function aimedb(db: DataSource) {
for await (const obj of input) {
try {
const now = new Date();
const req = obj as AimeRequest;
const res = await db.transaction(txn => dispatch(txn, req, now));
const req = obj;
const res = await db.transaction(txn =>
dispatch(new SqlRepositories(txn), req, now)
);
if (res === undefined) {
debug("Closing connection");

View File

@@ -40,18 +40,14 @@ import { updateTeamMember } from "./updateTeamMember";
import { updateTeamPoints } from "./updateTeamPoints";
import { updateUiReport } from "./updateUiReport";
import { updateUserLog } from "./updateUserLog";
import { Repositories } from "../repo";
import { Request } from "../request";
import { Response } from "../response";
import { Repositories } from "../repo";
import { Transaction } from "../../sql";
import { SqlRepositories } from "../db";
export async function dispatch(
txn: Transaction,
w: Repositories,
req: Request
): Promise<Response> {
const w = new SqlRepositories(txn);
switch (req.type) {
case "check_team_name_req":
return checkTeamName(w, req);

View File

@@ -4,6 +4,7 @@ import { Socket } from "net";
import { dispatch } from "./handler";
import { setup } from "./setup";
import { DataSource } from "../sql";
import { SqlRepositories } from "./sql";
const debug = logger("app:idz:session");
@@ -15,7 +16,11 @@ export default function idz(db: DataSource) {
try {
for await (const req of input) {
output.write(await db.transaction(txn => dispatch(txn, req)));
const res = await db.transaction(txn =>
dispatch(new SqlRepositories(txn), req)
);
output.write(res);
}
} catch (e) {
if (debug.enabled) {