chore: initial commit
This commit is contained in:
30
src/services/users/[userId]/get.ts
Normal file
30
src/services/users/[userId]/get.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Request, Response, Router } from 'express'
|
||||
|
||||
import User from '../../../models/User'
|
||||
import UserSetting from '../../../models/UserSetting'
|
||||
import { NotFoundError } from '../../../tools/errors/NotFoundError'
|
||||
|
||||
export const getUsersRouter = Router()
|
||||
|
||||
getUsersRouter.get(
|
||||
'/users/:userId',
|
||||
[],
|
||||
async (req: Request, res: Response) => {
|
||||
const { userId } = req.params as { userId: string }
|
||||
const user = await User.findOne({ where: { id: userId } })
|
||||
if (user == null) {
|
||||
throw new NotFoundError()
|
||||
}
|
||||
const userSettings = await UserSetting.findOne({
|
||||
where: { userId: user.id }
|
||||
})
|
||||
if (userSettings == null) {
|
||||
throw new NotFoundError()
|
||||
}
|
||||
const result = Object.assign({}, user.toJSON())
|
||||
if (!userSettings.isPublicEmail) {
|
||||
delete result.email
|
||||
}
|
||||
return res.status(200).json({ user: result })
|
||||
}
|
||||
)
|
Reference in New Issue
Block a user