Free and Open-source video streaming suite. https://miracle-tv.live
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

34 lines
956 B

  1. import uuidv4 from 'uuid/v4';
  2. import db from 'server/db';
  3. import ISession, { ISessionRaw } from 'miracle-tv-shared/src/types/api/v1/interfaces/ISession';
  4. class Sessions {
  5. augmentSession (rawSession?: ISessionRaw): PromiseLike<ISession|null> {
  6. if (rawSession) {
  7. return db('users').where({ id: rawSession.user_id }).get(0)
  8. .then(user => ({ user, id: rawSession.id }));
  9. }
  10. return Promise.resolve(null);
  11. }
  12. getSession (id: string): PromiseLike<ISession|null> {
  13. return db('sessions').where({ id }).get(0).then(this.augmentSession);
  14. }
  15. createSession (rawSession: ISessionRaw): PromiseLike<ISession> {
  16. return db('sessions').insert({
  17. ...rawSession, id: uuidv4(),
  18. }).returning('*').get(0).then(
  19. (session: ISessionRaw) => this.augmentSession(session),
  20. );
  21. }
  22. destroySession (id: string): PromiseLike<boolean> {
  23. return db('sessions').where({ id }).delete();
  24. }
  25. }
  26. export default new Sessions;