feat: changing equipped shawzin/instrument #762
17
src/controllers/api/setEquippedInstrumentController.ts
Normal file
17
src/controllers/api/setEquippedInstrumentController.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
|
||||
export const setEquippedInstrumentController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId);
|
||||
const body = getJSONfromString(String(req.body)) as ISetEquippedInstrumentRequest;
|
||||
inventory.EquippedInstrument = body.Instrument;
|
||||
await inventory.save();
|
||||
res.end();
|
||||
};
|
||||
|
||||
|
||||
interface ISetEquippedInstrumentRequest {
|
||||
Instrument: string;
|
||||
}
|
@ -56,6 +56,7 @@ import { sellController } from "@/src/controllers/api/sellController";
|
||||
import { setActiveQuestController } from "@/src/controllers/api/setActiveQuestController";
|
||||
import { setActiveShipController } from "@/src/controllers/api/setActiveShipController";
|
||||
import { setBootLocationController } from "@/src/controllers/api/setBootLocationController";
|
||||
import { setEquippedInstrumentController } from "@/src/controllers/api/setEquippedInstrumentController";
|
||||
import { setPlacedDecoInfoController } from "@/src/controllers/api/setPlacedDecoInfoController";
|
||||
import { setShipCustomizationsController } from "@/src/controllers/api/setShipCustomizationsController";
|
||||
import { setShipFavouriteLoadoutController } from "@/src/controllers/api/setShipFavouriteLoadoutController";
|
||||
@ -141,6 +142,7 @@ apiRouter.post("/purchase.php", purchaseController);
|
||||
apiRouter.post("/rerollRandomMod.php", rerollRandomModController);
|
||||
apiRouter.post("/saveLoadout.php", saveLoadoutController);
|
||||
apiRouter.post("/sell.php", sellController);
|
||||
apiRouter.post("/setEquippedInstrument.php", setEquippedInstrumentController);
|
||||
apiRouter.post("/setPlacedDecoInfo.php", setPlacedDecoInfoController);
|
||||
apiRouter.post("/setShipCustomizations.php", setShipCustomizationsController);
|
||||
apiRouter.post("/setShipFavouriteLoadout.php", setShipFavouriteLoadoutController);
|
||||
|
@ -250,7 +250,7 @@ export interface IInventoryResponse {
|
||||
CompletedJobChains: ICompletedJobChain[];
|
||||
SeasonChallengeHistory: ISeasonChallenge[];
|
||||
MoaPets: IEquipmentDatabase[];
|
||||
EquippedInstrument: string;
|
||||
EquippedInstrument?: string;
|
||||
InvasionChainProgress: IInvasionChainProgress[];
|
||||
![]() 💡 Codebase verification Make EquippedInstrument a required field The field is defined as required in the database schema (inventoryModel.ts) and the setEquippedInstrumentController implementation assumes its presence. The optional marker (?) should be removed to maintain consistency with the underlying data model.
🔗 Analysis chainVerify if EquippedInstrument should be optional. The property is marked as optional (
Run the following script to check existing inventory documents: 🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 3151 Script:
Length of output: 3911 _:bulb: Codebase verification_
**Make EquippedInstrument a required field**
The field is defined as required in the database schema (inventoryModel.ts) and the setEquippedInstrumentController implementation assumes its presence. The optional marker (?) should be removed to maintain consistency with the underlying data model.
- `src/types/inventoryTypes/inventoryTypes.ts`: Change `EquippedInstrument?: string;` to `EquippedInstrument: string;`
<details>
<summary>🔗 Analysis chain</summary>
**Verify if EquippedInstrument should be optional.**
The property is marked as optional (`?`). Please verify if this is intentional:
1. Are there cases where this property might not exist?
2. Should existing inventories be migrated to include a default value?
Run the following script to check existing inventory documents:
</details>
<details>
<summary>🏁 Scripts executed</summary>
The following scripts were executed for the analysis:
Script:
```shell
#!/bin/bash
# Description: Check if any existing inventories have the EquippedInstrument field
# and what values it contains
# Search for inventory-related files
echo "Searching for inventory-related files..."
rg -l "inventory" --type ts
# Search for migrations or default values
echo "Searching for any migrations or default values..."
rg "EquippedInstrument.*default" --type ts
```
Length of output: 3151
---
Script:
```shell
#!/bin/bash
# Check implementation and usage of EquippedInstrument
# Check setEquippedInstrumentController implementation
echo "Checking setEquippedInstrumentController implementation:"
ast-grep --pattern 'export class setEquippedInstrumentController {
$$$
}'
# Search for EquippedInstrument usage
echo -e "\nSearching for EquippedInstrument usage:"
rg "EquippedInstrument" -B 2 -A 2 --type ts
# Check inventory models for related fields
echo -e "\nChecking inventory models:"
rg "EquippedInstrument" src/models/inventoryModels/ -B 2 -A 2
```
Length of output: 3911
</details>
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
DataKnives: IEquipmentDatabase[];
|
||||
Motorcycles: IEquipmentDatabase[];
|
||||
|
Loading…
x
Reference in New Issue
Block a user
🛠️ Refactor suggestion
Add error handling and input validation.
The controller needs to handle potential errors and validate input:
Apply this diff to improve error handling and validation:
📝 Committable suggestion