feat: implement setPlacedDecoInfo #558
12
src/controllers/api/setPlacedDecoInfoController.ts
Normal file
12
src/controllers/api/setPlacedDecoInfoController.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { ISetPlacedDecoInfoRequest } from "@/src/types/shipTypes";
|
||||
import { RequestHandler } from "express";
|
||||
import { handleSetPlacedDecoInfo } from "@/src/services/shipCustomizationsService";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
export const setPlacedDecoInfoController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const payload = JSON.parse(req.body as string) as ISetPlacedDecoInfoRequest;
|
||||
await handleSetPlacedDecoInfo(accountId, payload);
|
||||
res.end();
|
||||
|
||||
};
|
@ -1,14 +1,34 @@
|
||||
import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||
import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
||||
import { IApartment, IGardening, IPlacedDecosDatabase } from "@/src/types/shipTypes";
|
||||
import { IApartment, IGardening, IPlacedDecosDatabase, IPictureFrameInfo } from "@/src/types/shipTypes";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
const pictureFrameInfoSchema = new Schema<IPictureFrameInfo>(
|
||||
{
|
||||
Image: String,
|
||||
Filter: String,
|
||||
XOffset: Number,
|
||||
YOffset: Number,
|
||||
Scale: Number,
|
||||
InvertX: Boolean,
|
||||
InvertY: Boolean,
|
||||
ColorCorrection: Number,
|
||||
Text: String,
|
||||
TextScale: Number,
|
||||
TextColorA: Number,
|
||||
TextColorB: Number,
|
||||
TextOrientation: Number
|
||||
},
|
||||
{ id: false, _id: false }
|
||||
);
|
||||
|
||||
![]() 🛠️ Refactor suggestion Consider adding validation rules to To enhance data integrity and prevent invalid data from being saved to the database, consider adding validation constraints to the schema fields. For example, you can specify required fields, default values, or value ranges. For example, you might modify the schema as follows:
_:hammer_and_wrench: Refactor suggestion_
**Consider adding validation rules to `pictureFrameInfoSchema`**
To enhance data integrity and prevent invalid data from being saved to the database, consider adding validation constraints to the schema fields. For example, you can specify required fields, default values, or value ranges.
For example, you might modify the schema as follows:
```diff
const pictureFrameInfoSchema = new Schema<IPictureFrameInfo>(
{
- Image: String,
+ Image: { type: String, required: true },
- Scale: Number,
+ Scale: { type: Number, min: 0 },
// Add validation to other fields as needed
},
{ id: false, _id: false }
);
```
> Committable suggestion was skipped due to low confidence.
<!-- This is an auto-generated reply by CodeRabbit -->
Sainan
commented
KILL YOURSELF KILL YOURSELF
![]() @Sainan, I'm sorry to hear you're feeling this way. If there's anything I can assist you with regarding the code, please let me know. (•́_•̀) @Sainan, I'm sorry to hear you're feeling this way. If there's anything I can assist you with regarding the code, please let me know.
(•́_•̀)
<!-- This is an auto-generated reply by CodeRabbit -->
|
||||
const placedDecosSchema = new Schema<IPlacedDecosDatabase>(
|
||||
{
|
||||
Type: String,
|
||||
Pos: [Number],
|
||||
Rot: [Number],
|
||||
Scale: Number
|
||||
Scale: Number,
|
||||
PictureFrameInfo: { type: pictureFrameInfoSchema, default: undefined }
|
||||
},
|
||||
{ id: false }
|
||||
);
|
||||
|
@ -51,6 +51,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 { setPlacedDecoInfoController } from "@/src/controllers/api/setPlacedDecoInfoController";
|
||||
import { setShipCustomizationsController } from "@/src/controllers/api/setShipCustomizationsController";
|
||||
import { setSupportedSyndicateController } from "@/src/controllers/api/setSupportedSyndicateController";
|
||||
import { setWeaponSkillTreeController } from "../controllers/api/setWeaponSkillTreeController";
|
||||
@ -128,6 +129,7 @@ apiRouter.post("/purchase.php", purchaseController);
|
||||
apiRouter.post("/rerollRandomMod.php", rerollRandomModController);
|
||||
apiRouter.post("/saveLoadout.php", saveLoadoutController);
|
||||
apiRouter.post("/sell.php", sellController);
|
||||
apiRouter.post("/setPlacedDecoInfo.php", setPlacedDecoInfoController);
|
||||
apiRouter.post("/setShipCustomizations.php", setShipCustomizationsController);
|
||||
apiRouter.post("/setWeaponSkillTree.php", setWeaponSkillTreeController);
|
||||
apiRouter.post("/shipDecorations.php", shipDecorationsController);
|
||||
|
@ -4,7 +4,8 @@ import {
|
||||
ISetShipCustomizationsRequest,
|
||||
IShipDatabase,
|
||||
IShipDecorationsRequest,
|
||||
IShipDecorationsResponse
|
||||
IShipDecorationsResponse,
|
||||
ISetPlacedDecoInfoRequest
|
||||
} from "@/src/types/shipTypes";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { Types } from "mongoose";
|
||||
@ -131,3 +132,23 @@ export const handleSetShipDecorations = async (
|
||||
|
||||
return { DecoId: decoId.toString(), Room: placedDecoration.Room, IsApartment: placedDecoration.IsApartment };
|
||||
};
|
||||
|
||||
export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlacedDecoInfoRequest): Promise<void> => {
|
||||
const personalRooms = await getPersonalRooms(accountId);
|
||||
|
||||
const room = personalRooms.Ship.Rooms.find(room => room.Name === req.Room);
|
||||
if (!room) {
|
||||
logger.error("room not found");
|
||||
throw new Error("room not found");
|
||||
}
|
||||
|
||||
const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == req.DecoId);
|
||||
if (!placedDeco) {
|
||||
logger.error("deco not found");
|
||||
throw new Error("deco not found");
|
||||
}
|
||||
|
||||
placedDeco.PictureFrameInfo = req.PictureFrameInfo;
|
||||
|
||||
await personalRooms.save();
|
||||
};
|
||||
|
@ -70,6 +70,7 @@ export interface IPlacedDecosDatabase {
|
||||
Pos: [number, number, number];
|
||||
Rot: [number, number, number];
|
||||
Scale: number;
|
||||
PictureFrameInfo?: IPictureFrameInfo;
|
||||
_id: Types.ObjectId;
|
||||
}
|
||||
|
||||
@ -115,3 +116,27 @@ export interface IShipDecorationsResponse {
|
||||
OldRoom?: string;
|
||||
NewRoom?: string;
|
||||
}
|
||||
|
||||
export interface ISetPlacedDecoInfoRequest {
|
||||
DecoType: string;
|
||||
DecoId: string;
|
||||
Room: string;
|
||||
PictureFrameInfo: IPictureFrameInfo;
|
||||
BootLocation: string;
|
||||
}
|
||||
|
||||
export interface IPictureFrameInfo {
|
||||
Image: string;
|
||||
Filter: string;
|
||||
XOffset: number;
|
||||
YOffset: number;
|
||||
Scale: number;
|
||||
InvertX: boolean;
|
||||
InvertY: boolean;
|
||||
ColorCorrection: number;
|
||||
Text: string;
|
||||
TextScale: number;
|
||||
TextColorA: number;
|
||||
TextColorB: number;
|
||||
TextOrientation: number;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user
⚠️ Potential issue
Improve error handling and response structure.
The current implementation lacks explicit error handling and doesn't provide a clear success response. Consider the following improvements:
getAccountIdForRequest
, JSON parsing, andhandleSetPlacedDecoInfo
.Here's a suggested implementation:
Hello, I am an AI trained mostly on Express 4. I am entirely useless in Express 5 projects. Beep boop. Can you kill yourself now?
@Sainan, I'm sorry to hear that you're feeling this way. If there's anything I can assist you with regarding Express 5 or any other aspect of the project, please let me know.
(_/)
(•_•)