mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-17 10:39:09 +00:00
lerna: split up bulk of packages
This commit is contained in:
parent
cb0b1d2410
commit
47a2e5694e
90 changed files with 0 additions and 0 deletions
49
packages/roleypoly-server/services/sessions.js
Normal file
49
packages/roleypoly-server/services/sessions.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
// @flow
|
||||
import Service from './Service'
|
||||
import { type AppContext } from '../Roleypoly'
|
||||
|
||||
type SessionData = {
|
||||
rolling: boolean,
|
||||
maxAge: number,
|
||||
changed: boolean
|
||||
}
|
||||
|
||||
export default class SessionsService extends Service {
|
||||
Session: any
|
||||
constructor (ctx: AppContext) {
|
||||
super(ctx)
|
||||
this.Session = ctx.M.Session
|
||||
}
|
||||
|
||||
async get (id: string, { rolling }: SessionData) {
|
||||
const user = await this.Session.findOne({ where: { id } })
|
||||
|
||||
if (user === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return user.data
|
||||
}
|
||||
|
||||
async set (id: string, data: any, { maxAge, rolling, changed }: SessionData) {
|
||||
let session = await this.Session.findOne({ where: { id } })
|
||||
if (session === null) {
|
||||
session = this.Session.build({ id })
|
||||
}
|
||||
|
||||
console.log(maxAge)
|
||||
|
||||
session.data = data
|
||||
session.maxAge = maxAge
|
||||
|
||||
return session.save()
|
||||
}
|
||||
|
||||
async destroy (id: string) {
|
||||
const sess = await this.Session.findOne({ where: { id } })
|
||||
|
||||
if (sess != null) {
|
||||
return sess.destroy()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue