appusers.ts 758 Bytes
Newer Older
chinguyen's avatar
chinguyen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import * as uuid from 'uuid'
import { AppUser } from './../sqlz/models/appuser'
import { Language } from '../sqlz/models/language'

export function create(appUser: any): Promise<any> {

  return Language.findOne({
    where: { name: 'fr' }
  })
    .then(language => {
      return AppUser
        .create({
          id: uuid.v1(),
          email: appUser.email,
          pwd: appUser.pwd,
          languageId: language.get('id')
        })
    })
}

export function findAll(): Promise<any> {
  return AppUser
    .findAll({ include: [{ all: true }] })
}

export function login(appUser: any): Promise<any> {
  return AppUser
    .findOne({
      where: {
        email: appUser.email,
        pwd: appUser.pwd
      },
      include: [Language]
    })
}