diff --git a/src/index.ts b/src/index.ts index 928d265..5caf2ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -export { User } from './model/user' -import UserService from './service/user' - -export { - UserService, +export { User } from './model/user' +import UserService from './service/user' + +export { + UserService, } \ No newline at end of file diff --git a/src/service/user.ts b/src/service/user.ts index 1d9dafe..e1b01e7 100644 --- a/src/service/user.ts +++ b/src/service/user.ts @@ -1,42 +1,43 @@ -import PouchDB from 'pouchdb' -import { User } from '../model/user' -import Service, {DatabaseSync} from '../Service' -export default class UserService implements Service { - dbs: DatabaseSync = { - cache: new PouchDB>('user'), - remote: new PouchDB>('https://app.hospitalrun.io/next/user'), - master: new PouchDB>('https://app.hospitalrun.io/next/master') - } - constructor(sync: any){ - if(sync) { - this.dbs.cache.sync(this.dbs.remote, { - live: true, - retry: true - }).on('change', function (change: any) { - // yo, something changed! - }).on('paused', function (info: any) { - // replication was paused, usually because of a lost connection - }).on('active', function (info: any) { - // replication was resumed - }).on('error', function (err: any) { - // totally unhandled error (shouldn't happen) - }); - } - } - - /** - * Search for a User in the Database - */ - findUser({ - }: User){ - return this.dbs.cache.get(...arguments) - } - /** - * Search for a User in the Database - */ - findUserById({ - id - }: User){ - return this.dbs.cache.get(...arguments) - } -} +import PouchDB from 'pouchdb' +import { User } from '../model/user' +import Service, {DatabaseSync} from '../Service' +export default class UserService implements Service { + dbs: DatabaseSync = { + // TODO: Move db config to constructor OR setup helper to tell if we are NodeJS/Browser and prefix filepath in Node + cache: new PouchDB>('./.data/user'), + remote: new PouchDB>('https://app.hospitalrun.io/next/user'), + master: new PouchDB>('https://app.hospitalrun.io/next/master') + } + constructor(sync: any){ + if(sync) { + //this.dbs.cache.sync(this.dbs.remote, { + // live: true, + // retry: true + //}).on('change', function (change: any) { + // // yo, something changed! + //}).on('paused', function (info: any) { + // // replication was paused, usually because of a lost connection + //}).on('active', function (info: any) { + // // replication was resumed + //}).on('error', function (err: any) { + // // totally unhandled error (shouldn't happen) + //}); + } + } + + /** + * Search for a User in the Database + */ + findUser({ + }: User){ + return this.dbs.cache.get(...arguments) + } + /** + * Search for a User in the Database + */ + findUserById({ + id + }: User){ + return this.dbs.cache.get(...arguments) + } +}