mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Login route: Send associated locality ids on login
This commit is contained in:
@@ -25,10 +25,18 @@ router.post('/login', async (req, res) => {
|
||||
expiresIn: LOGIN_VALID_MS,
|
||||
})
|
||||
|
||||
const personResult = await nowDb.com_people.findFirst({ where: { user_id: foundUser.user_id } })
|
||||
const personResult = await nowDb.com_people.findFirst({
|
||||
where: { user_id: foundUser.user_id },
|
||||
select: {
|
||||
initials: true,
|
||||
now_proj: { select: { now_plr: { select: { now_loc: { select: { lid: true } } } } } },
|
||||
},
|
||||
})
|
||||
|
||||
if (!personResult) throw new Error('User found but not person; this should not happen.')
|
||||
|
||||
const associatedLocalityIds = personResult.now_proj.flatMap(proj => proj.now_plr.map(plr => plr.now_loc.lid))
|
||||
|
||||
await nowDb.com_users.update({ where: { user_id: foundUser.user_id }, data: { last_login: new Date() } })
|
||||
|
||||
return res.status(200).send({
|
||||
@@ -36,6 +44,7 @@ router.post('/login', async (req, res) => {
|
||||
username: foundUser.user_name,
|
||||
role: getRole(foundUser.now_user_group ?? ''),
|
||||
initials: personResult.initials,
|
||||
localities: associatedLocalityIds,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user