Skip to content

Commit

Permalink
add a try/catch to upsertpostgres
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 4, 2023
1 parent 11567cd commit ce4e32b
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions store/queries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,30 +1018,34 @@ function insertMatch(match, options, cb) {
// We need the basic match data to run the check, so only do it if type is api
return cb();
}
// Check if leagueid is premium/professional
const result = match.leagueid
? await db.raw(
`select leagueid from leagues where leagueid = ? and (tier = 'premium' OR tier = 'professional')`,
[match.leagueid]
)
: null;
const pass = result?.rows?.length > 0;
if (!pass) {
// Skip this if not a pro match
return cb();
}
const trx = await db.transaction();
try {
await upsertMatch();
await upsertPlayerMatches();
await upsertPicksBans();
await upsertMatchPatch();
await upsertTeamMatch();
await updateTeamRankings(match, options);
await trx.commit();
return cb();
// Check if leagueid is premium/professional
const result = match.leagueid
? await db.raw(
`select leagueid from leagues where leagueid = ? and (tier = 'premium' OR tier = 'professional')`,
[match.leagueid]
)
: null;
const pass = result?.rows?.length > 0;
if (!pass) {
// Skip this if not a pro match
return cb();
}
const trx = await db.transaction();
try {
await upsertMatch();
await upsertPlayerMatches();
await upsertPicksBans();
await upsertMatchPatch();
await upsertTeamMatch();
await updateTeamRankings(match, options);
await trx.commit();
return cb();
} catch (e) {
trx.rollback();
return cb(e);
}
} catch (e) {
trx.rollback();
return cb(e);
}
async function upsertMatch() {
Expand Down

0 comments on commit ce4e32b

Please sign in to comment.