|
|
|
const pg = require('../pg')
|
|
|
|
const joinjs = require('join-js').default;
|
|
|
|
const debug = require('debug')('sos:db:session')
|
|
|
|
const mappings = require('../mappings')
|
|
|
|
|
|
|
|
const session = module.exports = {}
|
|
|
|
|
|
|
|
session.create = async (user_uuid, ip_address, user_agent, referer, origin_link_uuid) => {
|
|
|
|
const query = {
|
|
|
|
text: 'select * from sos.login_user_session($1, $2, $3, $4, $5, $6)',
|
|
|
|
values: [
|
|
|
|
user_uuid,
|
|
|
|
'2 hours',
|
|
|
|
ip_address,
|
|
|
|
user_agent,
|
|
|
|
referer,
|
|
|
|
origin_link_uuid
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(query);
|
|
|
|
|
|
|
|
const {rows} = await pg.query(query)
|
|
|
|
return joinjs.map(rows, mappings, 'sessionMap', 'session_')[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
session.validate = async (session_uuid) => {
|
|
|
|
const query = {
|
|
|
|
text: 'select * from sos.validate_session($1)',
|
|
|
|
values: [
|
|
|
|
session_uuid
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(query);
|
|
|
|
|
|
|
|
const {rows} = await pg.query(query)
|
|
|
|
return joinjs.map(rows, mappings, 'sessionMap', 'session_')[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
session.update = async (session_uuid) => {
|
|
|
|
const query = {
|
|
|
|
text: 'select * from sos.update_session($1)',
|
|
|
|
values: [
|
|
|
|
session_uuid
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(query);
|
|
|
|
|
|
|
|
const {rows} = await pg.query(query)
|
|
|
|
return joinjs.map(rows, mappings, 'sessionMap', 'session_')[0];
|
|
|
|
}
|