返回提交历史
Modified
src/controllers/api/contributeToDojoComponentController.ts
+24
-12
XFEstudio/XFESpaceNinjaServer
chore: handle dojo contribution requests from U10 (#3470)
Closes #3465 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3470 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
ceddb9da
代码差异
1 个文件
+24
-12
@@ -11,7 +11,7 @@ import {
11
11
setDojoRoomLogFunded
12
12
} from "../../services/guildService.ts";
13
13
import { addMiscItems, getInventory, updateCurrency } from "../../services/inventoryService.ts";
14
import { getAccountIdForRequest } from "../../services/loginService.ts";
14
import { getAccountForRequest } from "../../services/loginService.ts";
15
15
import type { IDojoContributable, IGuildMemberDatabase } from "../../types/guildTypes.ts";
16
16
import type { IMiscItem } from "../../types/inventoryTypes/inventoryTypes.ts";
17
17
import type { IInventoryChanges } from "../../types/purchaseTypes.ts";
@@ -20,18 +20,24 @@ import type { IDojoBuild } from "warframe-public-export-plus";
20
20
import { ExportDojoRecipes } from "warframe-public-export-plus";
21
21
22
22
interface IContributeToDojoComponentRequest {
23
ComponentId: string;
23
ComponentId?: string; // req.query.componentId in U10
24
24
DecoId?: string;
25
25
DecoType?: string;
26
IngredientContributions: IMiscItem[];
26
27
// credit contributions
27
28
RegularCredits: number;
28
VaultIngredientContributions: IMiscItem[];
29
29
VaultCredits: number;
30
31
// 'ingredient' contributions are just MiscItems in U10; unsure when it changed.
32
MiscItems?: IMiscItem[];
33
VaultMiscItems?: IMiscItem[];
34
IngredientContributions?: IMiscItem[];
35
VaultIngredientContributions?: IMiscItem[];
30
36
}
31
37
32
38
export const contributeToDojoComponentController: RequestHandler = async (req, res) => {
33
const accountId = await getAccountIdForRequest(req);
34
const inventory = await getInventory(accountId);
39
const account = await getAccountForRequest(req);
40
const inventory = await getInventory(account._id.toString());
35
41
// Any clan member should have permission to contribute although notably permission is denied if they have not crafted the dojo key and were simply invited in.
36
42
if (!hasAccessToDojo(inventory)) {
37
43
res.json({ DojoRequestStatus: -1 });
@@ -39,10 +45,16 @@ export const contributeToDojoComponentController: RequestHandler = async (req, r
39
45
}
40
46
const guild = await getGuildForRequestEx(req, inventory);
41
47
const guildMember = (await GuildMember.findOne(
42
{ accountId, guildId: guild._id },
48
{ accountId: account._id, guildId: guild._id },
43
49
"RegularCreditsContributed MiscItemsContributed"
44
50
))!;
45
51
const request = JSON.parse(String(req.body)) as IContributeToDojoComponentRequest;
52
if (!request.ComponentId) {
53
request.ComponentId = req.query.componentId as string;
54
}
55
request.DecoId ??= req.query.decoId as string | undefined;
56
request.IngredientContributions ??= request.MiscItems;
57
request.VaultIngredientContributions ??= request.VaultMiscItems;
46
58
const component = guild.DojoComponents.id(request.ComponentId)!;
47
59
48
60
const inventoryChanges: IInventoryChanges = {};
@@ -68,7 +80,7 @@ export const contributeToDojoComponentController: RequestHandler = async (req, r
68
80
69
81
await Promise.all([guild.save(), inventory.save(), guildMember.save()]);
70
82
res.json({
71
...(await getDojoClient(guild, 0, component._id)),
83
...(await getDojoClient(guild, 0, component._id, account.BuildLabel)),
72
84
InventoryChanges: inventoryChanges
73
85
});
74
86
};
@@ -102,8 +114,8 @@ const processContribution = (
102
114
}
103
115
104
116
component.MiscItems ??= [];
105
if (request.VaultIngredientContributions.length) {
106
for (const ingredientContribution of request.VaultIngredientContributions) {
117
if (request.VaultIngredientContributions!.length) {
118
for (const ingredientContribution of request.VaultIngredientContributions!) {
107
119
const componentMiscItem = component.MiscItems.find(x => x.ItemType == ingredientContribution.ItemType);
108
120
if (componentMiscItem) {
109
121
const ingredientMeta = meta.ingredients.find(x => x.ItemType == ingredientContribution.ItemType)!;
@@ -122,9 +134,9 @@ const processContribution = (
122
134
vaultMiscItem.ItemCount -= ingredientContribution.ItemCount;
123
135
}
124
136
}
125
if (request.IngredientContributions.length) {
137
if (request.IngredientContributions!.length) {
126
138
const miscItemChanges: IMiscItem[] = [];
127
for (const ingredientContribution of request.IngredientContributions) {
139
for (const ingredientContribution of request.IngredientContributions!) {
128
140
const componentMiscItem = component.MiscItems.find(x => x.ItemType == ingredientContribution.ItemType);
129
141
if (componentMiscItem) {
130
142
const ingredientMeta = meta.ingredients.find(x => x.ItemType == ingredientContribution.ItemType)!;