-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add planetary events and joint operations (#6)
* feat: add type definitions for `planetEvents` and `jointOperations` * feat: add `Order` model to database * refractor: incorporate the order model into generation service * feat: add dedicated routes for order model * feat: add related routes for order model * fix: rename route collection * feat: add order route collection to routes * refractor: updated postman collection
- Loading branch information
1 parent
f02acf6
commit c5d45bb
Showing
13 changed files
with
965 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- CreateTable | ||
CREATE TABLE "Order" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"index" INTEGER NOT NULL, | ||
"planetId" INTEGER, | ||
"factionId" INTEGER, | ||
"campaignId" INTEGER, | ||
"eventType" TEXT NOT NULL, | ||
"health" INTEGER NOT NULL, | ||
"maxHealth" INTEGER NOT NULL, | ||
"hqNodeIndex" INTEGER, | ||
"startTime" DATETIME NOT NULL, | ||
"expireTime" DATETIME NOT NULL, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" DATETIME NOT NULL, | ||
CONSTRAINT "Order_planetId_fkey" FOREIGN KEY ("planetId") REFERENCES "Planet" ("id") ON DELETE SET NULL ON UPDATE CASCADE, | ||
CONSTRAINT "Order_factionId_fkey" FOREIGN KEY ("factionId") REFERENCES "Faction" ("id") ON DELETE SET NULL ON UPDATE CASCADE, | ||
CONSTRAINT "Order_campaignId_fkey" FOREIGN KEY ("campaignId") REFERENCES "Campaign" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Order_index_key" ON "Order"("index"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Context } from "hono"; | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
import witCache from "utils/cache"; | ||
import parseIntParam from "utils/params"; | ||
import parseQueryParams from "utils/query"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
export const getOrderById = await witCache(async (ctx: Context) => { | ||
try { | ||
const id = parseIntParam(ctx, "id"); | ||
const query = await parseQueryParams(ctx); | ||
|
||
delete query.orderBy; | ||
delete query.where; | ||
delete query.orderBy; | ||
delete (query as any).skip; | ||
delete (query as any).take; | ||
|
||
const order = await prisma.order.findUnique({ | ||
...(query as any), | ||
where: { id }, | ||
}); | ||
|
||
if (!order) { | ||
ctx.status(404); | ||
return ctx.json({ | ||
data: null, | ||
error: { details: [`Order with id (${id}) not found`] }, | ||
}); | ||
} | ||
|
||
return ctx.json({ data: order, error: null }); | ||
} catch (error: any) { | ||
console.error(error); | ||
ctx.status(500); | ||
return ctx.json({ | ||
data: null, | ||
error: { details: [error.message] }, | ||
}); | ||
} | ||
}); | ||
|
||
export const getAllOrders = await witCache(async (ctx: Context) => { | ||
try { | ||
const query = await parseQueryParams(ctx); | ||
|
||
const [count, orders] = await Promise.all([ | ||
prisma.order.count({ where: query.where }), | ||
prisma.order.findMany(query), | ||
]); | ||
|
||
return ctx.json({ | ||
data: orders, | ||
error: null, | ||
pagination: { | ||
page: query.skip / query.take + 1, | ||
pageSize: query.take, | ||
pageCount: Math.ceil((count as number) / query.take), | ||
total: count, | ||
}, | ||
}); | ||
} catch (error: any) { | ||
console.error(error); | ||
ctx.status(500); | ||
return ctx.json({ | ||
data: null, | ||
error: { details: [error.message] }, | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Hono } from "hono"; | ||
|
||
import * as Orders from "controllers/orders"; | ||
|
||
export default async function orders(app: Hono) { | ||
app.get("/orders", Orders.getAllOrders); | ||
app.get("/orders/:id", Orders.getOrderById); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters