Skip to content

Commit 0532505

Browse files
committed
adding websockets
1 parent a7c9b69 commit 0532505

File tree

14 files changed

+49
-33
lines changed

14 files changed

+49
-33
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
node_modules
22
package-lock.json
33

4+
public/uploads
5+
46
tmp
57

68
.env

app/Controllers/Http/Auth/AuthController.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
'use strict'
22

33
const Database = use('Database')
4+
45
const User = use('App/Models/User')
56
const Role = use('Role')
67

8+
const Ws = use('Ws')
9+
710
class AuthController {
811

912
async register({ request, response }) {
@@ -25,6 +28,12 @@ class AuthController {
2528
await user.roles().attach([ userRole.id ], null, trx)
2629

2730
await trx.commit()
31+
32+
const topic = await Ws.getChannel('notifications').topic('notifications')
33+
if (topic) {
34+
topic.broadcast('new:user')
35+
}
36+
2837
return response.status(201).send({ data: user })
2938

3039
} catch(error) {
@@ -64,7 +73,7 @@ class AuthController {
6473
refresh_token = request.header('refresh_token')
6574
}
6675

67-
const loggedOut = await auth
76+
await auth
6877
.authenticator('jwt')
6978
.revokeTokens([refresh_token], true)
7079

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
class NotificationController {
4+
constructor ({ socket, request }) {
5+
this.socket = socket
6+
this.request = request
7+
}
8+
9+
onMessage (message) {
10+
this.socket.broadcast('message', message)
11+
}
12+
13+
onClose () {
14+
this.socket.broadcastToAll('drop:connection')
15+
}
16+
}
17+
18+
module.exports = NotificationController

app/Helpers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const manage_single_upload = async (file, path = null) => {
3737
path = path ? path : Helpers.publicPath('uploads')
3838
// gera um nome aleatorio
3939
const random_name = await str_random(30)
40-
let filename = `${new Date().getTime()}-${randomName}.${file.subtype}`
40+
let filename = `${new Date().getTime()}-${random_name}.${file.subtype}`
4141

4242
// renomeia o arquivo e move ele para o path
4343
await file.move(path, {
@@ -55,7 +55,7 @@ const manage_single_upload = async (file, path = null) => {
5555
* @return { Object }
5656
*/
5757
const manage_multiple_uploads = async (fileJar, path = null) => {
58-
const path = path ? path : Helpers.publicPath('uploads')
58+
path = path ? path : Helpers.publicPath('uploads')
5959
let success = [],
6060
errors = []
6161

app/Models/Hooks/OrderHook.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
const OrderHook = exports = module.exports = {}
44

55
OrderHook.updateValues = async (model) => {
6-
model.SsideLoaded.subtotal = await model.items().getSum('subtotal')
7-
model.SsideLoaded.qty_items = await model.items().getSum('quantity')
8-
model.SsideLoaded.discount = await model.discounts().getSum('discount')
6+
model.$sideLoaded.subtotal = await model.items().getSum('subtotal')
7+
model.$sideLoaded.qty_items = await model.items().getSum('quantity')
8+
model.$sideLoaded.discount = await model.discounts().getSum('discount')
99
model.total = model.$sideLoaded.subtotal - model.$sideLoaded.discount
1010
}
1111

app/Models/Image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Image extends Model {
1212

1313
getUrl({ path }){
1414

15-
return `${Env.get('APP_URL')}/images/${path}`
15+
return `${Env.get('APP_URL')}/uploads/${path}`
1616

1717
}
1818

app/Validators/Admin/StoreCategory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class StoreCategory {
44
get rules () {
55
return {
66
title: 'required',
7-
description: 'description'
7+
description: 'required'
88
}
99
}
1010
}

config/cors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
| Function - Receives the current origin and should return one of the above values.
1717
|
1818
*/
19-
origin: false,
19+
origin: true,
2020

2121
/*
2222
|--------------------------------------------------------------------------

database/migrations/1597874686212_coupon_schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class CouponSchema extends Schema {
1212
table.dateTime('valid_until')
1313
table.integer('quantity').defaultTo(1)
1414
table.enu('can_use_for', ['product', 'client', 'product_client', 'all'])
15+
table.decimal('discount', 12, 2).defaultTo(0.0)
1516

1617
table.enu('type', ['free', 'percent', 'currency']).defaultTo('currency')
1718
table.boolean('recursive').defaultTo(false)

server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ const { Ignitor } = require('@adonisjs/ignitor')
2121

2222
new Ignitor(require('@adonisjs/fold'))
2323
.appRoot(__dirname)
24+
.wsServer()
2425
.fireHttpServer()
2526
.catch(console.error)

0 commit comments

Comments
 (0)