Skip to content

Commit a102b7c

Browse files
Merge pull request #1 from williamtcastro/function_create-events
Function create events
2 parents bd667ea + f68c173 commit a102b7c

28 files changed

+7641
-5498
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
root = true
33

44
[*]
5-
indent_size = 2
5+
indent_size = 4
66
indent_style = space
77
end_of_line = lf
88
charset = utf-8

.env.test renamed to .env.testing

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
HOST=127.0.0.1
2+
PORT=4000
3+
4+
NODE_ENV=testing
15
DB_CONNECTION=sqlite
26
DB_HOST=127.0.0.1
37
DB_PORT=3306

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tmp
66

77
# Environment variables, never commit this file
88
.env
9+
.env-test
910

1011
# The development sqlite file
1112
database/development.sqlite

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
node_js:
3+
- 10.16.3
4+
cache: npm
5+
6+
install:
7+
- npm ci
8+
9+
sricpt:
10+
- adonis test
11+
- npm run build
12+
13+
deploy:
14+
provider: pages
15+
skip-clanup: true
16+
github-token: $GITHUB_TOKEN
17+
on:
18+
branch: master
19+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
2+
const Event = use('App/Models/Event')
3+
4+
class EventController {
5+
async index() {
6+
const events = Event.query()
7+
.with('user', builder => {
8+
builder.select(['id', 'name'])
9+
})
10+
.fetch()
11+
return events
12+
}
13+
14+
async show({ params }) {
15+
const event = await Event.find(params.id)
16+
await event.load('user', builder => {
17+
builder.select(['id', 'name'])
18+
})
19+
return event
20+
}
21+
22+
async store({ request, response }) {
23+
const data = request.only([
24+
'title',
25+
'description',
26+
'location_addres',
27+
'location_city_state',
28+
'start_time',
29+
'event_time',
30+
'user_id',
31+
'event_type',
32+
'language',
33+
'dificult_level',
34+
'max_attendess',
35+
'is_public',
36+
'require_registration',
37+
'website',
38+
])
39+
40+
const event = await Event.create(data)
41+
42+
return response.status(201).json(event)
43+
}
44+
}
45+
46+
module.exports = EventController

app/Controllers/Http/RegisterUserController.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
const User = use('App/Models/User')
33

44
class RegisterUserController {
5-
async store({ request }) {
5+
async store({ request, response }) {
66
const data = request.only(['email', 'username', 'name', 'password'])
7-
await User.create(data)
7+
const user = await User.create(data)
8+
if (user) return response.status(201).json({ message: 'user created' })
89
}
910
}
1011

app/Controllers/Http/ResetPasswordController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ResetPasswordController {
1818
const user = await userToken.user().fetch()
1919
user.password = password
2020
await user.save()
21+
22+
return response.status(201).json({ mensage: 'Password reset' })
2123
}
2224
}
2325

app/Models/Event.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
2+
const Model = use('Model')
3+
4+
class Event extends Model {
5+
user() {
6+
return this.belongsTo('App/Models/User')
7+
}
8+
}
9+
10+
module.exports = Event

app/Models/User.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class User extends Model {
1818
tokens() {
1919
return this.hasMany('App/Models/Token')
2020
}
21+
22+
events() {
23+
return this.hasMany('App/Models/Event')
24+
}
2125
}
2226

2327
module.exports = User

app/Validators/Event.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const Antl = use('Antl')
2+
3+
class Event {
4+
get validateAll() {
5+
return true
6+
}
7+
8+
get rules() {
9+
return {
10+
title: 'required',
11+
description: 'required',
12+
location_addres: 'required',
13+
location_city_state: 'required',
14+
start_time: 'required',
15+
event_time: 'required',
16+
user_id: 'required|exists:users,id',
17+
}
18+
}
19+
20+
get messages() {
21+
return Antl.list('validation')
22+
}
23+
}
24+
25+
module.exports = Event

0 commit comments

Comments
 (0)