返回提交历史
Modified
src/controllers/api/modularWeaponSaleController.ts
+14
-0
XFEstudio/XFESpaceNinjaServer
feat: modularWeaponSale op=Sync (#3246)
Old versions used this instead of SyncAll Closes #3245 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3246 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
36c6b7a4
代码差异
1 个文件
+14
-0
@@ -19,6 +19,7 @@ import { sendWsBroadcastTo } from "../../services/wsService.ts";
19
19
import { modularWeaponTypes } from "../../helpers/modularWeaponHelper.ts";
20
20
import type { IInventoryChanges } from "../../types/purchaseTypes.ts";
21
21
import { EquipmentFeatures } from "../../types/equipmentTypes.ts";
22
import { logger } from "../../utils/logger.ts";
22
23
23
24
export const modularWeaponSaleController: RequestHandler = async (req, res) => {
24
25
const partTypeToParts: Record<string, string[]> = {};
@@ -37,6 +38,12 @@ export const modularWeaponSaleController: RequestHandler = async (req, res) => {
37
38
res.json({
38
39
SaleInfos: getSaleInfos(partTypeToParts, Math.trunc(Date.now() / 86400000))
39
40
});
41
} else if (req.query.op == "Sync") {
42
const payload = getJSONfromString<IModularWeaponSyncRequest>(String(req.body));
43
const saleInfos = getSaleInfos(partTypeToParts, Math.trunc(Date.now() / 86400000));
44
res.json({
45
SaleInfo: saleInfos.find(x => x.Name == payload.SaleName)
46
});
40
47
} else if (req.query.op == "Purchase") {
41
48
const accountId = await getAccountIdForRequest(req);
42
49
const inventory = await getInventory(accountId);
@@ -73,6 +80,9 @@ export const modularWeaponSaleController: RequestHandler = async (req, res) => {
73
80
});
74
81
sendWsBroadcastTo(accountId, { update_inventory: true });
75
82
} else {
83
if (req.body) {
84
logger.debug(`data provided to ${req.path}: ${String(req.body)}`);
85
}
76
86
throw new Error(`unknown modularWeaponSale op: ${String(req.query.op)}`);
77
87
}
78
88
};
@@ -165,6 +175,10 @@ const getModularWeaponSale = (
165
175
};
166
176
};
167
177
178
interface IModularWeaponSyncRequest {
179
SaleName: string;
180
}
181
168
182
interface IModularWeaponSaleInfo {
169
183
Name: string;
170
184
Expiry: IMongoDate;