You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
34 lines
1.1 KiB
const { adminService, courseService, referralService, repository } = require('../services')
|
|
const { hasPermission } = require('../constants/permissions')
|
|
|
|
async function getBootstrap(req, res, next) {
|
|
try {
|
|
const profile = await repository.findUserById(req.account.id)
|
|
if (!profile) {
|
|
const error = new Error('账号不存在')
|
|
error.status = 404
|
|
throw error
|
|
}
|
|
const safeProfile = await repository.withPermissions(profile)
|
|
const account = await repository.getPointAccount(profile.id)
|
|
const referralCenter = await referralService.getCenter(profile.id)
|
|
|
|
res.json({
|
|
ok: true,
|
|
data: {
|
|
profile: { ...safeProfile, points: account },
|
|
points: account,
|
|
stats: referralCenter.stats,
|
|
referralStats: referralCenter.stats,
|
|
rules: referralCenter.rules,
|
|
courses: await courseService.listCourses(),
|
|
admin: hasPermission(safeProfile, ['dashboard:overview:view']) ? await adminService.getDashboard() : null,
|
|
},
|
|
})
|
|
} catch (error) {
|
|
next(error)
|
|
}
|
|
}
|
|
|
|
module.exports = { getBootstrap }
|