Skip to content

Instantly share code, notes, and snippets.

@Mattchewone
Last active December 18, 2018 14:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Mattchewone/602bfb5e642c36896516abd5f745b24f to your computer and use it in GitHub Desktop.
import { DefineMap, DefineList, QueryLogic } from 'can'
import feathersClient from '../feathers-client'
import feathersConnection from './connections/feathers'
import feathersQueryLogic from 'feathers-query-logic'
const User = DefineMap.extend({
_id: {
identity: true,
type: 'string'
},
email: 'string',
password: 'string'
})
User.List = DefineList.extend({
'#': User,
get usersById () {
return this.reduce((users, user) => {
users[user._id] = user
return users
}, {})
},
get usersByEmail () {
// Map to object keyed by name for easy lookup
return this.reduce((users, user) => {
users[user.email] = user
return users
}, {})
}
})
User.connection = feathersConnection({
idProp: '_id',
Map: User,
List: User.List,
name: 'user',
feathersService: feathersClient.service('users'),
queryLogic: new QueryLogic(User, feathersQueryLogic)
})
export default User
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment