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: fix most explicit-function-return-type warnings (#656)

d31f9f8d
Sainan <sainan@calamity.inc>
提交于

代码差异

12 个文件 +48 -34
Modified src/controllers/api/getFriendsController.ts +1 -1
@@ -1,6 +1,6 @@
1 1 import { Request, Response } from "express";
2 2
3 const getFriendsController = (_request: Request, response: Response) => {
3 const getFriendsController = (_request: Request, response: Response): void => {
4 4 response.writeHead(200, {
5 5 //Connection: "keep-alive",
6 6 //"Content-Encoding": "gzip",
Modified src/helpers/inventoryHelpers.ts +2 -2
@@ -1,4 +1,4 @@
1 import { IOid } from "@/src/types/commonTypes";
1 import { IMongoDate, IOid } from "@/src/types/commonTypes";
2 2 import { IInventoryResponse } from "@/src/types/inventoryTypes/inventoryTypes";
3 3 import { Types } from "mongoose";
4 4
@@ -13,6 +13,6 @@ export const toOid = (objectId: Types.ObjectId): IOid => {
13 13 return { $oid: objectId.toString() } satisfies IOid;
14 14 };
15 15
16 export const toMongoDate = (date: Date) => {
16 export const toMongoDate = (date: Date): IMongoDate => {
17 17 return { $date: { $numberLong: date.getTime().toString() } };
18 18 };
Modified src/helpers/purchaseHelpers.ts +1 -1
@@ -5,7 +5,7 @@ export const isSlotPurchaseName = (slotPurchaseName: string): slotPurchaseName i
5 5 return slotPurchaseName in slotPurchaseNameToSlotName;
6 6 };
7 7
8 export const parseSlotPurchaseName = (slotPurchaseName: string) => {
8 export const parseSlotPurchaseName = (slotPurchaseName: string): SlotPurchaseName => {
9 9 if (!isSlotPurchaseName(slotPurchaseName)) throw new Error(`invalid slot name ${slotPurchaseName}`);
10 10 return slotPurchaseName;
11 11 };
Modified src/helpers/stringHelpers.ts +1 -1
@@ -17,7 +17,7 @@ export const getSubstringFromKeywordToKeyword = (str: string, keywordBegin: stri
17 17 return str.substring(beginIndex, endIndex + 1);
18 18 };
19 19
20 export const getIndexAfter = (str: string, searchWord: string) => {
20 export const getIndexAfter = (str: string, searchWord: string): number => {
21 21 const index = str.indexOf(searchWord);
22 22 if (index === -1) {
23 23 return -1;
Modified src/middleware/middleware.ts +1 -1
@@ -1,7 +1,7 @@
1 1 import { logger } from "@/src/utils/logger";
2 2 import { /*NextFunction,*/ Request, Response } from "express";
3 3
4 const unknownEndpointHandler = (request: Request, response: Response) => {
4 const unknownEndpointHandler = (request: Request, response: Response): void => {
5 5 logger.error(`unknown endpoint ${request.method} ${request.path}`);
6 6 if (request.body) {
7 7 logger.debug(`data provided to ${request.path}: ${String(request.body)}`);
Modified src/models/inventoryModels/inventoryModel.ts +1 -1
@@ -326,7 +326,7 @@ const MailboxSchema = new Schema<IMailbox>(
326 326 {
327 327 LastInboxId: {
328 328 type: Schema.Types.ObjectId,
329 set: (v: IMailbox["LastInboxId"]) => v.$oid.toString()
329 set: (v: IMailbox["LastInboxId"]): string => v.$oid.toString()
330 330 }
331 331 },
332 332 { id: false, _id: false }
Modified src/services/configService.ts +1 -1
@@ -56,7 +56,7 @@ interface ILoggerConfig {
56 56 level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
57 57 }
58 58
59 export const updateConfig = async (data: string) => {
59 export const updateConfig = async (data: string): Promise<void> => {
60 60 amnesia = true;
61 61 await fsPromises.writeFile(configPath, data);
62 62 Object.assign(config, JSON.parse(data));
Modified src/services/inventoryService.ts +33 -19
@@ -47,7 +47,7 @@ import { handleStoreItemAcquisition } from "./purchaseService";
47 47 export const createInventory = async (
48 48 accountOwnerId: Types.ObjectId,
49 49 defaultItemReferences: { loadOutPresetId: Types.ObjectId; ship: Types.ObjectId }
50 ) => {
50 ): Promise<void> => {
51 51 try {
52 52 const inventory = config.skipTutorial
53 53 ? new Inventory({
@@ -367,7 +367,7 @@ export const addItem = async (
367 367 };
368 368
369 369 //TODO: maybe genericMethod for all the add methods, they share a lot of logic
370 export const addSentinel = async (sentinelName: string, accountId: string) => {
370 export const addSentinel = async (sentinelName: string, accountId: string): Promise<IInventoryChanges> => {
371 371 const inventoryChanges: IInventoryChanges = {};
372 372
373 373 if (ExportSentinels[sentinelName]?.defaultWeapon) {
@@ -400,11 +400,11 @@ export const addSentinel = async (sentinelName: string, accountId: string) => {
400 400 return inventoryChanges;
401 401 };
402 402
403 export const addSentinelWeapon = async (typeName: string, accountId: string) => {
403 export const addSentinelWeapon = async (typeName: string, accountId: string): Promise<IEquipmentClient> => {
404 404 const inventory = await getInventory(accountId);
405 405 const sentinelIndex = inventory.SentinelWeapons.push({ ItemType: typeName });
406 406 const changedInventory = await inventory.save();
407 return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON();
407 return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON<IEquipmentClient>();
408 408 };
409 409
410 410 export const addPowerSuit = async (powersuitName: string, accountId: string): Promise<IInventoryChanges> => {
@@ -458,14 +458,19 @@ export const addSpecialItem = async (
458 458 (inventoryChanges.SpecialItems as object[]).push(changedInventory.SpecialItems[specialItemIndex - 1].toJSON());
459 459 };
460 460
461 export const addSpaceSuit = async (spacesuitName: string, accountId: string) => {
461 export const addSpaceSuit = async (spacesuitName: string, accountId: string): Promise<IEquipmentClient> => {
462 462 const inventory = await getInventory(accountId);
463 463 const suitIndex = inventory.SpaceSuits.push({ ItemType: spacesuitName, Configs: [], UpgradeVer: 101, XP: 0 });
464 464 const changedInventory = await inventory.save();
465 return changedInventory.SpaceSuits[suitIndex - 1].toJSON();
465 return changedInventory.SpaceSuits[suitIndex - 1].toJSON<IEquipmentClient>();
466 466 };
467 467
468 export const updateSlots = async (accountId: string, slotName: SlotNames, slotAmount: number, extraAmount: number) => {
468 export const updateSlots = async (
469 accountId: string,
470 slotName: SlotNames,
471 slotAmount: number,
472 extraAmount: number
473 ): Promise<void> => {
469 474 const inventory = await getInventory(accountId);
470 475
471 476 inventory[slotName].Slots += slotAmount;
@@ -542,7 +547,7 @@ export const updateGeneric = async (data: IGenericUpdate, accountId: string): Pr
542 547 await inventory.save();
543 548 };
544 549
545 export const updateTheme = async (data: IThemeUpdateRequest, accountId: string) => {
550 export const updateTheme = async (data: IThemeUpdateRequest, accountId: string): Promise<void> => {
546 551 const inventory = await getInventory(accountId);
547 552 if (data.Style) inventory.ThemeStyle = data.Style;
548 553 if (data.Background) inventory.ThemeBackground = data.Background;
@@ -634,7 +639,7 @@ const addGearExpByCategory = (
634 639 inventory: IInventoryDatabaseDocument,
635 640 gearArray: IEquipmentClient[] | undefined,
636 641 categoryName: TEquipmentKey
637 ) => {
642 ): void => {
638 643 const category = inventory[categoryName];
639 644
640 645 gearArray?.forEach(({ ItemId, XP }) => {
@@ -663,7 +668,7 @@ const addGearExpByCategory = (
663 668 });
664 669 };
665 670
666 export const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray: IMiscItem[] | undefined) => {
671 export const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray: IMiscItem[] | undefined): void => {
667 672 const { MiscItems } = inventory;
668 673
669 674 itemsArray?.forEach(({ ItemCount, ItemType }) => {
@@ -678,7 +683,10 @@ export const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray:
678 683 });
679 684 };
680 685
681 export const addShipDecorations = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
686 export const addShipDecorations = (
687 inventory: IInventoryDatabaseDocument,
688 itemsArray: IConsumable[] | undefined
689 ): void => {
682 690 const { ShipDecorations } = inventory;
683 691
684 692 itemsArray?.forEach(({ ItemCount, ItemType }) => {
@@ -693,7 +701,7 @@ export const addShipDecorations = (inventory: IInventoryDatabaseDocument, itemsA
693 701 });
694 702 };
695 703
696 export const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
704 export const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined): void => {
697 705 const { Consumables } = inventory;
698 706
699 707 itemsArray?.forEach(({ ItemCount, ItemType }) => {
@@ -708,7 +716,7 @@ export const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray
708 716 });
709 717 };
710 718
711 export const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: ITypeCount[] | undefined) => {
719 export const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: ITypeCount[] | undefined): void => {
712 720 const { Recipes } = inventory;
713 721
714 722 itemsArray?.forEach(({ ItemCount, ItemType }) => {
@@ -723,7 +731,7 @@ export const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: IT
723 731 });
724 732 };
725 733
726 export const addMods = (inventory: IInventoryDatabaseDocument, itemsArray: IRawUpgrade[] | undefined) => {
734 export const addMods = (inventory: IInventoryDatabaseDocument, itemsArray: IRawUpgrade[] | undefined): void => {
727 735 const { RawUpgrades } = inventory;
728 736 itemsArray?.forEach(({ ItemType, ItemCount }) => {
729 737 const itemIndex = RawUpgrades.findIndex(i => i.ItemType === ItemType);
@@ -740,7 +748,7 @@ export const addMods = (inventory: IInventoryDatabaseDocument, itemsArray: IRawU
740 748 export const addFusionTreasures = (
741 749 inventory: IInventoryDatabaseDocument,
742 750 itemsArray: IFusionTreasure[] | undefined
743 ) => {
751 ): void => {
744 752 const { FusionTreasures } = inventory;
745 753 itemsArray?.forEach(({ ItemType, ItemCount, Sockets }) => {
746 754 const itemIndex = FusionTreasures.findIndex(i => i.ItemType == ItemType && (i.Sockets || 0) == (Sockets || 0));
@@ -754,7 +762,10 @@ export const addFusionTreasures = (
754 762 });
755 763 };
756 764
757 export const updateChallengeProgress = async (challenges: IUpdateChallengeProgressRequest, accountId: string) => {
765 export const updateChallengeProgress = async (
766 challenges: IUpdateChallengeProgressRequest,
767 accountId: string
768 ): Promise<void> => {
758 769 const inventory = await getInventory(accountId);
759 770
760 771 addChallenges(inventory, challenges.ChallengeProgress);
@@ -766,7 +777,7 @@ export const updateChallengeProgress = async (challenges: IUpdateChallengeProgre
766 777 export const addSeasonalChallengeHistory = (
767 778 inventory: IInventoryDatabaseDocument,
768 779 itemsArray: ISeasonChallenge[] | undefined
769 ) => {
780 ): void => {
770 781 const category = inventory.SeasonChallengeHistory;
771 782
772 783 itemsArray?.forEach(({ challenge, id }) => {
@@ -780,7 +791,10 @@ export const addSeasonalChallengeHistory = (
780 791 });
781 792 };
782 793
783 export const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray: IChallengeProgress[] | undefined) => {
794 export const addChallenges = (
795 inventory: IInventoryDatabaseDocument,
796 itemsArray: IChallengeProgress[] | undefined
797 ): void => {
784 798 const category = inventory.ChallengeProgress;
785 799
786 800 itemsArray?.forEach(({ Name, Progress }) => {
@@ -795,7 +809,7 @@ export const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray:
795 809 });
796 810 };
797 811
798 const addMissionComplete = (inventory: IInventoryDatabaseDocument, { Tag, Completes }: IMission) => {
812 const addMissionComplete = (inventory: IInventoryDatabaseDocument, { Tag, Completes }: IMission): void => {
799 813 const { Missions } = inventory;
800 814 const itemIndex = Missions.findIndex(item => item.Tag === Tag);
801 815
Modified src/services/loginService.ts +2 -2
@@ -34,13 +34,13 @@ export const createAccount = async (accountData: IDatabaseAccount): Promise<IDat
34 34 }
35 35 };
36 36
37 export const createLoadout = async (accountId: Types.ObjectId) => {
37 export const createLoadout = async (accountId: Types.ObjectId): Promise<Types.ObjectId> => {
38 38 const loadout = new Loadout({ loadoutOwnerId: accountId });
39 39 const savedLoadout = await loadout.save();
40 40 return savedLoadout._id;
41 41 };
42 42
43 export const createPersonalRooms = async (accountId: Types.ObjectId, shipId: Types.ObjectId) => {
43 export const createPersonalRooms = async (accountId: Types.ObjectId, shipId: Types.ObjectId): Promise<void> => {
44 44 const personalRooms = new PersonalRooms({
45 45 ...new_personal_rooms,
46 46 personalRoomsOwnerId: accountId,
Modified src/services/purchaseService.ts +2 -2
@@ -25,13 +25,13 @@ import {
25 25 TRarity
26 26 } from "warframe-public-export-plus";
27 27
28 export const getStoreItemCategory = (storeItem: string) => {
28 export const getStoreItemCategory = (storeItem: string): string => {
29 29 const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
30 30 const storeItemElements = storeItemString.split("/");
31 31 return storeItemElements[1];
32 32 };
33 33
34 export const getStoreItemTypesCategory = (typesItem: string) => {
34 export const getStoreItemTypesCategory = (typesItem: string): string => {
35 35 const typesString = getSubstringFromKeyword(typesItem, "Types");
36 36 const typeElements = typesString.split("/");
37 37 if (typesItem.includes("StoreItems")) {
Modified src/services/recipeService.ts +2 -2
@@ -4,7 +4,7 @@ import { getRecipe } from "@/src/services/itemDataService";
4 4 import { logger } from "@/src/utils/logger";
5 5 import { Types } from "mongoose";
6 6
7 export const startRecipe = async (recipeName: string, accountId: string) => {
7 export const startRecipe = async (recipeName: string, accountId: string): Promise<{ RecipeId: { $oid: string } }> => {
8 8 const recipe = getRecipe(recipeName);
9 9
10 10 if (!recipe) {
@@ -34,6 +34,6 @@ export const startRecipe = async (recipeName: string, accountId: string) => {
34 34 const newInventory = await inventory.save();
35 35
36 36 return {
37 RecipeId: { $oid: newInventory.PendingRecipes[newInventory.PendingRecipes.length - 1]._id?.toString() }
37 RecipeId: { $oid: newInventory.PendingRecipes[newInventory.PendingRecipes.length - 1]._id.toString() }
38 38 };
39 39 };
Modified src/utils/logger.ts +1 -1
@@ -103,7 +103,7 @@ export const logger = createLogger({
103 103
104 104 addColors(logLevels.colors);
105 105
106 export function registerLogFileCreationListener() {
106 export function registerLogFileCreationListener(): void {
107 107 errorLog.on("new", filename => logger.info(`Using error log file: ${filename}`));
108 108 combinedLog.on("new", filename => logger.info(`Using combined log file: ${filename}`));
109 109 errorLog.on("rotate", filename => logger.info(`Rotated error log file: ${filename}`));