feat: more work on clans (#214)
Co-authored-by: Sainan <Sainan@users.noreply.github.com>
This commit is contained in:
parent
6dd5ceabde
commit
63712121af
@ -2,7 +2,7 @@ import { RequestHandler } from "express";
|
|||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
||||||
import { Guild } from "@/src/models/guildModel";
|
import { Guild } from "@/src/models/guildModel";
|
||||||
import { IGuild, ICreateGuildRequest } from "@/src/types/guildTypes";
|
import { ICreateGuildRequest } from "@/src/types/guildTypes";
|
||||||
|
|
||||||
const createGuildController: RequestHandler = async (req, res) => {
|
const createGuildController: RequestHandler = async (req, res) => {
|
||||||
const payload: ICreateGuildRequest = getJSONfromString(req.body.toString());
|
const payload: ICreateGuildRequest = getJSONfromString(req.body.toString());
|
||||||
@ -10,7 +10,7 @@ const createGuildController: RequestHandler = async (req, res) => {
|
|||||||
// Create guild on database
|
// Create guild on database
|
||||||
const guild = new Guild({
|
const guild = new Guild({
|
||||||
Name: payload.guildName
|
Name: payload.guildName
|
||||||
} satisfies IGuild);
|
});
|
||||||
await guild.save();
|
await guild.save();
|
||||||
|
|
||||||
// Update inventory
|
// Update inventory
|
||||||
@ -19,7 +19,7 @@ const createGuildController: RequestHandler = async (req, res) => {
|
|||||||
// Set GuildId
|
// Set GuildId
|
||||||
inventory.GuildId = guild._id;
|
inventory.GuildId = guild._id;
|
||||||
|
|
||||||
// Give clan key
|
// Give clan key (TODO: This should only be a blueprint)
|
||||||
inventory.LevelKeys ??= [];
|
inventory.LevelKeys ??= [];
|
||||||
inventory.LevelKeys.push({
|
inventory.LevelKeys.push({
|
||||||
ItemType: "/Lotus/Types/Keys/DojoKey",
|
ItemType: "/Lotus/Types/Keys/DojoKey",
|
||||||
|
5
src/controllers/api/dojoController.ts
Normal file
5
src/controllers/api/dojoController.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
|
export const dojoController: RequestHandler = (_req, res) => {
|
||||||
|
res.json("-1"); // Tell client to use authorised request.
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
|
||||||
import { Guild } from "@/src/models/guildModel";
|
import { Guild } from "@/src/models/guildModel";
|
||||||
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||||
|
|
||||||
const getGuildController: RequestHandler = async (req, res) => {
|
const getGuildController: RequestHandler = async (req, res) => {
|
||||||
if (!req.query.accountId) {
|
if (!req.query.accountId) {
|
||||||
@ -15,7 +16,56 @@ const getGuildController: RequestHandler = async (req, res) => {
|
|||||||
if (inventory.GuildId) {
|
if (inventory.GuildId) {
|
||||||
const guild = await Guild.findOne({ _id: inventory.GuildId });
|
const guild = await Guild.findOne({ _id: inventory.GuildId });
|
||||||
if (guild) {
|
if (guild) {
|
||||||
res.json(guild);
|
res.json({
|
||||||
|
_id: toOid(guild._id),
|
||||||
|
Name: guild.Name,
|
||||||
|
Members: [
|
||||||
|
{
|
||||||
|
_id: { $oid: req.query.accountId },
|
||||||
|
Rank: 0,
|
||||||
|
Status: 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
Ranks: [
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Creator",
|
||||||
|
Permissions: 16351
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Warlord",
|
||||||
|
Permissions: 14303
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_General",
|
||||||
|
Permissions: 4318
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Officer",
|
||||||
|
Permissions: 4314
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Leader",
|
||||||
|
Permissions: 4106
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Sage",
|
||||||
|
Permissions: 4304
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Soldier",
|
||||||
|
Permissions: 4098
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Initiate",
|
||||||
|
Permissions: 4096
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "/Lotus/Language/Game/Rank_Utility",
|
||||||
|
Permissions: 4096
|
||||||
|
}
|
||||||
|
],
|
||||||
|
Tier: 1
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
51
src/controllers/api/getGuildDojoController.ts
Normal file
51
src/controllers/api/getGuildDojoController.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
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 = async (req, res) => {
|
||||||
|
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);
|
||||||
|
};
|
11
src/controllers/api/getGuildLogController.ts
Normal file
11
src/controllers/api/getGuildLogController.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
|
export const getGuildLogController: RequestHandler = (_req, res) => {
|
||||||
|
res.json({
|
||||||
|
RoomChanges: [],
|
||||||
|
TechChanges: [],
|
||||||
|
RosterActivity: [],
|
||||||
|
StandingsUpdates: [],
|
||||||
|
ClassChanges: []
|
||||||
|
});
|
||||||
|
};
|
5
src/controllers/api/guildTechController.ts
Normal file
5
src/controllers/api/guildTechController.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
|
export const guildTechController: RequestHandler = (_req, res) => {
|
||||||
|
res.status(500).end(); // This is what I got for a fresh clan.
|
||||||
|
};
|
@ -1,16 +1,18 @@
|
|||||||
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";
|
|
||||||
|
|
||||||
const guildSchema = new Schema<IGuild>({
|
const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
|
||||||
Name: { type: String, required: true }
|
pf: { type: String, required: true },
|
||||||
|
ppf: String,
|
||||||
|
CompletionTime: Date
|
||||||
});
|
});
|
||||||
|
|
||||||
guildSchema.set("toJSON", {
|
const guildSchema = new Schema<IGuildDatabase>(
|
||||||
virtuals: true,
|
{
|
||||||
transform(_document, guild) {
|
Name: { type: String, required: true },
|
||||||
guild._id = toOid(guild._id);
|
DojoComponents: [dojoComponentSchema]
|
||||||
}
|
},
|
||||||
});
|
{ id: false }
|
||||||
|
);
|
||||||
|
|
||||||
export const Guild = model<IGuild>("Guild", guildSchema);
|
export const Guild = model<IGuildDatabase>("Guild", guildSchema);
|
||||||
|
@ -48,6 +48,10 @@ import { sellController } from "@/src/controllers/api/sellController";
|
|||||||
import { upgradesController } from "@/src/controllers/api/upgradesController";
|
import { upgradesController } from "@/src/controllers/api/upgradesController";
|
||||||
import { setSupportedSyndicateController } from "@/src/controllers/api/setSupportedSyndicateController";
|
import { setSupportedSyndicateController } from "@/src/controllers/api/setSupportedSyndicateController";
|
||||||
import { getDailyDealStockLevelsController } from "@/src/controllers/api/getDailyDealStockLevelsController";
|
import { getDailyDealStockLevelsController } from "@/src/controllers/api/getDailyDealStockLevelsController";
|
||||||
|
import { getGuildLogController } from "../controllers/api/getGuildLogController";
|
||||||
|
import { guildTechController } from "../controllers/api/guildTechController";
|
||||||
|
import { dojoController } from "@/src/controllers/api/dojoController";
|
||||||
|
import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoController";
|
||||||
|
|
||||||
const apiRouter = express.Router();
|
const apiRouter = express.Router();
|
||||||
|
|
||||||
@ -77,6 +81,9 @@ apiRouter.get("/setActiveShip.php", setActiveShipController);
|
|||||||
apiRouter.get("/getGuild.php", getGuildController);
|
apiRouter.get("/getGuild.php", getGuildController);
|
||||||
apiRouter.get("/setSupportedSyndicate.php", setSupportedSyndicateController);
|
apiRouter.get("/setSupportedSyndicate.php", setSupportedSyndicateController);
|
||||||
apiRouter.get("/getDailyDealStockLevels.php", getDailyDealStockLevelsController);
|
apiRouter.get("/getDailyDealStockLevels.php", getDailyDealStockLevelsController);
|
||||||
|
apiRouter.get("/getGuildLog.php", getGuildLogController);
|
||||||
|
apiRouter.get("/dojo", dojoController);
|
||||||
|
apiRouter.get("/getGuildDojo.php", getGuildDojoController);
|
||||||
|
|
||||||
// post
|
// post
|
||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
@ -106,5 +113,6 @@ apiRouter.post("/addFriendImage.php", addFriendImageController);
|
|||||||
apiRouter.post("/createGuild.php", createGuildController);
|
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);
|
||||||
|
|
||||||
export { apiRouter };
|
export { apiRouter };
|
||||||
|
@ -1,7 +1,43 @@
|
|||||||
|
import { Types } from "mongoose";
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IDojoClient {
|
||||||
|
_id: IOid; // ID of the guild
|
||||||
|
Name: string;
|
||||||
|
Tier: number;
|
||||||
|
FixedContributions: boolean;
|
||||||
|
DojoRevision: number;
|
||||||
|
RevisionTime: number;
|
||||||
|
Energy: number;
|
||||||
|
Capacity: number;
|
||||||
|
DojoRequestStatus: number;
|
||||||
|
DojoComponents: IDojoComponentClient[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IDojoComponentClient {
|
||||||
|
id: IOid;
|
||||||
|
pf: string;
|
||||||
|
ppf: string;
|
||||||
|
CompletionTime: IMongoDate;
|
||||||
|
DecoCapacity: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IDojoComponentDatabase {
|
||||||
|
_id: Types.ObjectId;
|
||||||
|
pf: string;
|
||||||
|
ppf: string;
|
||||||
|
CompletionTime: Date;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user