chanmged app.ts based on Onyxoasis's recommendations
This commit is contained in:
@@ -172,57 +172,7 @@ const decodeJwtPayload = (token: string) => {
|
||||
};
|
||||
|
||||
const ensureProfileDefaults = async (profileId: string) => {
|
||||
<<<<<<< HEAD
|
||||
await pool.query(
|
||||
`UPDATE calibers
|
||||
SET name = '12 Gauge - Sporting',
|
||||
is_default = TRUE
|
||||
WHERE profile_id = $1
|
||||
AND name = '12 Gauge'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM calibers existing
|
||||
WHERE existing.profile_id = $1
|
||||
AND existing.name = '12 Gauge - Sporting'
|
||||
)`,
|
||||
[profileId],
|
||||
);
|
||||
|
||||
await pool.query(
|
||||
`UPDATE calibers
|
||||
SET name = '12 Gauge - Sporting',
|
||||
is_default = TRUE
|
||||
WHERE profile_id = $1
|
||||
AND name = '12 Gauge Sporting'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM calibers existing
|
||||
WHERE existing.profile_id = $1
|
||||
AND existing.name = '12 Gauge - Sporting'
|
||||
)`,
|
||||
[profileId],
|
||||
);
|
||||
|
||||
for (const caliber of defaultCalibers) {
|
||||
const caliberResult = await pool.query<CaliberRow>(
|
||||
`INSERT INTO calibers (profile_id, name, is_default, is_active)
|
||||
VALUES ($1, $2, TRUE, TRUE)
|
||||
ON CONFLICT (profile_id, name) DO UPDATE
|
||||
SET is_default = TRUE
|
||||
RETURNING id, name, is_default, is_active`,
|
||||
[profileId, caliber],
|
||||
);
|
||||
|
||||
await pool.query(
|
||||
`INSERT INTO ammo_inventory (profile_id, caliber_id, rounds_on_hand, cost_per_round)
|
||||
VALUES ($1, $2, 0, 0)
|
||||
ON CONFLICT (profile_id, caliber_id) DO NOTHING`,
|
||||
[profileId, caliberResult.rows[0].id],
|
||||
);
|
||||
}
|
||||
=======
|
||||
await db.ensureProfileDefaults(profileId, defaultCalibers);
|
||||
>>>>>>> bcd4459 (chanmged app.ts based on Onyxoasis's recommendations)
|
||||
};
|
||||
|
||||
const getUserProfiles = async (userId: string) => db.getUserProfiles(userId);
|
||||
|
||||
@@ -243,6 +243,36 @@ export class ArsenalIqClient {
|
||||
}
|
||||
|
||||
async ensureProfileDefaults(profileId: string, defaultCalibers: string[]) {
|
||||
await this.pool.query(
|
||||
`UPDATE calibers
|
||||
SET name = '12 Gauge - Sporting',
|
||||
is_default = TRUE
|
||||
WHERE profile_id = $1
|
||||
AND name = '12 Gauge'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM calibers existing
|
||||
WHERE existing.profile_id = $1
|
||||
AND existing.name = '12 Gauge - Sporting'
|
||||
)`,
|
||||
[profileId],
|
||||
);
|
||||
|
||||
await this.pool.query(
|
||||
`UPDATE calibers
|
||||
SET name = '12 Gauge - Sporting',
|
||||
is_default = TRUE
|
||||
WHERE profile_id = $1
|
||||
AND name = '12 Gauge Sporting'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM calibers existing
|
||||
WHERE existing.profile_id = $1
|
||||
AND existing.name = '12 Gauge - Sporting'
|
||||
)`,
|
||||
[profileId],
|
||||
);
|
||||
|
||||
for (const caliber of defaultCalibers) {
|
||||
const caliberResult = await this.pool.query<CaliberRow>(
|
||||
`INSERT INTO calibers (profile_id, name, is_default, is_active)
|
||||
|
||||
Reference in New Issue
Block a user