Skip to content

Commit

Permalink
refactor (user/database): nome is not unique
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Jan 24, 2022
1 parent 0aac352 commit ef819d1
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 45 deletions.
98 changes: 53 additions & 45 deletions src/adonisjs/app/Controllers/Http/v1/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,52 +122,60 @@ class UserController {
eventRel = await Event.find(event_id)

if (eventRel != null) {
const user = new User()

user.id = await uuidv4()
user.username = request.input('username')
user.email = request.input('email')
user.password = request.input('password')
user.login = request.input('login')
user.grade = request.input('grade')

const institution_id = request.input('institution')
let ins = null
if (institution_id != null)
ins = await Institution.findBy('acronym', institution_id)
if (ins != null)
user.institution_id = ins.id

await user.save(trx)
feedback += 'user ' + user.username + ' created'

/*
if (eventRel.role_id != null) {
console.log('=== linking role')
console.log(eventRel.role_id)
const ul = await User.find(user.id)
console.log(user.id)
const role = await Role.find(eventRel.role_id)
const roles = await ul.roles()
console.log('--- role found')
console.log(roles)
roles.attach(eventRel.role_id)
feedback += role.slug + ' role has given to the user ' + user.username + ';'
if (eventRel.active > 0) {
const user = new User()

user.id = await uuidv4()
user.username = request.input('username')
user.email = request.input('email')
user.password = request.input('password')
user.login = request.input('login')
user.grade = request.input('grade')

const institution_id = request.input('institution')
let ins = null
if (institution_id != null)
ins = await Institution.findBy('acronym', institution_id)
if (ins != null)
user.institution_id = ins.id

await user.save(trx)
feedback += 'user ' + user.username + ' created'

/*
if (eventRel.role_id != null) {
console.log('=== linking role')
console.log(eventRel.role_id)
const ul = await User.find(user.id)
console.log(user.id)
const role = await Role.find(eventRel.role_id)
const roles = await ul.roles()
console.log('--- role found')
console.log(roles)
roles.attach(eventRel.role_id)
feedback += role.slug + ' role has given to the user ' + user.username + ';'
}
if (eventRel.group_id != null) {
console.log('=== linking group')
console.log(eventRel.group_id)
const group = await Group.find(eventRel.group_id)
console.log('--- role found')
await user.groups().attach(eventRel.group_id)
feedback += group.title + ' group has assigned to the user ' + user.username
}
*/

trx.commit()

return response.json(user)
} else {
trx.rollback()
console.log('expired authorization for self signin');
return response.status(500).json({
type: 'unauthorized',
message: 'expired authorization for self signin'})
}
if (eventRel.group_id != null) {
console.log('=== linking group')
console.log(eventRel.group_id)
const group = await Group.find(eventRel.group_id)
console.log('--- role found')
await user.groups().attach(eventRel.group_id)
feedback += group.title + ' group has assigned to the user ' + user.username
}
*/

trx.commit()

return response.json(user)
} else {
trx.rollback()
console.log('not authorized self signin');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')

class UserUpdateColumnUsernameSchema extends Schema {
up () {
this.table('users', (table) => {
table.dropUnique('username')
})
}

down () {
this.table('users', (table) => {
table.unique('username')
})
}
}

module.exports = UserUpdateColumnUsernameSchema

0 comments on commit ef819d1

Please sign in to comment.