push
github
371 of 585 branches covered (0.0%)
Branch coverage included in aggregate %.
1161 of 1161 new or added lines in 45 files covered. (100.0%)
6008 of 13061 relevant lines covered (46.0%)
0.91 hits per line
|
import SQL from '@nearform/sql' |
|
|
|
2✔ |
|
export async function deleteAdminUser (fastify, opts) { |
|
|
fastify.delete(
|
2✔ |
|
'/',
|
2✔ |
|
{ |
2✔ |
|
preHandler: fastify.auth([
|
2✔ |
|
fastify.verifyJWT, |
2✔ |
|
fastify.verifyAdmin |
2✔ |
|
], { |
2✔ |
|
relation: 'and' |
2✔ |
|
}), |
2✔ |
|
schema: {
|
2✔ |
|
hide: true, |
2✔ |
|
params: {
|
2✔ |
|
type: 'object', |
2✔ |
|
properties: {
|
2✔ |
|
id: { type: 'string', format: 'uuid' } |
2✔ |
|
}, |
2✔ |
|
required: ['id'] |
2✔ |
|
} |
2✔ |
|
} |
2✔ |
|
}, |
2✔ |
|
// DELETE user as an admin
|
2✔ |
|
async function deleteAdminUserHandler (request, reply) { |
2✔ |
|
const userId = request.user.id |
× |
|
const { id: targetUserId } = request.params
|
× |
|
|
× |
|
if (userId === targetUserId) {
|
× |
|
return reply.conflict('You can\'t delete yourself this way') |
× |
|
} |
× |
|
|
× |
|
const query = SQL`
|
× |
|
DELETE from users |
× |
|
WHERE id = ${targetUserId};
|
× |
|
`
|
× |
|
|
× |
|
await fastify.pg.query(query) |
× |
|
|
× |
|
return {
|
× |
|
status: 'ok' |
× |
|
} |
× |
|
} |
× |
|
) |
2✔ |
|
} |
2✔ |