-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeleteUser.ts
More file actions
35 lines (22 loc) · 916 Bytes
/
deleteUser.ts
File metadata and controls
35 lines (22 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Request, Response } from 'express'
import { authenticationData } from '../types/authenticationData'
import { getTokenData } from '../services/authenticator'
import { USER_ROLES } from '../types/users'
import delUser from '../data/delUser'
export default async function deleteUser (req: Request, res: Response) {
try {
const id: string = req.params.id as string
const token: string = req.headers.authorization as string
const tokenData: authenticationData = getTokenData(token)
if (tokenData.role !== USER_ROLES.ADMIN) {
res.statusCode = 401
throw new Error('Funcionalidade permitida somente para usuários "ADMIN"!')
}
await delUser(id)
res.status(200).send("Usuário deletado com sucesso!")
} catch (error) {
res.send({
message: error.message || error.sqlMessage
})
}
}