@playcademy/sandbox 0.1.0-beta.4 → 0.1.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +59 -26
- package/dist/server.js +59 -26
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -77525,7 +77525,7 @@ var userLevels = pgTable("user_levels", {
|
|
|
77525
77525
|
userId: text("user_id").primaryKey().references(() => users.id, { onDelete: "cascade" }),
|
|
77526
77526
|
currentLevel: integer("current_level").notNull().default(1),
|
|
77527
77527
|
currentXp: integer("current_xp").notNull().default(0),
|
|
77528
|
-
|
|
77528
|
+
totalXP: integer("total_xp").notNull().default(0),
|
|
77529
77529
|
lastLevelUpAt: timestamp("last_level_up_at", { withTimezone: true }),
|
|
77530
77530
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
77531
77531
|
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().$onUpdate(() => new Date)
|
|
@@ -77547,7 +77547,7 @@ var InsertUserLevelSchema = createInsertSchema(userLevels, {
|
|
|
77547
77547
|
userId: exports_external.string().min(1, "User ID is required"),
|
|
77548
77548
|
currentLevel: exports_external.number().int().min(1, "Level must be at least 1").default(1),
|
|
77549
77549
|
currentXp: exports_external.number().int().min(0, "XP cannot be negative").default(0),
|
|
77550
|
-
|
|
77550
|
+
totalXP: exports_external.number().int().min(0, "Total XP cannot be negative").default(0)
|
|
77551
77551
|
}).omit({ createdAt: true, updatedAt: true });
|
|
77552
77552
|
var SelectUserLevelSchema = createSelectSchema(userLevels);
|
|
77553
77553
|
var UpdateUserLevelSchema = createUpdateSchema(userLevels).omit({
|
|
@@ -77659,14 +77659,26 @@ async function seedDemoData(db) {
|
|
|
77659
77659
|
function generateLevelConfigs() {
|
|
77660
77660
|
const configs = [];
|
|
77661
77661
|
for (let level = 1;level <= 100; level++) {
|
|
77662
|
-
|
|
77663
|
-
|
|
77664
|
-
|
|
77665
|
-
|
|
77666
|
-
|
|
77667
|
-
|
|
77662
|
+
let xpRequired;
|
|
77663
|
+
if (level === 1) {
|
|
77664
|
+
xpRequired = 0;
|
|
77665
|
+
} else {
|
|
77666
|
+
const baseXp = Math.pow(level - 1, 1.8) * 100;
|
|
77667
|
+
let roundTo;
|
|
77668
|
+
if (level <= 10) {
|
|
77669
|
+
roundTo = 50;
|
|
77670
|
+
} else if (level <= 20) {
|
|
77671
|
+
roundTo = 100;
|
|
77672
|
+
} else if (level <= 50) {
|
|
77673
|
+
roundTo = 250;
|
|
77674
|
+
} else {
|
|
77675
|
+
roundTo = 500;
|
|
77668
77676
|
}
|
|
77677
|
+
xpRequired = Math.round(baseXp / roundTo) * roundTo;
|
|
77669
77678
|
}
|
|
77679
|
+
const baseReward = level === 1 ? 0 : 25 + (level - 1) * 25;
|
|
77680
|
+
const bonusReward = Math.floor((level - 1) / 10) * 50;
|
|
77681
|
+
const creditsReward = baseReward + bonusReward;
|
|
77670
77682
|
configs.push({
|
|
77671
77683
|
level,
|
|
77672
77684
|
xpRequired,
|
|
@@ -77710,7 +77722,7 @@ async function seedCurrentProjectGame(db, project) {
|
|
|
77710
77722
|
// package.json
|
|
77711
77723
|
var package_default = {
|
|
77712
77724
|
name: "@playcademy/sandbox",
|
|
77713
|
-
version: "0.1.0-beta.
|
|
77725
|
+
version: "0.1.0-beta.5",
|
|
77714
77726
|
description: "Local development server for Playcademy game development",
|
|
77715
77727
|
type: "module",
|
|
77716
77728
|
exports: {
|
|
@@ -77813,6 +77825,27 @@ async function getUserMe(ctx) {
|
|
|
77813
77825
|
}
|
|
77814
77826
|
}
|
|
77815
77827
|
|
|
77828
|
+
// ../data/src/constants.ts
|
|
77829
|
+
var ITEM_INTERNAL_NAMES = {
|
|
77830
|
+
PLAYCADEMY_CREDITS: "PLAYCADEMY_CREDITS",
|
|
77831
|
+
PLAYCADEMY_XP: "PLAYCADEMY_XP",
|
|
77832
|
+
FOUNDING_MEMBER_BADGE: "FOUNDING_MEMBER_BADGE",
|
|
77833
|
+
EARLY_ADOPTER_BADGE: "EARLY_ADOPTER_BADGE",
|
|
77834
|
+
FIRST_GAME_BADGE: "FIRST_GAME_BADGE",
|
|
77835
|
+
COMMON_SWORD: "COMMON_SWORD",
|
|
77836
|
+
SMALL_HEALTH_POTION: "SMALL_HEALTH_POTION",
|
|
77837
|
+
SMALL_BACKPACK: "SMALL_BACKPACK"
|
|
77838
|
+
};
|
|
77839
|
+
var CURRENCIES = {
|
|
77840
|
+
PRIMARY: ITEM_INTERNAL_NAMES.PLAYCADEMY_CREDITS,
|
|
77841
|
+
XP: ITEM_INTERNAL_NAMES.PLAYCADEMY_XP
|
|
77842
|
+
};
|
|
77843
|
+
var BADGES = {
|
|
77844
|
+
FOUNDING_MEMBER: ITEM_INTERNAL_NAMES.FOUNDING_MEMBER_BADGE,
|
|
77845
|
+
EARLY_ADOPTER: ITEM_INTERNAL_NAMES.EARLY_ADOPTER_BADGE,
|
|
77846
|
+
FIRST_GAME: ITEM_INTERNAL_NAMES.FIRST_GAME_BADGE
|
|
77847
|
+
};
|
|
77848
|
+
|
|
77816
77849
|
// ../api-core/src/utils/levels.ts
|
|
77817
77850
|
var levelConfigCache = null;
|
|
77818
77851
|
async function getLevelConfig(db, level) {
|
|
@@ -77904,7 +77937,7 @@ async function getUserLevel(ctx) {
|
|
|
77904
77937
|
userId: user.id,
|
|
77905
77938
|
currentLevel: 1,
|
|
77906
77939
|
currentXp: 0,
|
|
77907
|
-
|
|
77940
|
+
totalXP: 0
|
|
77908
77941
|
}).returning();
|
|
77909
77942
|
if (!newUserLevel) {
|
|
77910
77943
|
throw ApiError.internal("Failed to create user level record");
|
|
@@ -77937,7 +77970,7 @@ async function addXP(ctx, amount) {
|
|
|
77937
77970
|
userId: user.id,
|
|
77938
77971
|
currentLevel: 1,
|
|
77939
77972
|
currentXp: 0,
|
|
77940
|
-
|
|
77973
|
+
totalXP: 0
|
|
77941
77974
|
}).returning();
|
|
77942
77975
|
if (!newUserLevel) {
|
|
77943
77976
|
throw ApiError.internal("Failed to create user level record");
|
|
@@ -77945,12 +77978,12 @@ async function addXP(ctx, amount) {
|
|
|
77945
77978
|
userLevel = newUserLevel;
|
|
77946
77979
|
}
|
|
77947
77980
|
const newCurrentXp = userLevel.currentXp + amount;
|
|
77948
|
-
const
|
|
77981
|
+
const newTotalXP = userLevel.totalXP + amount;
|
|
77949
77982
|
const levelUpResult = await checkLevelUp(tx, userLevel.currentLevel, newCurrentXp);
|
|
77950
77983
|
const [updatedUserLevel] = await tx.update(userLevels).set({
|
|
77951
77984
|
currentLevel: levelUpResult.newLevel,
|
|
77952
77985
|
currentXp: levelUpResult.remainingXp,
|
|
77953
|
-
|
|
77986
|
+
totalXP: newTotalXP,
|
|
77954
77987
|
lastLevelUpAt: levelUpResult.leveledUp ? new Date : userLevel.lastLevelUpAt
|
|
77955
77988
|
}).where(eq(userLevels.userId, user.id)).returning();
|
|
77956
77989
|
if (!updatedUserLevel) {
|
|
@@ -77964,13 +77997,13 @@ async function addXP(ctx, amount) {
|
|
|
77964
77997
|
oldLevel: userLevel.currentLevel,
|
|
77965
77998
|
newLevel: levelUpResult.newLevel,
|
|
77966
77999
|
xpAdded: amount,
|
|
77967
|
-
|
|
78000
|
+
totalXP: newTotalXP,
|
|
77968
78001
|
creditsAwarded: creditsToAward
|
|
77969
78002
|
});
|
|
77970
78003
|
if (creditsToAward > 0) {
|
|
77971
|
-
const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName,
|
|
78004
|
+
const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName, CURRENCIES.PRIMARY)).limit(1);
|
|
77972
78005
|
if (!creditsItem) {
|
|
77973
|
-
throw ApiError.internal(
|
|
78006
|
+
throw ApiError.internal(`${CURRENCIES.PRIMARY} item not found`);
|
|
77974
78007
|
}
|
|
77975
78008
|
await tx.insert(inventoryItems).values({
|
|
77976
78009
|
userId: user.id,
|
|
@@ -77992,11 +78025,11 @@ async function addXP(ctx, amount) {
|
|
|
77992
78025
|
userId: user.id,
|
|
77993
78026
|
level: userLevel.currentLevel,
|
|
77994
78027
|
xpAdded: amount,
|
|
77995
|
-
|
|
78028
|
+
totalXP: newTotalXP
|
|
77996
78029
|
});
|
|
77997
78030
|
}
|
|
77998
78031
|
return {
|
|
77999
|
-
|
|
78032
|
+
totalXP: newTotalXP,
|
|
78000
78033
|
newLevel: levelUpResult.newLevel,
|
|
78001
78034
|
leveledUp: levelUpResult.leveledUp,
|
|
78002
78035
|
creditsAwarded,
|
|
@@ -78046,7 +78079,7 @@ async function getUserLevelProgress(ctx) {
|
|
|
78046
78079
|
level: userLevel.currentLevel,
|
|
78047
78080
|
currentXp: userLevel.currentXp,
|
|
78048
78081
|
xpToNextLevel,
|
|
78049
|
-
|
|
78082
|
+
totalXP: userLevel.totalXP
|
|
78050
78083
|
};
|
|
78051
78084
|
} catch (error2) {
|
|
78052
78085
|
if (error2 instanceof ApiError) {
|
|
@@ -78246,7 +78279,7 @@ async function addInventoryItem(ctx) {
|
|
|
78246
78279
|
throw ApiError.internal("Internal server error", error2);
|
|
78247
78280
|
}
|
|
78248
78281
|
}
|
|
78249
|
-
async function
|
|
78282
|
+
async function removeInventoryItem(ctx) {
|
|
78250
78283
|
const user = ctx.user;
|
|
78251
78284
|
if (!user) {
|
|
78252
78285
|
throw ApiError.unauthorized("Valid session or bearer token required");
|
|
@@ -78279,8 +78312,8 @@ async function spendInventoryItem(ctx) {
|
|
|
78279
78312
|
}
|
|
78280
78313
|
const [updatedItemRecord] = await tx.update(inventoryItems).set({ quantity: sql`${inventoryItems.quantity} - ${qty}` }).where(eq(inventoryItems.id, currentItem.id)).returning({ quantity: inventoryItems.quantity });
|
|
78281
78314
|
if (!updatedItemRecord) {
|
|
78282
|
-
logger2.error(`Failed to update inventory item ${currentItem.id} during
|
|
78283
|
-
throw ApiError.internal("Failed to update item quantity during
|
|
78315
|
+
logger2.error(`Failed to update inventory item ${currentItem.id} during remove operation.`);
|
|
78316
|
+
throw ApiError.internal("Failed to update item quantity during remove.");
|
|
78284
78317
|
}
|
|
78285
78318
|
return updatedItemRecord.quantity;
|
|
78286
78319
|
});
|
|
@@ -78289,7 +78322,7 @@ async function spendInventoryItem(ctx) {
|
|
|
78289
78322
|
if (error2 instanceof ApiError) {
|
|
78290
78323
|
throw error2;
|
|
78291
78324
|
}
|
|
78292
|
-
logger2.error(`Error
|
|
78325
|
+
logger2.error(`Error removing inventory item ${itemId} for user ${user.id}:`, error2);
|
|
78293
78326
|
throw ApiError.internal("Internal server error", error2);
|
|
78294
78327
|
}
|
|
78295
78328
|
}
|
|
@@ -78334,7 +78367,7 @@ inventoryRouter.post("/add", async (c2) => {
|
|
|
78334
78367
|
return c2.json({ error: message }, 500);
|
|
78335
78368
|
}
|
|
78336
78369
|
});
|
|
78337
|
-
inventoryRouter.post("/
|
|
78370
|
+
inventoryRouter.post("/remove", async (c2) => {
|
|
78338
78371
|
const ctx = {
|
|
78339
78372
|
user: c2.get("user"),
|
|
78340
78373
|
params: {},
|
|
@@ -78342,13 +78375,13 @@ inventoryRouter.post("/spend", async (c2) => {
|
|
|
78342
78375
|
request: c2.req.raw
|
|
78343
78376
|
};
|
|
78344
78377
|
try {
|
|
78345
|
-
const result = await
|
|
78378
|
+
const result = await removeInventoryItem(ctx);
|
|
78346
78379
|
return c2.json(result);
|
|
78347
78380
|
} catch (error2) {
|
|
78348
78381
|
if (error2 instanceof ApiError) {
|
|
78349
78382
|
return c2.json({ error: error2.message }, error2.statusCode);
|
|
78350
78383
|
}
|
|
78351
|
-
console.error("Error in
|
|
78384
|
+
console.error("Error in removeInventoryItem:", error2);
|
|
78352
78385
|
const message = error2 instanceof Error ? error2.message : "Internal server error";
|
|
78353
78386
|
return c2.json({ error: message }, 500);
|
|
78354
78387
|
}
|
package/dist/server.js
CHANGED
|
@@ -75615,7 +75615,7 @@ var userLevels = pgTable("user_levels", {
|
|
|
75615
75615
|
userId: text("user_id").primaryKey().references(() => users.id, { onDelete: "cascade" }),
|
|
75616
75616
|
currentLevel: integer("current_level").notNull().default(1),
|
|
75617
75617
|
currentXp: integer("current_xp").notNull().default(0),
|
|
75618
|
-
|
|
75618
|
+
totalXP: integer("total_xp").notNull().default(0),
|
|
75619
75619
|
lastLevelUpAt: timestamp("last_level_up_at", { withTimezone: true }),
|
|
75620
75620
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
75621
75621
|
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().$onUpdate(() => new Date)
|
|
@@ -75637,7 +75637,7 @@ var InsertUserLevelSchema = createInsertSchema(userLevels, {
|
|
|
75637
75637
|
userId: exports_external.string().min(1, "User ID is required"),
|
|
75638
75638
|
currentLevel: exports_external.number().int().min(1, "Level must be at least 1").default(1),
|
|
75639
75639
|
currentXp: exports_external.number().int().min(0, "XP cannot be negative").default(0),
|
|
75640
|
-
|
|
75640
|
+
totalXP: exports_external.number().int().min(0, "Total XP cannot be negative").default(0)
|
|
75641
75641
|
}).omit({ createdAt: true, updatedAt: true });
|
|
75642
75642
|
var SelectUserLevelSchema = createSelectSchema(userLevels);
|
|
75643
75643
|
var UpdateUserLevelSchema = createUpdateSchema(userLevels).omit({
|
|
@@ -75749,14 +75749,26 @@ async function seedDemoData(db) {
|
|
|
75749
75749
|
function generateLevelConfigs() {
|
|
75750
75750
|
const configs = [];
|
|
75751
75751
|
for (let level = 1;level <= 100; level++) {
|
|
75752
|
-
|
|
75753
|
-
|
|
75754
|
-
|
|
75755
|
-
|
|
75756
|
-
|
|
75757
|
-
|
|
75752
|
+
let xpRequired;
|
|
75753
|
+
if (level === 1) {
|
|
75754
|
+
xpRequired = 0;
|
|
75755
|
+
} else {
|
|
75756
|
+
const baseXp = Math.pow(level - 1, 1.8) * 100;
|
|
75757
|
+
let roundTo;
|
|
75758
|
+
if (level <= 10) {
|
|
75759
|
+
roundTo = 50;
|
|
75760
|
+
} else if (level <= 20) {
|
|
75761
|
+
roundTo = 100;
|
|
75762
|
+
} else if (level <= 50) {
|
|
75763
|
+
roundTo = 250;
|
|
75764
|
+
} else {
|
|
75765
|
+
roundTo = 500;
|
|
75758
75766
|
}
|
|
75767
|
+
xpRequired = Math.round(baseXp / roundTo) * roundTo;
|
|
75759
75768
|
}
|
|
75769
|
+
const baseReward = level === 1 ? 0 : 25 + (level - 1) * 25;
|
|
75770
|
+
const bonusReward = Math.floor((level - 1) / 10) * 50;
|
|
75771
|
+
const creditsReward = baseReward + bonusReward;
|
|
75760
75772
|
configs.push({
|
|
75761
75773
|
level,
|
|
75762
75774
|
xpRequired,
|
|
@@ -75800,7 +75812,7 @@ async function seedCurrentProjectGame(db, project) {
|
|
|
75800
75812
|
// package.json
|
|
75801
75813
|
var package_default = {
|
|
75802
75814
|
name: "@playcademy/sandbox",
|
|
75803
|
-
version: "0.1.0-beta.
|
|
75815
|
+
version: "0.1.0-beta.5",
|
|
75804
75816
|
description: "Local development server for Playcademy game development",
|
|
75805
75817
|
type: "module",
|
|
75806
75818
|
exports: {
|
|
@@ -75903,6 +75915,27 @@ async function getUserMe(ctx) {
|
|
|
75903
75915
|
}
|
|
75904
75916
|
}
|
|
75905
75917
|
|
|
75918
|
+
// ../data/src/constants.ts
|
|
75919
|
+
var ITEM_INTERNAL_NAMES = {
|
|
75920
|
+
PLAYCADEMY_CREDITS: "PLAYCADEMY_CREDITS",
|
|
75921
|
+
PLAYCADEMY_XP: "PLAYCADEMY_XP",
|
|
75922
|
+
FOUNDING_MEMBER_BADGE: "FOUNDING_MEMBER_BADGE",
|
|
75923
|
+
EARLY_ADOPTER_BADGE: "EARLY_ADOPTER_BADGE",
|
|
75924
|
+
FIRST_GAME_BADGE: "FIRST_GAME_BADGE",
|
|
75925
|
+
COMMON_SWORD: "COMMON_SWORD",
|
|
75926
|
+
SMALL_HEALTH_POTION: "SMALL_HEALTH_POTION",
|
|
75927
|
+
SMALL_BACKPACK: "SMALL_BACKPACK"
|
|
75928
|
+
};
|
|
75929
|
+
var CURRENCIES = {
|
|
75930
|
+
PRIMARY: ITEM_INTERNAL_NAMES.PLAYCADEMY_CREDITS,
|
|
75931
|
+
XP: ITEM_INTERNAL_NAMES.PLAYCADEMY_XP
|
|
75932
|
+
};
|
|
75933
|
+
var BADGES = {
|
|
75934
|
+
FOUNDING_MEMBER: ITEM_INTERNAL_NAMES.FOUNDING_MEMBER_BADGE,
|
|
75935
|
+
EARLY_ADOPTER: ITEM_INTERNAL_NAMES.EARLY_ADOPTER_BADGE,
|
|
75936
|
+
FIRST_GAME: ITEM_INTERNAL_NAMES.FIRST_GAME_BADGE
|
|
75937
|
+
};
|
|
75938
|
+
|
|
75906
75939
|
// ../api-core/src/utils/levels.ts
|
|
75907
75940
|
var levelConfigCache = null;
|
|
75908
75941
|
async function getLevelConfig(db, level) {
|
|
@@ -75994,7 +76027,7 @@ async function getUserLevel(ctx) {
|
|
|
75994
76027
|
userId: user.id,
|
|
75995
76028
|
currentLevel: 1,
|
|
75996
76029
|
currentXp: 0,
|
|
75997
|
-
|
|
76030
|
+
totalXP: 0
|
|
75998
76031
|
}).returning();
|
|
75999
76032
|
if (!newUserLevel) {
|
|
76000
76033
|
throw ApiError.internal("Failed to create user level record");
|
|
@@ -76027,7 +76060,7 @@ async function addXP(ctx, amount) {
|
|
|
76027
76060
|
userId: user.id,
|
|
76028
76061
|
currentLevel: 1,
|
|
76029
76062
|
currentXp: 0,
|
|
76030
|
-
|
|
76063
|
+
totalXP: 0
|
|
76031
76064
|
}).returning();
|
|
76032
76065
|
if (!newUserLevel) {
|
|
76033
76066
|
throw ApiError.internal("Failed to create user level record");
|
|
@@ -76035,12 +76068,12 @@ async function addXP(ctx, amount) {
|
|
|
76035
76068
|
userLevel = newUserLevel;
|
|
76036
76069
|
}
|
|
76037
76070
|
const newCurrentXp = userLevel.currentXp + amount;
|
|
76038
|
-
const
|
|
76071
|
+
const newTotalXP = userLevel.totalXP + amount;
|
|
76039
76072
|
const levelUpResult = await checkLevelUp(tx, userLevel.currentLevel, newCurrentXp);
|
|
76040
76073
|
const [updatedUserLevel] = await tx.update(userLevels).set({
|
|
76041
76074
|
currentLevel: levelUpResult.newLevel,
|
|
76042
76075
|
currentXp: levelUpResult.remainingXp,
|
|
76043
|
-
|
|
76076
|
+
totalXP: newTotalXP,
|
|
76044
76077
|
lastLevelUpAt: levelUpResult.leveledUp ? new Date : userLevel.lastLevelUpAt
|
|
76045
76078
|
}).where(eq(userLevels.userId, user.id)).returning();
|
|
76046
76079
|
if (!updatedUserLevel) {
|
|
@@ -76054,13 +76087,13 @@ async function addXP(ctx, amount) {
|
|
|
76054
76087
|
oldLevel: userLevel.currentLevel,
|
|
76055
76088
|
newLevel: levelUpResult.newLevel,
|
|
76056
76089
|
xpAdded: amount,
|
|
76057
|
-
|
|
76090
|
+
totalXP: newTotalXP,
|
|
76058
76091
|
creditsAwarded: creditsToAward
|
|
76059
76092
|
});
|
|
76060
76093
|
if (creditsToAward > 0) {
|
|
76061
|
-
const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName,
|
|
76094
|
+
const [creditsItem] = await tx.select({ id: items.id }).from(items).where(eq(items.internalName, CURRENCIES.PRIMARY)).limit(1);
|
|
76062
76095
|
if (!creditsItem) {
|
|
76063
|
-
throw ApiError.internal(
|
|
76096
|
+
throw ApiError.internal(`${CURRENCIES.PRIMARY} item not found`);
|
|
76064
76097
|
}
|
|
76065
76098
|
await tx.insert(inventoryItems).values({
|
|
76066
76099
|
userId: user.id,
|
|
@@ -76082,11 +76115,11 @@ async function addXP(ctx, amount) {
|
|
|
76082
76115
|
userId: user.id,
|
|
76083
76116
|
level: userLevel.currentLevel,
|
|
76084
76117
|
xpAdded: amount,
|
|
76085
|
-
|
|
76118
|
+
totalXP: newTotalXP
|
|
76086
76119
|
});
|
|
76087
76120
|
}
|
|
76088
76121
|
return {
|
|
76089
|
-
|
|
76122
|
+
totalXP: newTotalXP,
|
|
76090
76123
|
newLevel: levelUpResult.newLevel,
|
|
76091
76124
|
leveledUp: levelUpResult.leveledUp,
|
|
76092
76125
|
creditsAwarded,
|
|
@@ -76136,7 +76169,7 @@ async function getUserLevelProgress(ctx) {
|
|
|
76136
76169
|
level: userLevel.currentLevel,
|
|
76137
76170
|
currentXp: userLevel.currentXp,
|
|
76138
76171
|
xpToNextLevel,
|
|
76139
|
-
|
|
76172
|
+
totalXP: userLevel.totalXP
|
|
76140
76173
|
};
|
|
76141
76174
|
} catch (error2) {
|
|
76142
76175
|
if (error2 instanceof ApiError) {
|
|
@@ -76336,7 +76369,7 @@ async function addInventoryItem(ctx) {
|
|
|
76336
76369
|
throw ApiError.internal("Internal server error", error2);
|
|
76337
76370
|
}
|
|
76338
76371
|
}
|
|
76339
|
-
async function
|
|
76372
|
+
async function removeInventoryItem(ctx) {
|
|
76340
76373
|
const user = ctx.user;
|
|
76341
76374
|
if (!user) {
|
|
76342
76375
|
throw ApiError.unauthorized("Valid session or bearer token required");
|
|
@@ -76369,8 +76402,8 @@ async function spendInventoryItem(ctx) {
|
|
|
76369
76402
|
}
|
|
76370
76403
|
const [updatedItemRecord] = await tx.update(inventoryItems).set({ quantity: sql`${inventoryItems.quantity} - ${qty}` }).where(eq(inventoryItems.id, currentItem.id)).returning({ quantity: inventoryItems.quantity });
|
|
76371
76404
|
if (!updatedItemRecord) {
|
|
76372
|
-
logger2.error(`Failed to update inventory item ${currentItem.id} during
|
|
76373
|
-
throw ApiError.internal("Failed to update item quantity during
|
|
76405
|
+
logger2.error(`Failed to update inventory item ${currentItem.id} during remove operation.`);
|
|
76406
|
+
throw ApiError.internal("Failed to update item quantity during remove.");
|
|
76374
76407
|
}
|
|
76375
76408
|
return updatedItemRecord.quantity;
|
|
76376
76409
|
});
|
|
@@ -76379,7 +76412,7 @@ async function spendInventoryItem(ctx) {
|
|
|
76379
76412
|
if (error2 instanceof ApiError) {
|
|
76380
76413
|
throw error2;
|
|
76381
76414
|
}
|
|
76382
|
-
logger2.error(`Error
|
|
76415
|
+
logger2.error(`Error removing inventory item ${itemId} for user ${user.id}:`, error2);
|
|
76383
76416
|
throw ApiError.internal("Internal server error", error2);
|
|
76384
76417
|
}
|
|
76385
76418
|
}
|
|
@@ -76424,7 +76457,7 @@ inventoryRouter.post("/add", async (c2) => {
|
|
|
76424
76457
|
return c2.json({ error: message }, 500);
|
|
76425
76458
|
}
|
|
76426
76459
|
});
|
|
76427
|
-
inventoryRouter.post("/
|
|
76460
|
+
inventoryRouter.post("/remove", async (c2) => {
|
|
76428
76461
|
const ctx = {
|
|
76429
76462
|
user: c2.get("user"),
|
|
76430
76463
|
params: {},
|
|
@@ -76432,13 +76465,13 @@ inventoryRouter.post("/spend", async (c2) => {
|
|
|
76432
76465
|
request: c2.req.raw
|
|
76433
76466
|
};
|
|
76434
76467
|
try {
|
|
76435
|
-
const result = await
|
|
76468
|
+
const result = await removeInventoryItem(ctx);
|
|
76436
76469
|
return c2.json(result);
|
|
76437
76470
|
} catch (error2) {
|
|
76438
76471
|
if (error2 instanceof ApiError) {
|
|
76439
76472
|
return c2.json({ error: error2.message }, error2.statusCode);
|
|
76440
76473
|
}
|
|
76441
|
-
console.error("Error in
|
|
76474
|
+
console.error("Error in removeInventoryItem:", error2);
|
|
76442
76475
|
const message = error2 instanceof Error ? error2.message : "Internal server error";
|
|
76443
76476
|
return c2.json({ error: message }, 500);
|
|
76444
76477
|
}
|