Store dojo components in database as subdocument array
This commit is contained in:
parent
51ea9d5ca1
commit
9aa8213f7b
@ -1,28 +0,0 @@
|
|||||||
import { RequestHandler } from "express";
|
|
||||||
import { IDojoClient } from "@/src/types/guildTypes";
|
|
||||||
|
|
||||||
export const createGuildDojoController: RequestHandler = (req, res) => {
|
|
||||||
// req.body.toString() -> {"SpawnComponent":{"id":{"$oid":"000000000000000000000000"},"pf":"/Lotus/Levels/ClanDojo/DojoHall.level","ppf":""}}
|
|
||||||
|
|
||||||
// I'm guessing the response is same as getGuildDojo.php, which responds like this for a fresh dojo:
|
|
||||||
res.json({
|
|
||||||
_id: { $oid: req.params.guildId },
|
|
||||||
Name: "If you can read this in-game, tell me I need to fetch the clan name from the DB, lol.",
|
|
||||||
Tier: 1,
|
|
||||||
FixedContributions: true,
|
|
||||||
DojoRevision: 1,
|
|
||||||
RevisionTime: Math.round(Date.now() / 1000),
|
|
||||||
Energy: 5,
|
|
||||||
Capacity: 100,
|
|
||||||
DojoRequestStatus: 0,
|
|
||||||
DojoComponents: [
|
|
||||||
{
|
|
||||||
pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
|
|
||||||
ppf: "",
|
|
||||||
id: { $oid: "000000000000000000000000" },
|
|
||||||
CompletionTime: { $date: { $numberLong: "" + Date.now() } },
|
|
||||||
DecoCapacity: 600
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} satisfies IDojoClient);
|
|
||||||
};
|
|
@ -1,5 +1,51 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
import { Guild } from "@/src/models/guildModel";
|
||||||
|
import { IDojoClient } from "@/src/types/guildTypes";
|
||||||
|
import { toOid, toMongoDate } from "@/src/helpers/inventoryHelpers";
|
||||||
|
|
||||||
export const getGuildDojoController: RequestHandler = (_req, res) => {
|
export const getGuildDojoController: RequestHandler = async (req, res) => {
|
||||||
res.json({}); // This is what I got for a fresh clan.
|
const guildId = req.query.guildId as string;
|
||||||
|
|
||||||
|
const guild = await Guild.findOne({ _id: guildId });
|
||||||
|
if (!guild) {
|
||||||
|
res.status(404).end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate dojo info if not present
|
||||||
|
if (!guild.DojoComponents || guild.DojoComponents.length == 0) {
|
||||||
|
guild.DojoComponents = [
|
||||||
|
{
|
||||||
|
_id: new Types.ObjectId(),
|
||||||
|
pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
|
||||||
|
ppf: "",
|
||||||
|
CompletionTime: new Date(Date.now())
|
||||||
|
}
|
||||||
|
];
|
||||||
|
guild.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
const dojo: IDojoClient = {
|
||||||
|
_id: { $oid: guildId },
|
||||||
|
Name: guild.Name,
|
||||||
|
Tier: 1,
|
||||||
|
FixedContributions: true,
|
||||||
|
DojoRevision: 1,
|
||||||
|
RevisionTime: Math.round(Date.now() / 1000),
|
||||||
|
Energy: 5,
|
||||||
|
Capacity: 100,
|
||||||
|
DojoRequestStatus: 0,
|
||||||
|
DojoComponents: []
|
||||||
|
};
|
||||||
|
guild.DojoComponents.forEach(dojoComponent => {
|
||||||
|
dojo.DojoComponents.push({
|
||||||
|
id: toOid(dojoComponent._id),
|
||||||
|
pf: dojoComponent.pf,
|
||||||
|
ppf: dojoComponent.ppf,
|
||||||
|
CompletionTime: toMongoDate(dojoComponent.CompletionTime),
|
||||||
|
DecoCapacity: 600
|
||||||
|
});
|
||||||
|
});
|
||||||
|
res.json(dojo);
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
import { IGuild } from "@/src/types/guildTypes";
|
import { IGuildDatabase, IDojoComponentDatabase } from "@/src/types/guildTypes";
|
||||||
import { model, Schema } from "mongoose";
|
import { model, Schema } from "mongoose";
|
||||||
import { toOid } from "@/src/helpers/inventoryHelpers";
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||||
|
|
||||||
const guildSchema = new Schema<IGuild>(
|
const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
|
||||||
|
pf: { type: String, required: true },
|
||||||
|
ppf: String,
|
||||||
|
CompletionTime: Date
|
||||||
|
});
|
||||||
|
|
||||||
|
const guildSchema = new Schema<IGuildDatabase>(
|
||||||
{
|
{
|
||||||
Name: { type: String, required: true }
|
Name: { type: String, required: true },
|
||||||
|
DojoComponents: [dojoComponentSchema]
|
||||||
},
|
},
|
||||||
{ id: false }
|
{ id: false }
|
||||||
);
|
);
|
||||||
@ -17,4 +24,4 @@ guildSchema.set("toJSON", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Guild = model<IGuild>("Guild", guildSchema);
|
export const Guild = model<IGuildDatabase>("Guild", guildSchema);
|
||||||
|
@ -52,7 +52,6 @@ import { getGuildLogController } from "../controllers/api/getGuildLogController"
|
|||||||
import { guildTechController } from "../controllers/api/guildTechController";
|
import { guildTechController } from "../controllers/api/guildTechController";
|
||||||
import { dojoController } from "@/src/controllers/api/dojoController";
|
import { dojoController } from "@/src/controllers/api/dojoController";
|
||||||
import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoController";
|
import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoController";
|
||||||
import { createGuildDojoController } from "@/src/controllers/api/createGuildDojoController";
|
|
||||||
|
|
||||||
const apiRouter = express.Router();
|
const apiRouter = express.Router();
|
||||||
|
|
||||||
@ -115,6 +114,5 @@ apiRouter.post("/createGuild.php", createGuildController);
|
|||||||
apiRouter.post("/sell.php", sellController);
|
apiRouter.post("/sell.php", sellController);
|
||||||
apiRouter.post("/upgrades.php", upgradesController);
|
apiRouter.post("/upgrades.php", upgradesController);
|
||||||
apiRouter.post("/guildTech.php", guildTechController);
|
apiRouter.post("/guildTech.php", guildTechController);
|
||||||
apiRouter.post("/createGuildDojo.php", createGuildDojoController);
|
|
||||||
|
|
||||||
export { apiRouter };
|
export { apiRouter };
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
|
import { Types } from "mongoose";
|
||||||
import { IOid, IMongoDate } from "@/src/types/commonTypes";
|
import { IOid, IMongoDate } from "@/src/types/commonTypes";
|
||||||
|
|
||||||
export interface IGuild {
|
export interface IGuild {
|
||||||
Name: string;
|
Name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IGuildDatabase extends IGuild {
|
||||||
|
_id: Types.ObjectId;
|
||||||
|
DojoComponents?: IDojoComponentDatabase[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICreateGuildRequest {
|
export interface ICreateGuildRequest {
|
||||||
guildName: string;
|
guildName: string;
|
||||||
}
|
}
|
||||||
@ -22,9 +28,16 @@ export interface IDojoClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IDojoComponentClient {
|
export interface IDojoComponentClient {
|
||||||
|
id: IOid;
|
||||||
pf: string;
|
pf: string;
|
||||||
ppf: string;
|
ppf: string;
|
||||||
id: IOid;
|
|
||||||
CompletionTime: IMongoDate;
|
CompletionTime: IMongoDate;
|
||||||
DecoCapacity: number;
|
DecoCapacity: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IDojoComponentDatabase {
|
||||||
|
_id: Types.ObjectId;
|
||||||
|
pf: string;
|
||||||
|
ppf: string;
|
||||||
|
CompletionTime: Date;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user