Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/controllers/assignments.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Context } from "hono";
import { PrismaClient } from "@prisma/client";

import { db } from "utils/database";
import parseIntParam from "utils/params";
import witCache from "utils/request-cache";
import parseQueryParams from "utils/query";

const prisma = new PrismaClient();

export const getAssignmentById = await witCache(async (ctx: Context) => {
try {
const id = parseIntParam(ctx, "id");
Expand All @@ -18,7 +16,7 @@ export const getAssignmentById = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const assignment = await prisma.assignment.findUnique({
const assignment = await db.assignment.findUnique({
...(query as any),
where: { id },
});
Expand Down Expand Up @@ -47,8 +45,8 @@ export const getAllAssignments = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, assignments] = await Promise.all([
prisma.assignment.count({ where: query.where }),
prisma.assignment.findMany(query),
db.assignment.count({ where: query.where }),
db.assignment.findMany(query),
]);

return ctx.json({
Expand Down Expand Up @@ -82,7 +80,7 @@ export const getAssignmentReward = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const reward = await prisma.reward.findFirst({
const reward = await db.reward.findFirst({
where: { assignment: { id } },
});

Expand Down
14 changes: 6 additions & 8 deletions src/controllers/attacks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Context } from "hono";
import { PrismaClient } from "@prisma/client";

import { db } from "utils/database";
import parseIntParam from "utils/params";
import witCache from "utils/request-cache";
import parseQueryParams from "utils/query";

const prisma = new PrismaClient();

export const getAttackById = await witCache(async (ctx: Context) => {
try {
const id = parseIntParam(ctx, "id");
Expand All @@ -18,7 +16,7 @@ export const getAttackById = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const attack = await prisma.attack.findUnique({
const attack = await db.attack.findUnique({
...(query as any),
where: { id },
});
Expand Down Expand Up @@ -47,8 +45,8 @@ export const getAllAttacks = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, attacks] = await Promise.all([
prisma.attack.count({ where: query.where }),
prisma.attack.findMany(query),
db.attack.count({ where: query.where }),
db.attack.findMany(query),
]);

return ctx.json({
Expand Down Expand Up @@ -83,10 +81,10 @@ export const getPlanetsByAttack = await witCache(async (ctx: Context) => {
delete (query as any).take;

const [target, source] = await Promise.all([
prisma.planet.findFirst({
db.planet.findFirst({
where: { attacking: { some: { id } } },
}),
prisma.planet.findFirst({
db.planet.findFirst({
where: { defending: { some: { id } } },
}),
]);
Expand Down
10 changes: 4 additions & 6 deletions src/controllers/events.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Context } from "hono";
import { PrismaClient } from "@prisma/client";

import { db } from "utils/database";
import parseIntParam from "utils/params";
import witCache from "utils/request-cache";
import parseQueryParams from "utils/query";

const prisma = new PrismaClient();

export const getEventById = await witCache(async (ctx: Context) => {
try {
const id = parseIntParam(ctx, "id");
Expand All @@ -18,7 +16,7 @@ export const getEventById = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const event = await prisma.globalEvent.findUnique({
const event = await db.globalEvent.findUnique({
...(query as any),
where: { id },
});
Expand Down Expand Up @@ -47,8 +45,8 @@ export const getAllEvents = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, events] = await Promise.all([
prisma.globalEvent.count({ where: query.where }),
prisma.globalEvent.findMany(query),
db.globalEvent.count({ where: query.where }),
db.globalEvent.findMany(query),
]);

return ctx.json({
Expand Down
24 changes: 11 additions & 13 deletions src/controllers/factions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Context } from "hono";
import { PrismaClient } from "@prisma/client";

import { db } from "utils/database";
import parseIntParam from "utils/params";
import witCache from "utils/request-cache";
import parseQueryParams from "utils/query";

const prisma = new PrismaClient();

export const getFactionById = await witCache(async (ctx: Context) => {
try {
const id = parseIntParam(ctx, "id");
Expand All @@ -18,7 +16,7 @@ export const getFactionById = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const faction = await prisma.faction.findUnique({
const faction = await db.faction.findUnique({
...(query as any),
where: { id },
});
Expand Down Expand Up @@ -47,8 +45,8 @@ export const getAllFactions = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, factions] = await Promise.all([
prisma.faction.count({ where: query.where }),
prisma.faction.findMany(query),
db.faction.count({ where: query.where }),
db.faction.findMany(query),
]);

return ctx.json({
Expand Down Expand Up @@ -77,10 +75,10 @@ export const getFactionPlanets = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, planets] = await Promise.all([
prisma.planet.count({
db.planet.count({
where: { ...(query.where ?? {}), ownerId: id },
}),
prisma.planet.findMany({
db.planet.findMany({
...query,
where: { ...(query.where ?? {}), ownerId: id },
}),
Expand Down Expand Up @@ -112,14 +110,14 @@ export const getFactionPushbacks = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, planets] = await Promise.all([
prisma.planet.count({
db.planet.count({
where: {
...(query.where ?? {}),
ownerId: { not: id },
initialOwnerId: id,
},
}),
prisma.planet.findMany({
db.planet.findMany({
...query,
where: {
...(query.where ?? {}),
Expand Down Expand Up @@ -160,7 +158,7 @@ export const getFactionOrigin = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const planet = await prisma.planet.findFirst({
const planet = await db.planet.findFirst({
...(query as any),
where: { homeWorld: { some: { factionId: id } } },
});
Expand Down Expand Up @@ -192,10 +190,10 @@ export const getFactionOrders = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, orders] = await Promise.all([
prisma.order.count({
db.order.count({
where: { ...(query.where ?? {}), factionId: id },
}),
prisma.order.findMany({
db.order.findMany({
...query,
where: { ...(query.where ?? {}), factionId: id },
}),
Expand Down
10 changes: 4 additions & 6 deletions src/controllers/orders.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Context } from "hono";
import { PrismaClient } from "@prisma/client";

import { db } from "utils/database";
import parseIntParam from "utils/params";
import witCache from "utils/request-cache";
import parseQueryParams from "utils/query";

const prisma = new PrismaClient();

export const getOrderById = await witCache(async (ctx: Context) => {
try {
const id = parseIntParam(ctx, "id");
Expand All @@ -18,7 +16,7 @@ export const getOrderById = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const order = await prisma.order.findUnique({
const order = await db.order.findUnique({
...(query as any),
where: { id },
});
Expand Down Expand Up @@ -47,8 +45,8 @@ export const getAllOrders = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, orders] = await Promise.all([
prisma.order.count({ where: query.where }),
prisma.order.findMany(query),
db.order.count({ where: query.where }),
db.order.findMany(query),
]);

return ctx.json({
Expand Down
28 changes: 13 additions & 15 deletions src/controllers/planets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Context } from "hono";
import { PrismaClient } from "@prisma/client";

import { db } from "utils/database";
import parseIntParam from "utils/params";
import witCache from "utils/request-cache";
import parseQueryParams from "utils/query";

const prisma = new PrismaClient();

export const getPlanetById = await witCache(async (ctx: Context) => {
try {
const id = parseIntParam(ctx, "id");
Expand All @@ -18,7 +16,7 @@ export const getPlanetById = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const planet = await prisma.planet.findUnique({
const planet = await db.planet.findUnique({
...(query as any),
where: { id },
});
Expand Down Expand Up @@ -47,8 +45,8 @@ export const getAllPlanets = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, planets] = await Promise.all([
prisma.planet.count({ where: query.where }),
prisma.planet.findMany(query),
db.planet.count({ where: query.where }),
db.planet.findMany(query),
]);

return ctx.json({
Expand Down Expand Up @@ -77,12 +75,12 @@ export const getPlanetAttacks = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, attacks] = await Promise.all([
prisma.attack.count({
db.attack.count({
where: {
OR: [{ source: { id } }, { target: { id } }],
},
}),
prisma.attack.findMany({
db.attack.findMany({
...(query ?? {}),
where: {
...(query.where as any),
Expand Down Expand Up @@ -130,10 +128,10 @@ export const getPlanetOwners = await witCache(async (ctx: Context) => {
delete (query as any).take;

const [owner, initialOwner] = await Promise.all([
prisma.faction.findFirst({
db.faction.findFirst({
where: { planets: { some: { id } } },
}),
prisma.faction.findFirst({
db.faction.findFirst({
where: { initialPlanets: { some: { id } } },
}),
]);
Expand Down Expand Up @@ -165,10 +163,10 @@ export const getPlanetCampaigns = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, campaigns] = await Promise.all([
prisma.campaign.count({
db.campaign.count({
where: { planetId: id },
}),
prisma.campaign.findMany({
db.campaign.findMany({
...(query ?? {}),
where: { ...(query.where as any), planetId: id },
}),
Expand Down Expand Up @@ -200,10 +198,10 @@ export const getPlanetOrders = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, orders] = await Promise.all([
prisma.order.count({
db.order.count({
where: { planetId: id },
}),
prisma.order.findMany({
db.order.findMany({
...(query ?? {}),
where: { ...(query.where as any), planetId: id },
}),
Expand Down Expand Up @@ -240,7 +238,7 @@ export const getPlanetStatistics = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const stats = await prisma.stats.findFirst({
const stats = await db.stats.findFirst({
...(query as any),
where: { planet: { id } },
});
Expand Down
10 changes: 4 additions & 6 deletions src/controllers/reports.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Context } from "hono";
import { PrismaClient } from "@prisma/client";

import { db } from "utils/database";
import parseIntParam from "utils/params";
import witCache from "utils/request-cache";
import parseQueryParams from "utils/query";

const prisma = new PrismaClient();

export const getReportById = await witCache(async (ctx: Context) => {
try {
const id = parseIntParam(ctx, "id");
Expand All @@ -18,7 +16,7 @@ export const getReportById = await witCache(async (ctx: Context) => {
delete (query as any).skip;
delete (query as any).take;

const report = await prisma.news.findUnique({
const report = await db.news.findUnique({
...(query as any),
where: { id },
});
Expand Down Expand Up @@ -47,8 +45,8 @@ export const getAllReports = await witCache(async (ctx: Context) => {
const query = await parseQueryParams(ctx);

const [count, reports] = await Promise.all([
prisma.news.count({ where: query.where }),
prisma.news.findMany(query),
db.news.count({ where: query.where }),
db.news.findMany(query),
]);

return ctx.json({
Expand Down
Loading