返回提交历史
Modified
.eslintrc
+2
-1
Modified
src/controllers/api/getGuildDojoController.ts
+12
-4
Added
src/controllers/api/startDojoRecipeController.ts
+28
-0
Modified
src/models/guildModel.ts
+3
-0
Modified
src/routes/api.ts
+2
-0
Added
src/services/guildService.ts
+18
-0
Modified
src/types/guildTypes.ts
+12
-6
XFEstudio/SpaceNinjaServer
feat: implement startDojoRecipeController to place new rooms in Dojo (#273)
Co-authored-by: Sainan <Sainan@users.noreply.github.com>
e35a7fd6
代码差异
7 个文件
+77
-11
@@ -24,7 +24,8 @@
24
24
"@typescript-eslint/no-unsafe-assignment": "warn",
25
25
"@typescript-eslint/no-explicit-any": "warn",
26
26
"@typescript-eslint/no-loss-of-precision": "warn",
27
"no-case-declarations": "warn"
27
"no-case-declarations": "warn",
28
"no-mixed-spaces-and-tabs": "warn"
28
29
},
29
30
"parser": "@typescript-eslint/parser",
30
31
"parserOptions": {
@@ -1,7 +1,7 @@
1
1
import { RequestHandler } from "express";
2
2
import { Types } from "mongoose";
3
3
import { Guild } from "@/src/models/guildModel";
4
import { IDojoClient } from "@/src/types/guildTypes";
4
import { IDojoClient, IDojoComponentClient } from "@/src/types/guildTypes";
5
5
import { toOid, toMongoDate } from "@/src/helpers/inventoryHelpers";
6
6
7
7
export const getGuildDojoController: RequestHandler = async (req, res) => {
@@ -39,13 +39,21 @@ export const getGuildDojoController: RequestHandler = async (req, res) => {
39
39
DojoComponents: []
40
40
};
41
41
guild.DojoComponents.forEach(dojoComponent => {
42
dojo.DojoComponents.push({
42
const clientComponent: IDojoComponentClient = {
43
43
id: toOid(dojoComponent._id),
44
44
pf: dojoComponent.pf,
45
45
ppf: dojoComponent.ppf,
46
CompletionTime: toMongoDate(dojoComponent.CompletionTime),
47
46
DecoCapacity: 600
48
});
47
};
48
if (dojoComponent.pi) {
49
clientComponent.pi = toOid(dojoComponent.pi);
50
clientComponent.op = dojoComponent.op!;
51
clientComponent.pp = dojoComponent.pp!;
52
}
53
if (dojoComponent.CompletionTime) {
54
clientComponent.CompletionTime = toMongoDate(dojoComponent.CompletionTime);
55
}
56
dojo.DojoComponents.push(clientComponent);
49
57
});
50
58
res.json(dojo);
51
59
};
@@ -0,0 +1,28 @@
1
import { RequestHandler } from "express";
2
import { IDojoComponentClient } from "@/src/types/guildTypes";
3
import { getGuildForRequest } from "@/src/services/guildService";
4
import { Types } from "mongoose";
5
6
interface IStartDojoRecipeRequest {
7
PlacedComponent: IDojoComponentClient;
8
Revision: number;
9
}
10
11
export const startDojoRecipeController: RequestHandler = async (req, res) => {
12
const guild = await getGuildForRequest(req);
13
// At this point, we know that a member of the guild is making this request. Assuming they are allowed to start a build.
14
const request = JSON.parse(req.body.toString()) as IStartDojoRecipeRequest;
15
guild.DojoComponents!.push({
16
_id: new Types.ObjectId(),
17
pf: request.PlacedComponent.pf,
18
ppf: request.PlacedComponent.ppf,
19
pi: new Types.ObjectId(request.PlacedComponent.pi!.$oid),
20
op: request.PlacedComponent.op,
21
pp: request.PlacedComponent.pp,
22
CompletionTime: new Date(Date.now()) // TOOD: Omit this field & handle the "Collecting Materials" state.
23
});
24
await guild.save();
25
res.json({
26
DojoRequestStatus: 0
27
});
28
};
@@ -4,6 +4,9 @@ import { model, Schema } from "mongoose";
4
4
const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
5
5
pf: { type: String, required: true },
6
6
ppf: String,
7
pi: Schema.Types.ObjectId,
8
op: String,
9
pp: String,
7
10
CompletionTime: Date
8
11
});
9
12
@@ -53,6 +53,7 @@ import { guildTechController } from "../controllers/api/guildTechController";
53
53
import { dojoController } from "@/src/controllers/api/dojoController";
54
54
import { getGuildDojoController } from "@/src/controllers/api/getGuildDojoController";
55
55
import { syndicateSacrificeController } from "../controllers/api/syndicateSacrificeController";
56
import { startDojoRecipeController } from "@/src/controllers/api/startDojoRecipeController";
56
57
57
58
const apiRouter = express.Router();
58
59
@@ -116,5 +117,6 @@ apiRouter.post("/sell.php", sellController);
116
117
apiRouter.post("/upgrades.php", upgradesController);
117
118
apiRouter.post("/guildTech.php", guildTechController);
118
119
apiRouter.post("/syndicateSacrifice.php", syndicateSacrificeController);
120
apiRouter.post("/startDojoRecipe.php", startDojoRecipeController);
119
121
120
122
export { apiRouter };
@@ -0,0 +1,18 @@
1
import { Request } from "express";
2
import { getAccountIdForRequest } from "@/src/services/loginService";
3
import { getInventory } from "@/src/services/inventoryService";
4
import { Guild } from "@/src/models/guildModel";
5
6
export const getGuildForRequest = async (req: Request) => {
7
const accountId = await getAccountIdForRequest(req);
8
const inventory = await getInventory(accountId);
9
const guildId = req.query.guildId as string;
10
if (!inventory.GuildId || inventory.GuildId.toString() != guildId) {
11
throw new Error("Account is not in the guild that it has sent a request for");
12
}
13
const guild = await Guild.findOne({ _id: guildId });
14
if (!guild) {
15
throw new Error("Account thinks it is a in guild that doesn't exist");
16
}
17
return guild;
18
};
@@ -1,5 +1,6 @@
1
1
import { Types } from "mongoose";
2
2
import { IOid, IMongoDate } from "@/src/types/commonTypes";
3
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
3
4
4
5
export interface IGuild {
5
6
Name: string;
@@ -31,13 +32,18 @@ export interface IDojoComponentClient {
31
32
id: IOid;
32
33
pf: string;
33
34
ppf: string;
34
CompletionTime: IMongoDate;
35
DecoCapacity: number;
35
pi?: IOid; // Parent ID. N/A to root.
36
op?: string; // "Open Portal"? N/A to root.
37
pp?: string; // "Parent Portal"? N/A to root.
38
RegularCredits?: number; // "Collecting Materials" state: Number of credits that were donated.
39
MiscItems?: IMiscItem[]; // "Collecting Materials" state: Resources that were donated.
40
CompletionTime?: IMongoDate;
41
DecoCapacity?: number;
36
42
}
37
43
38
export interface IDojoComponentDatabase {
44
export interface IDojoComponentDatabase
45
extends Omit<IDojoComponentClient, "id" | "pi" | "CompletionTime" | "DecoCapacity"> {
39
46
_id: Types.ObjectId;
40
pf: string;
41
ppf: string;
42
CompletionTime: Date;
47
pi?: Types.ObjectId;
48
CompletionTime?: Date;
43
49
}