登录:初始登录onEntryData添加try catch

This commit is contained in:
luying
2022-06-13 16:56:58 +08:00
parent 106fb3ce39
commit 748588635a
+105 -100
View File
@@ -105,108 +105,113 @@ export async function pushData(hasInit: boolean, role: RoleType, session: Fronte
} }
export async function getModuleData(type: string, data: { role: RoleType, session: FrontendOrBackendSession }, guildData: { hasGuild: boolean, guild?: GuildType, userGuild?: UserGuildType, guildResult?: any } = { hasGuild: false }) { export async function getModuleData(type: string, data: { role: RoleType, session: FrontendOrBackendSession }, guildData: { hasGuild: boolean, guild?: GuildType, userGuild?: UserGuildType, guildResult?: any } = { hasGuild: false }) {
let { role, session } = data; try {
const { roleId, serverId, roleName, guildCode } = role; let { role, session } = data;
let { hasGuild, guild, userGuild, guildResult } = guildData; const { roleId, serverId, roleName, guildCode } = role;
switch (type) { let { hasGuild, guild, userGuild, guildResult } = guildData;
case 'role': switch (type) {
let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true); case 'role':
let jewels = await JewelModel.findbyRole(role.roleId, JEWEL_SELECT.ENTRY); let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
let items = await ItemModel.findbyRole(role.roleId, ITEM_SELECT.ENTRY); let jewels = await JewelModel.findbyRole(role.roleId, JEWEL_SELECT.ENTRY);
let skins = await SkinModel.findbyRole(role.roleId, SKIN_SELECT.ENTRY); let items = await ItemModel.findbyRole(role.roleId, ITEM_SELECT.ENTRY);
let skins = await SkinModel.findbyRole(role.roleId, SKIN_SELECT.ENTRY);
role['heros'] = heros.map(hero => new HeroParam(hero)); role['heros'] = heros.map(hero => new HeroParam(hero));
role['jewels'] = jewels; role['jewels'] = jewels;
role['consumeGoods'] = items; role['consumeGoods'] = items;
role['skins'] = skins; role['skins'] = skins;
let apJson = await getAp(role.roleId, '', role.lv); let apJson = await getAp(role.roleId, '', role.lv);
role['apJson'] = apJson; role['apJson'] = apJson;
if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid); if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid);
role.heads = role.heads.filter(cur => cur.status); role.heads = role.heads.filter(cur => cur.status);
role.frames = role.frames.filter(cur => cur.status); role.frames = role.frames.filter(cur => cur.status);
role.spines = role.spines.filter(cur => cur.status); role.spines = role.spines.filter(cur => cur.status);
return pick(role, ENTERY_ROLE_PICK); return pick(role, ENTERY_ROLE_PICK);
case 'shop': // 商店 case 'shop': // 商店
return await getAllShopList(roleId); return await getAllShopList(roleId);
case 'rank': // 排名 case 'rank': // 排名
const rewards = await getRankFirstReward(role, serverId); const rewards = await getRankFirstReward(role, serverId);
return { rewards } return { rewards }
case 'mail': // 邮件 case 'mail': // 邮件
return await getMails(roleId, serverId); return await getMails(roleId, serverId);
case 'friend': // 好友 case 'friend': // 好友
const friendList = await getFriendList(role); const friendList = await getFriendList(role);
const applyList = await getApplyList(roleId); const applyList = await getApplyList(roleId);
return { friendList, applyList } return { friendList, applyList }
case 'daily': // 每日 case 'daily': // 每日
return await getDailyBattleList(role); return await getDailyBattleList(role);
case 'expedition': // 远征 case 'expedition': // 远征
return await getExpeditionStatus(roleId, roleName, true); return await getExpeditionStatus(roleId, roleName, true);
case 'tower': // 镇念塔 case 'tower': // 镇念塔
return await getTowerEntryData(role); return await getTowerEntryData(role);
case 'comBattle': // 寻宝 case 'comBattle': // 寻宝
const assistCnt = await getAllAssistCnt(roleId); const assistCnt = await getAllAssistCnt(roleId);
const blueprts = await Item.findByRoleAndType(roleId, CONSUME_TYPE.BLUEPRT); const blueprts = await Item.findByRoleAndType(roleId, CONSUME_TYPE.BLUEPRT);
return { assistCnt, blueprts } return { assistCnt, blueprts }
case 'dungeon': // 秘境 case 'dungeon': // 秘境
return await getDungeonData(role); return await getDungeonData(role);
case 'pvp': // pvp case 'pvp': // pvp
return await getPvpEntryData(roleId); return await getPvpEntryData(roleId);
case 'gacha': case 'gacha':
const { gachaHasGuide } = role; const { gachaHasGuide } = role;
const gachalist = await getGachaList(roleId); const gachalist = await getGachaList(roleId);
const visitList = await getVisitedHeroList(roleId); const visitList = await getVisitedHeroList(roleId);
return { hasInit: !!gachaHasGuide, gachalist, visitList } return { hasInit: !!gachaHasGuide, gachalist, visitList }
case 'school': case 'school':
return await getSchoolList(roleId); return await getSchoolList(roleId);
case 'guild': case 'guild':
let invitation = await getInvitationList(roleId, ''); let invitation = await getInvitationList(roleId, '');
return { ...guildResult, invitation }; return { ...guildResult, invitation };
case 'auction': case 'auction':
return hasGuild ? await getAuction(guildCode, session) : null; return hasGuild ? await getAuction(guildCode, session) : null;
case 'train': case 'train':
if (hasGuild) { if (hasGuild) {
let trainInstance = await getGuildTrainInstance(roleId, guild, userGuild); let trainInstance = await getGuildTrainInstance(roleId, guild, userGuild);
let trainBoxRewards = await getTrainBoxRewardsResult(guildCode); let trainBoxRewards = await getTrainBoxRewardsResult(guildCode);
return { trainInstance, trainBoxRewards } return { trainInstance, trainBoxRewards }
} }
break; break;
case 'boss': case 'boss':
if (hasGuild) { if (hasGuild) {
return await getBossInstanceInfo(userGuild, guild); return await getBossInstanceInfo(userGuild, guild);
} }
return null; return null;
case 'wishPool': case 'wishPool':
return hasGuild ? await getWishPool(userGuild) : null; return hasGuild ? await getWishPool(userGuild) : null;
case 'donate': case 'donate':
if (hasGuild) { if (hasGuild) {
const { guildCode: code, donateCnt, receiveBoxs } = userGuild; const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
let { donateFund, reports, donationLv } = await getDonation(code, guild); let { donateFund, reports, donationLv } = await getDonation(code, guild);
return { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv }; return { receiveBoxs, donateFund, reports, donateCnt: donateCnt || 0, donationLv };
} }
break; break;
case 'task': case 'task':
let tasks = await getCurTask(role.roleId, session); let tasks = await getCurTask(role.roleId, session);
let pvpTask = await getPvpTask(role.roleId); let pvpTask = await getPvpTask(role.roleId);
return {...tasks, pvpTask} return {...tasks, pvpTask}
case 'chat': case 'chat':
const worldMsgs = await recentWorldMsgs(serverId); const worldMsgs = await recentWorldMsgs(serverId);
const sysMsgs = await recentSysMsgs(serverId); const sysMsgs = await recentSysMsgs(serverId);
const guildMsgs = await recentGuildMsgs(guildCode); const guildMsgs = await recentGuildMsgs(guildCode);
const recentPrivateChats = await recentPrivateChatInfos(roleId, roleName); const recentPrivateChats = await recentPrivateChatInfos(roleId, roleName);
return { worldMsgs, sysMsgs, guildMsgs, recentPrivateChats }; return { worldMsgs, sysMsgs, guildMsgs, recentPrivateChats };
case 'event': case 'event':
return await getEvent(role.eventStatus, roleId, roleName); return await getEvent(role.eventStatus, roleId, roleName);
case 'battle': case 'battle':
return await getBattleListOfMain(role); return await getBattleListOfMain(role);
case 'guildActivity': case 'guildActivity':
return getAllGuildActivityStatus(role.guildCode, role.serverId); return getAllGuildActivityStatus(role.guildCode, role.serverId);
case 'chapter': case 'chapter':
return getMainChapter(role); return getMainChapter(role);
case 'survey': case 'survey':
return await getSurvey(role.roleId, role.lv); return await getSurvey(role.roleId, role.lv);
default: default:
return null; return null;
}
} catch (e) {
console.error(e.stack);
return false
} }
} }