39 lines
945 B
TypeScript
39 lines
945 B
TypeScript
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
import User from 'App/Models/User'
|
|
|
|
export default class UsersController {
|
|
public async index({}: HttpContextContract) {
|
|
|
|
}
|
|
|
|
public async create({ auth, inertia }: HttpContextContract) {
|
|
if(auth.user?.isAdmin) {
|
|
inertia.render('Users/Create')
|
|
} else {
|
|
inertia
|
|
}
|
|
}
|
|
|
|
public async store({}: HttpContextContract) {}
|
|
|
|
public async show({}: HttpContextContract) {}
|
|
|
|
public async edit({}: HttpContextContract) {}
|
|
|
|
public async update({}: HttpContextContract) {}
|
|
|
|
public async destroy({ auth, response, params }: HttpContextContract) {
|
|
if (auth.user?.isAdmin){
|
|
const user = await User.findOrFail(params.id)
|
|
await user.delete()
|
|
.then(
|
|
() => {
|
|
response.redirect('users.index')
|
|
},
|
|
)
|
|
// TODO implement reasonable error handling.
|
|
.catch(error => console.log(error))
|
|
}
|
|
}
|
|
}
|