⛄ Snowberb ⛄ – 07-50 Jul 5

How can I accomplish the same but in a cleaner way?
export const getStaticProps: GetStaticProps = async () => {
const { bettingBonuses, casinoBonuses } = getBonuses
const { getAccounts, getTransactions } = getAccountInfo
let savedBonuses: IBonus[] = []
let savedCasinoBonuses: IBonus[] = []
let savedBets: Bet[] = []
let savedAccounts: Account[] = []
let savedTransactions: Transaction[] = []

try {
const promises = await Promise.allSettled([
bettingBonuses(),
casinoBonuses(),
getBets(),
getAccounts(),
getTransactions(),
])
const filteredPromises = promises.map((promise) =>
promise.status === 'fulfilled' ? promise.value : []
)

savedBonuses = filteredPromises[0] as IBonus[]
savedCasinoBonuses = filteredPromises[1] as IBonus[]
savedBets = filteredPromises[2] as Bet[]
savedAccounts = filteredPromises[3] as Account[]
savedTransactions = filteredPromises[4] as Transaction[]
} catch (err) {}

return {
props: {
savedBonuses,
savedCasinoBonuses,
savedBets,
savedAccounts,
savedTransactions,
},
}
}
export const getStaticProps: GetStaticProps = async () => {
const { bettingBonuses, casinoBonuses } = getBonuses
const { getAccounts, getTransactions } = getAccountInfo
let savedBonuses: IBonus[] = []
let savedCasinoBonuses: IBonus[] = []
let savedBets: Bet[] = []
let savedAccounts: Account[] = []
let savedTransactions: Transaction[] = []

try {
const promises = await Promise.allSettled([
bettingBonuses(),
casinoBonuses(),
getBets(),
getAccounts(),
getTransactions(),
])
const filteredPromises = promises.map((promise) =>
promise.status === 'fulfilled' ? promise.value : []
)

savedBonuses = filteredPromises[0] as IBonus[]
savedCasinoBonuses = filteredPromises[1] as IBonus[]
savedBets = filteredPromises[2] as Bet[]
savedAccounts = filteredPromises[3] as Account[]
savedTransactions = filteredPromises[4] as Transaction[]
} catch (err) {}

return {
props: {
savedBonuses,
savedCasinoBonuses,
savedBets,
savedAccounts,
savedTransactions,
},
}
}
UU
Unknown User653d ago