feat: import #831
@ -2,6 +2,7 @@ import { Types } from "mongoose";
|
||||
|
||||
import { IEquipmentClient, IEquipmentDatabase } from "../types/inventoryTypes/commonInventoryTypes";
|
||||
import { IMongoDate } from "../types/commonTypes";
|
||||
import {
|
||||
equipmentKeys,
|
||||
![]() 🛠️ 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 -->
|
||||
IInventoryClient,
|
||||
IUpgradeClient,
|
||||
IUpgradeDatabase,
|
||||
@ -55,8 +56,10 @@ const replaceArray = <T>(arr: T[], replacement: T[]): 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 -->
![]() 🛠️ 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 Similar to Apply this diff to add validation:
📝 Committable suggestion
_:warning: Potential issue_
**Add validation for `ItemId.$oid` before creating `ObjectId` in `convertWeaponSkin`**
Similar to `convertEquipment`, ensure that `ItemId.$oid` is valid in the `convertWeaponSkin` function to prevent potential runtime exceptions.
Apply this diff to add validation:
```diff
const convertWeaponSkin = (client: IWeaponSkinClient): IWeaponSkinDatabase => {
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)
};
};
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const convertWeaponSkin = (client: IWeaponSkinClient): IWeaponSkinDatabase => {
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)
};
};
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
|
||||
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
|
||||
if (client.Suits) {
|
||||
![]() 🛠️ 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 -->
|
||||
replaceArray<IEquipmentDatabase>(db.Suits, client.Suits.map(convertEquipment));
|
||||
![]() 🛠️ 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 -->
|
||||
for (const key of equipmentKeys) {
|
||||
![]() 🛠️ 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 (client[key]) {
|
||||
![]() 🛠️ 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 -->
|
||||
replaceArray<IEquipmentDatabase>(db[key], client[key].map(convertEquipment));
|
||||
![]() 🛠️ 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 -->
|
||||
}
|
||||
if (client.WeaponSkins) {
|
||||
![]() ⚠️ Potential issue Add validation for In the Apply this diff to add validation:
📝 Committable suggestion
_:warning: Potential issue_
**Add validation for `ItemId.$oid` before creating `ObjectId` in `convertUpgrade`**
In the `convertUpgrade` function, validate `ItemId.$oid` to prevent exceptions when creating a new `ObjectId`.
Apply this diff to add validation:
```diff
const convertUpgrade = (client: IUpgradeClient): IUpgradeDatabase => {
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)
};
};
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const convertUpgrade = (client: IUpgradeClient): IUpgradeDatabase => {
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)
};
};
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
|
||||
replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
|
||||
|
||||
![]() 🛠️ 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 -->
|
@ -24,10 +24,10 @@ export interface IInventoryDatabase
|
||||
| "BlessingCooldown"
|
||||
| "Ships"
|
||||
| "WeaponSkins"
|
||||
| "Suits"
|
||||
| "Upgrades"
|
||||
| "CrewShipSalvagedWeaponSkins"
|
||||
| "CrewShipWeaponSkins"
|
||||
| TEquipmentKey
|
||||
> {
|
||||
accountOwnerId: Types.ObjectId;
|
||||
Created: Date;
|
||||
@ -40,10 +40,23 @@ export interface IInventoryDatabase
|
||||
BlessingCooldown: Date;
|
||||
Ships: Types.ObjectId[];
|
||||
WeaponSkins: IWeaponSkinDatabase[];
|
||||
Suits: IEquipmentDatabase[];
|
||||
Upgrades: IUpgradeDatabase[];
|
||||
CrewShipSalvagedWeaponSkins: IUpgradeDatabase[];
|
||||
CrewShipWeaponSkins: IUpgradeDatabase[];
|
||||
|
||||
Suits: IEquipmentDatabase[];
|
||||
LongGuns: IEquipmentDatabase[];
|
||||
Pistols: IEquipmentDatabase[];
|
||||
Melee: IEquipmentDatabase[];
|
||||
SpecialItems: IEquipmentDatabase[];
|
||||
Sentinels: IEquipmentDatabase[];
|
||||
SentinelWeapons: IEquipmentDatabase[];
|
||||
SpaceSuits: IEquipmentDatabase[];
|
||||
SpaceGuns: IEquipmentDatabase[];
|
||||
SpaceMelee: IEquipmentDatabase[];
|
||||
Hoverboards: IEquipmentDatabase[];
|
||||
OperatorAmps: IEquipmentDatabase[];
|
||||
MoaPets: IEquipmentDatabase[];
|
||||
}
|
||||
|
||||
export interface IQuestKeyDatabase {
|
||||
@ -136,6 +149,20 @@ export interface IDailyAffiliations {
|
||||
}
|
||||
|
||||
export interface IInventoryClient extends IDailyAffiliations {
|
||||
Suits: IEquipmentClient[];
|
||||
LongGuns: IEquipmentClient[];
|
||||
Pistols: IEquipmentClient[];
|
||||
Melee: IEquipmentClient[];
|
||||
SpecialItems: IEquipmentClient[];
|
||||
Sentinels: IEquipmentClient[];
|
||||
SentinelWeapons: IEquipmentClient[];
|
||||
SpaceSuits: IEquipmentClient[];
|
||||
SpaceGuns: IEquipmentClient[];
|
||||
SpaceMelee: IEquipmentClient[];
|
||||
Hoverboards: IEquipmentClient[];
|
||||
OperatorAmps: IEquipmentClient[];
|
||||
MoaPets: IEquipmentClient[];
|
||||
|
||||
Horses: IEquipmentDatabase[];
|
||||
DrifterMelee: IEquipmentDatabase[];
|
||||
DrifterGuns: IEquipmentDatabase[];
|
||||
@ -172,10 +199,6 @@ export interface IInventoryClient extends IDailyAffiliations {
|
||||
ChallengeProgress: IChallengeProgress[];
|
||||
RawUpgrades: IRawUpgrade[];
|
||||
ReceivedStartingGear: boolean;
|
||||
Suits: IEquipmentClient[];
|
||||
LongGuns: IEquipmentDatabase[];
|
||||
Pistols: IEquipmentDatabase[];
|
||||
Melee: IEquipmentDatabase[];
|
||||
Ships: IShipInventory[];
|
||||
QuestKeys: IQuestKeyResponse[];
|
||||
FlavourItems: IFlavourItem[];
|
||||
@ -222,14 +245,9 @@ export interface IInventoryClient extends IDailyAffiliations {
|
||||
Affiliations: IAffiliation[];
|
||||
QualifyingInvasions: any[];
|
||||
FactionScores: number[];
|
||||
SpaceSuits: IEquipmentDatabase[];
|
||||
SpaceMelee: IEquipmentDatabase[];
|
||||
SpaceGuns: IEquipmentDatabase[];
|
||||
ArchwingEnabled: boolean;
|
||||
PendingSpectreLoadouts?: ISpectreLoadout[];
|
||||
SpectreLoadouts?: ISpectreLoadout[];
|
||||
SentinelWeapons: IEquipmentDatabase[];
|
||||
Sentinels: IEquipmentDatabase[];
|
||||
EmailItems: ITypeCount[];
|
||||
CompletedSyndicates: string[];
|
||||
FocusXP: IFocusXP;
|
||||
@ -246,13 +264,11 @@ export interface IInventoryClient extends IDailyAffiliations {
|
||||
CompletedJobs: ICompletedJob[];
|
||||
FocusAbility: string;
|
||||
FocusUpgrades: IFocusUpgrade[];
|
||||
OperatorAmps: IEquipmentDatabase[];
|
||||
HasContributedToDojo?: boolean;
|
||||
HWIDProtectEnabled?: boolean;
|
||||
KubrowPetPrints: IKubrowPetPrint[];
|
||||
AlignmentReplay: IAlignment;
|
||||
PersonalGoalProgress: IPersonalGoalProgress[];
|
||||
SpecialItems: IEquipmentDatabase[];
|
||||
ThemeStyle: string;
|
||||
ThemeBackground: string;
|
||||
ThemeSounds: string;
|
||||
@ -261,12 +277,10 @@ export interface IInventoryClient extends IDailyAffiliations {
|
||||
LoginMilestoneRewards: string[];
|
||||
OperatorLoadOuts: IOperatorConfigClient[];
|
||||
RecentVendorPurchases: Array<number | string>;
|
||||
Hoverboards: IEquipmentDatabase[];
|
||||
NodeIntrosCompleted: string[];
|
||||
GuildId?: IOid;
|
||||
CompletedJobChains: ICompletedJobChain[];
|
||||
SeasonChallengeHistory: ISeasonChallenge[];
|
||||
MoaPets: IEquipmentDatabase[];
|
||||
EquippedInstrument?: string;
|
||||
InvasionChainProgress: IInvasionChainProgress[];
|
||||
DataKnives: IEquipmentDatabase[];
|
||||
|
🛠️ 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.
🛠️ 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.