Skip to content
Snippets Groups Projects
Commit 204a5c8b authored by Richard Fernando Heise Ferreira's avatar Richard Fernando Heise Ferreira
Browse files

Merge branch 'issue/3-delete-user-route' into 'develop'

Issue #3: ADD Delete User Route

See merge request !3
parents 7c2ed1bb a1ef1119
No related branches found
No related tags found
1 merge request!3Issue #3: ADD Delete User Route
......@@ -69,4 +69,13 @@ export class UserRepo {
return userSchemas.userModelSchema.parse(ret)
}
async delete(id: UserModel['id']): Promise<UserModel>{
const [ret] = await db
.delete(userTable)
.where(eq(userTable.id, id))
.returning()
return userSchemas.userModelSchema.parse(ret)
}
}
......@@ -75,3 +75,26 @@ export const userRouter = honoWithJwt()
}
})
.post('/delete/:id',
async (c) => {
try {
const id = c.req.param('id')
const user = userSchemas.userDtoSchema.parse(
await service.delete(id!)
)
return c.json(user)
} catch (e) {
return c.json(
createApexError({
status: 'error',
message: 'could not delete user',
code: HttpStatus.BAD_REQUEST,
path: c.req.routePath,
suggestion: 'check the input and try again',
}),
HttpStatus.BAD_REQUEST
)
}
}
)
......@@ -58,4 +58,9 @@ export class UserService {
user.password = hashPassword(user.password)
return this.repo.update(user)
}
async delete(user: UserModel['id']): Promise<UserModel> {
return this.repo.delete(user)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment