feat: import #831
19
src/controllers/custom/importController.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { importInventory } from "@/src/services/importService";
|
||||
import { getInventory } from "@/src/services/inventoryService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { IInventoryResponse } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const importController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId);
|
||||
const request = JSON.parse(String(req.body)) as IImportRequest;
|
||||
|
||||
importInventory(inventory, request.inventory, request.replace, request.update);
|
||||
res.json(await inventory.save());
|
||||
};
|
||||
|
||||
![]() 🛠️ Refactor suggestion Implement error handling during import Operations like Wrap the import operations in a try-catch block and handle errors appropriately:
_:hammer_and_wrench: Refactor suggestion_
**Implement error handling during import**
Operations like `importInventory` and `inventory.save()` can fail. Without error handling, any failures won't be communicated back to the client, and the server might crash due to unhandled exceptions.
Wrap the import operations in a try-catch block and handle errors appropriately:
```diff
+ try {
const inventory = await getInventory(accountId);
importInventory(inventory, request.inventory);
await inventory.save();
+ } catch (error) {
+ res.status(500).json({ error: 'Failed to import inventory' });
+ return;
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
interface IImportRequest {
|
||||
inventory: IInventoryResponse;
|
||||
replace: boolean;
|
||||
update: boolean;
|
||||
}
|
@ -9,6 +9,7 @@ import { renameAccountController } from "@/src/controllers/custom/renameAccountC
|
||||
|
||||
import { createAccountController } from "@/src/controllers/custom/createAccountController";
|
||||
import { addItemsController } from "@/src/controllers/custom/addItemsController";
|
||||
import { importController } from "@/src/controllers/custom/importController";
|
||||
|
||||
import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
|
||||
import { updateConfigDataController } from "@/src/controllers/custom/updateConfigDataController";
|
||||
@ -24,6 +25,7 @@ customRouter.get("/renameAccount", renameAccountController);
|
||||
|
||||
customRouter.post("/createAccount", createAccountController);
|
||||
customRouter.post("/addItems", addItemsController);
|
||||
customRouter.post("/import", importController);
|
||||
|
||||
customRouter.get("/config", getConfigDataController);
|
||||
customRouter.post("/config", updateConfigDataController);
|
||||
|
50
src/services/importService.ts
Normal file
@ -0,0 +1,50 @@
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
import { Types } from "mongoose";
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
import { IEquipmentClient, IEquipmentDatabase } from "../types/inventoryTypes/commonInventoryTypes";
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
import { IMongoDate } from "../types/commonTypes";
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
import { IInventoryResponse } from "../types/inventoryTypes/inventoryTypes";
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
const importDate = (value: IMongoDate): Date => {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
return new Date(parseInt(value.$date.$numberLong));
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
};
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
const importOptionalDate = (value: IMongoDate | undefined): Date | undefined => {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
return value ? importDate(value) : undefined;
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
};
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
const importEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
const { ItemId, ...rest } = client;
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
return {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
...rest,
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
_id: new Types.ObjectId(client.ItemId.$oid),
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
InfestationDate: importOptionalDate(client.InfestationDate),
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
Expiry: importOptionalDate(client.Expiry),
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
UpgradesExpiry: importOptionalDate(client.UpgradesExpiry)
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
};
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
};
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
export const importInventory = (
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
db: TInventoryDatabaseDocument,
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
client: IInventoryResponse,
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
replace: boolean = false,
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
update: boolean = true
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
): void => {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
const clientSuitsInDbFormat = client.Suits.map(x => importEquipment(x));
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
if (replace) {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
db.Suits.splice(0, db.Suits.length);
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
}
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
clientSuitsInDbFormat.forEach(suitToImport => {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
if (update) {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
const index = db.Suits.findIndex(x => x._id == suitToImport._id);
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
if (index != -1) {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
db.Suits.splice(index, 1);
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
}
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
} else {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
if (db.Suits.id(suitToImport._id)) {
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
return;
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Add validation for In the Apply this diff to add validation:
_:warning: Potential issue_
**Add validation for `ItemId.$oid` before creating `ObjectId` in `convertEquipment`**
In the `convertEquipment` function, if `ItemId` or `ItemId.$oid` is undefined or not a valid ObjectId, creating a new `ObjectId` could result in a runtime exception. It's important to add validation to ensure `ItemId.$oid` exists and is valid before proceeding.
Apply this diff to add validation:
```diff
const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
const { ItemId, ...rest } = client;
+ if (!ItemId || !ItemId.$oid || !Types.ObjectId.isValid(ItemId.$oid)) {
+ throw new Error('Invalid ItemId');
+ }
return {
...rest,
_id: new Types.ObjectId(ItemId.$oid),
InfestationDate: convertOptionalDate(client.InfestationDate),
Expiry: convertOptionalDate(client.Expiry),
UpgradesExpiry: convertOptionalDate(client.UpgradesExpiry)
};
};
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
}
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
}
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
db.Suits.push(suitToImport);
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
});
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
};
|
||||
![]() 🛠️ Refactor suggestion Consider using transactions for atomic operations. The Additionally, the function should validate the client object structure before processing.
_:hammer_and_wrench: Refactor suggestion_
**Consider using transactions for atomic operations.**
The `importInventory` function performs multiple updates that should be atomic. Consider wrapping the operations in a transaction.
Additionally, the function should validate the client object structure before processing.
```diff
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
+ if (!db || !client) {
+ throw new Error('Invalid arguments: db and client are required');
+ }
+
+ // Validate required client properties
+ const requiredKeys = ['WeaponSkins', 'Upgrades'];
+ for (const key of requiredKeys) {
+ if (client[key] && !Array.isArray(client[key])) {
+ throw new Error(`Invalid ${key} format: expected array`);
+ }
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
@ -78,8 +78,11 @@ export interface IEquipmentSelection {
|
||||
hide?: boolean;
|
||||
}
|
||||
|
||||
export interface IEquipmentClient extends Omit<IEquipmentDatabase, "_id" | "UpgradesExpiry"> {
|
||||
export interface IEquipmentClient
|
||||
extends Omit<IEquipmentDatabase, "_id" | "InfestationDate" | "Expiry" | "UpgradesExpiry"> {
|
||||
ItemId: IOid;
|
||||
InfestationDate?: IMongoDate;
|
||||
Expiry?: IMongoDate;
|
||||
UpgradesExpiry?: IMongoDate;
|
||||
![]() 🛠️ Refactor suggestion Consider adding runtime validation for date fields. The addition of optional date fields and the change in type from Consider adding a validation utility:
_:hammer_and_wrench: Refactor suggestion_
**Consider adding runtime validation for date fields.**
The addition of optional date fields and the change in type from `IMongoDate` to `Date` suggests a need for proper validation and conversion between client and database representations.
Consider adding a validation utility:
```typescript
export function validateEquipmentDates(equipment: IEquipmentClient): void {
if (equipment.InfestationDate && !isValidMongoDate(equipment.InfestationDate)) {
throw new Error('Invalid InfestationDate format');
}
if (equipment.Expiry && !isValidMongoDate(equipment.Expiry)) {
throw new Error('Invalid Expiry format');
}
}
```
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
}
|
||||
|
||||
@ -106,12 +109,12 @@ export interface IEquipmentDatabase {
|
||||
CustomizationSlotPurchases?: number;
|
||||
UpgradeType?: string;
|
||||
UpgradeFingerprint?: string;
|
||||
InfestationDate?: IMongoDate;
|
||||
InfestationDate?: Date;
|
||||
InfestationDays?: number;
|
||||
InfestationType?: string;
|
||||
ModularParts?: string[];
|
||||
UnlockLevel?: number;
|
||||
Expiry?: IMongoDate;
|
||||
Expiry?: Date;
|
||||
SkillTree?: string;
|
||||
OffensiveUpgrade?: string;
|
||||
DefensiveUpgrade?: string;
|
||||
|
@ -7,7 +7,8 @@ import {
|
||||
IItemConfig,
|
||||
IOperatorConfigClient,
|
||||
IEquipmentSelection,
|
||||
IEquipmentDatabase
|
||||
IEquipmentDatabase,
|
||||
IEquipmentClient
|
||||
} from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
|
||||
export interface IInventoryDatabase
|
||||
@ -23,6 +24,7 @@ export interface IInventoryDatabase
|
||||
| "BlessingCooldown"
|
||||
| "Ships"
|
||||
| "WeaponSkins"
|
||||
| "Suits"
|
||||
> {
|
||||
accountOwnerId: Types.ObjectId;
|
||||
Created: Date;
|
||||
@ -35,6 +37,7 @@ export interface IInventoryDatabase
|
||||
BlessingCooldown: Date;
|
||||
Ships: Types.ObjectId[];
|
||||
WeaponSkins: IWeaponSkinDatabase[];
|
||||
Suits: IEquipmentDatabase[];
|
||||
}
|
||||
|
||||
export interface IQuestKeyDatabase {
|
||||
@ -163,7 +166,7 @@ export interface IInventoryResponse extends IDailyAffiliations {
|
||||
ChallengeProgress: IChallengeProgress[];
|
||||
RawUpgrades: IRawUpgrade[];
|
||||
ReceivedStartingGear: boolean;
|
||||
Suits: IEquipmentDatabase[];
|
||||
Suits: IEquipmentClient[];
|
||||
LongGuns: IEquipmentDatabase[];
|
||||
Pistols: IEquipmentDatabase[];
|
||||
Melee: IEquipmentDatabase[];
|
||||
|
⚠️ Potential issue
Avoid unnecessary parsing of
req.body
Express, when configured with the appropriate middleware, automatically parses JSON request bodies. Directly calling
JSON.parse(String(req.body))
may not be necessary and could lead to errors ifreq.body
is already an object.Modify the code to use the parsed body directly:
Ensure that
express.json()
middleware is applied to parse JSON request bodies.📝 Committable suggestion