mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +00:00
sync
This commit is contained in:
parent
13cd3bd4a0
commit
52cb96baa3
43 changed files with 3257 additions and 1072 deletions
37
Server/services/sessions.js
Normal file
37
Server/services/sessions.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const Service = require('./Service')
|
||||
|
||||
class SessionsService extends Service {
|
||||
constructor (ctx) {
|
||||
super(ctx)
|
||||
this.Session = ctx.M.Session
|
||||
}
|
||||
|
||||
async get (id) {
|
||||
const user = await this.Session.findOne({ where: { id } })
|
||||
|
||||
if (user === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return user.data
|
||||
}
|
||||
|
||||
async set (id, data, maxAge) {
|
||||
let session = await this.Session.findOne({ where: { id } })
|
||||
if (session === null) {
|
||||
session = this.Session.build({ id })
|
||||
}
|
||||
|
||||
session.data = data
|
||||
session.maxAge = maxAge
|
||||
|
||||
return session.save()
|
||||
}
|
||||
|
||||
async destroy (id) {
|
||||
return (await this.Session.findOne({ where: { id } })).destroy()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = SessionsService
|
Loading…
Add table
Add a link
Reference in a new issue