feat: Auto-fix cost_credits <= 0 to 3 on every furniture import
- Extended fixDatabaseConsistencyAfterImport() to also set cost_credits = 3 where <= 0 - Integrated into both single and batch import routes - API responses now include costCreditsFixed count Ensures 100% of catalog_items have cost_credits > 0 after import - Typecheck, lint, tests all pass - Pushed to GitLab
This commit is contained in:
1 parent
86f3d82c5d
commit
0b0cf4f37f
3 files changed
+30
-14
No files matched your search
@@ -1089,10 +1089,12 @@ async function realNitroModes(classname: string): Promise<number | undefined> {
|
||||
/** Fix database consistency after import:
|
||||
* 1. Fill empty catalog_name from items_base.public_name
|
||||
* 2. Set have_offer = '1' where it was '0'
|
||||
* Returns { catalogNameFixed, haveOfferFixed } with counts. */
|
||||
* 3. Set cost_credits = 3 where it was <= 0
|
||||
* Returns { catalogNameFixed, haveOfferFixed, costCreditsFixed } with counts. */
|
||||
export async function fixDatabaseConsistencyAfterImport(): Promise<{
|
||||
catalogNameFixed: number;
|
||||
haveOfferFixed: number;
|
||||
costCreditsFixed: number;
|
||||
}> {
|
||||
// 1. Fill empty catalog_name from items_base.public_name
|
||||
const [nameResult] = (await db.execute(sql`
|
||||
@@ -1114,7 +1116,15 @@ export async function fixDatabaseConsistencyAfterImport(): Promise<{
|
||||
`)) as unknown as [Record<string, unknown>, unknown];
|
||||
const haveOfferFixed = Number(offerResult.affectedRows ?? 0);
|
||||
|
||||
return { catalogNameFixed, haveOfferFixed };
|
||||
// 3. Set cost_credits = 3 where it was <= 0
|
||||
const [creditResult] = (await db.execute(sql`
|
||||
UPDATE catalog_items
|
||||
SET cost_credits = 3
|
||||
WHERE cost_credits <= 0
|
||||
`)) as unknown as [Record<string, unknown>, unknown];
|
||||
const costCreditsFixed = Number(creditResult.affectedRows ?? 0);
|
||||
|
||||
return { catalogNameFixed, haveOfferFixed, costCreditsFixed };
|
||||
}
|
||||
|
||||
/** Verify and fix interaction values for ALL furniture in items_base.
|
||||
|
||||
Reference in new issue
Block a user