XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: turn guild DojoComponents into a DocumentArray (#1070)

and use .id for setDojoComponentMessage Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1070

36d12e08
Sainan <sainan@calamity.inc>
提交于

代码差异

8 个文件 +36 -27
Modified src/controllers/api/changeDojoRootController.ts +3 -3
@@ -9,7 +9,7 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
9 9 // At this point, we know that a member of the guild is making this request. Assuming they are allowed to change the root.
10 10
11 11 const idToNode: Record<string, INode> = {};
12 guild.DojoComponents!.forEach(x => {
12 guild.DojoComponents.forEach(x => {
13 13 idToNode[x._id.toString()] = {
14 14 component: x,
15 15 parent: undefined,
@@ -18,7 +18,7 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
18 18 });
19 19
20 20 let oldRoot: INode | undefined;
21 guild.DojoComponents!.forEach(x => {
21 guild.DojoComponents.forEach(x => {
22 22 const node = idToNode[x._id.toString()];
23 23 if (x.pi) {
24 24 idToNode[x.pi.toString()].children.push(node);
@@ -47,7 +47,7 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
47 47 );
48 48 top.children.forEach(x => stack.push(x));
49 49 }
50 guild.DojoComponents!.forEach(x => {
50 guild.DojoComponents.forEach(x => {
51 51 x._id = idMap[x._id.toString()];
52 52 if (x.pi) {
53 53 x.pi = idMap[x.pi.toString()];
Modified src/controllers/api/getGuildDojoController.ts +3 -3
@@ -13,15 +13,15 @@ export const getGuildDojoController: RequestHandler = async (req, res) => {
13 13 }
14 14
15 15 // Populate dojo info if not present
16 if (!guild.DojoComponents || guild.DojoComponents.length == 0) {
17 guild.DojoComponents = [
16 if (guild.DojoComponents.length == 0) {
17 guild.DojoComponents.push([
18 18 {
19 19 _id: new Types.ObjectId(),
20 20 pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
21 21 ppf: "",
22 22 CompletionTime: new Date(Date.now())
23 23 }
24 ];
24 ]);
25 25 await guild.save();
26 26 }
27 27
Modified src/controllers/api/queueDojoComponentDestructionController.ts +2 -2
@@ -5,8 +5,8 @@ import { ExportDojoRecipes } from "warframe-public-export-plus";
5 5 export const queueDojoComponentDestructionController: RequestHandler = async (req, res) => {
6 6 const guild = await getGuildForRequest(req);
7 7 const componentId = req.query.componentId as string;
8 const component = guild.DojoComponents!.splice(
9 guild.DojoComponents!.findIndex(x => x._id.toString() === componentId),
8 const component = guild.DojoComponents.splice(
9 guild.DojoComponents.findIndex(x => x._id.toString() === componentId),
10 10 1
11 11 )[0];
12 12 const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
Modified src/controllers/api/setDojoComponentMessageController.ts +1 -1
@@ -4,7 +4,7 @@ import { getDojoClient, getGuildForRequest } from "@/src/services/guildService";
4 4 export const setDojoComponentMessageController: RequestHandler = async (req, res) => {
5 5 const guild = await getGuildForRequest(req);
6 6 // At this point, we know that a member of the guild is making this request. Assuming they are allowed to change the message.
7 const component = guild.DojoComponents!.find(x => x._id.equals(req.query.componentId as string))!;
7 const component = guild.DojoComponents.id(req.query.componentId as string)!;
8 8 const payload = JSON.parse(String(req.body)) as SetDojoComponentMessageRequest;
9 9 if ("Name" in payload) {
10 10 component.Name = payload.Name;
Modified src/controllers/api/startDojoRecipeController.ts +1 -1
@@ -20,7 +20,7 @@ export const startDojoRecipeController: RequestHandler = async (req, res) => {
20 20 guild.DojoEnergy += room.energy;
21 21 }
22 22
23 guild.DojoComponents!.push({
23 guild.DojoComponents.push({
24 24 _id: new Types.ObjectId(),
25 25 pf: request.PlacedComponent.pf,
26 26 ppf: request.PlacedComponent.ppf,
Modified src/models/guildModel.ts +22 -3
@@ -4,7 +4,7 @@ import {
4 4 ITechProjectDatabase,
5 5 ITechProjectClient
6 6 } from "@/src/types/guildTypes";
7 import { model, Schema } from "mongoose";
7 import { Document, Model, model, Schema, Types } from "mongoose";
8 8 import { typeCountSchema } from "./inventoryModels/inventoryModel";
9 9 import { toMongoDate } from "../helpers/inventoryHelpers";
10 10
@@ -44,7 +44,7 @@ techProjectSchema.set("toJSON", {
44 44 const guildSchema = new Schema<IGuildDatabase>(
45 45 {
46 46 Name: { type: String, required: true },
47 DojoComponents: [dojoComponentSchema],
47 DojoComponents: { type: [dojoComponentSchema], default: [] },
48 48 DojoCapacity: { type: Number, default: 100 },
49 49 DojoEnergy: { type: Number, default: 5 },
50 50 TechProjects: { type: [techProjectSchema], default: undefined }
@@ -52,4 +52,23 @@ const guildSchema = new Schema<IGuildDatabase>(
52 52 { id: false }
53 53 );
54 54
55 export const Guild = model<IGuildDatabase>("Guild", guildSchema);
55 type GuildDocumentProps = {
56 DojoComponents: Types.DocumentArray<IDojoComponentDatabase>;
57 };
58
59 // eslint-disable-next-line @typescript-eslint/ban-types
60 type GuildModel = Model<IGuildDatabase, {}, GuildDocumentProps>;
61
62 export const Guild = model<IGuildDatabase, GuildModel>("Guild", guildSchema);
63
64 // eslint-disable-next-line @typescript-eslint/ban-types
65 export type TGuildDatabaseDocument = Document<unknown, {}, IGuildDatabase> &
66 Omit<
67 IGuildDatabase & {
68 _id: Types.ObjectId;
69 } & {
70 __v: number;
71 },
72 keyof GuildDocumentProps
73 > &
74 GuildDocumentProps;
Modified src/services/guildService.ts +3 -13
@@ -1,10 +1,9 @@
1 1 import { Request } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { getInventory } from "@/src/services/inventoryService";
4 import { Guild } from "@/src/models/guildModel";
4 import { Guild, TGuildDatabaseDocument } from "@/src/models/guildModel";
5 5 import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
6 import { IDojoClient, IDojoComponentClient, IGuildDatabase } from "@/src/types/guildTypes";
7 import { Document, Types } from "mongoose";
6 import { IDojoClient, IDojoComponentClient } from "@/src/types/guildTypes";
8 7 import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
9 8
10 9 export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
@@ -41,7 +40,7 @@ export const getDojoClient = (guild: TGuildDatabaseDocument, status: number): ID
41 40 DojoRequestStatus: status,
42 41 DojoComponents: []
43 42 };
44 guild.DojoComponents!.forEach(dojoComponent => {
43 guild.DojoComponents.forEach(dojoComponent => {
45 44 const clientComponent: IDojoComponentClient = {
46 45 id: toOid(dojoComponent._id),
47 46 pf: dojoComponent.pf,
@@ -62,12 +61,3 @@ export const getDojoClient = (guild: TGuildDatabaseDocument, status: number): ID
62 61 });
63 62 return dojo;
64 63 };
65
66 // eslint-disable-next-line @typescript-eslint/ban-types
67 export type TGuildDatabaseDocument = Document<unknown, {}, IGuildDatabase> &
68 IGuildDatabase &
69 Required<{
70 _id: Types.ObjectId;
71 }> & {
72 __v: number;
73 };
Modified src/types/guildTypes.ts +1 -1
@@ -8,7 +8,7 @@ export interface IGuild {
8 8
9 9 export interface IGuildDatabase extends IGuild {
10 10 _id: Types.ObjectId;
11 DojoComponents?: IDojoComponentDatabase[];
11 DojoComponents: IDojoComponentDatabase[];
12 12 DojoCapacity: number;
13 13 DojoEnergy: number;
14 14 TechProjects?: ITechProjectDatabase[];