-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update example apps * deps: update example project deps * feat: finish social-network example updates
- Loading branch information
1 parent
824caab
commit a03cde5
Showing
60 changed files
with
789 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
|
||
## Running / Development | ||
|
||
* `lux db:reset` | ||
* `lux db:migrate` | ||
* `lux db:seed` | ||
* `lux serve` | ||
|
||
## Testing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import { Controller } from 'lux-framework'; | ||
|
||
class ActionsController extends Controller { | ||
params = [ | ||
'trackableId', | ||
'trackableType' | ||
]; | ||
|
||
} | ||
|
||
export default ActionsController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { Controller } from 'lux-framework'; | ||
|
||
class FriendshipsController extends Controller { | ||
params = [ | ||
'userId' | ||
]; | ||
|
||
} | ||
|
||
export default FriendshipsController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,89 @@ | ||
import { Model } from 'lux-framework'; | ||
|
||
import Comment from './comment'; | ||
import Notification from './notification'; | ||
import Post from './post'; | ||
import Reaction from './reaction'; | ||
import User from './user'; | ||
|
||
/* TODO: Add support for polymorphic relationship to a 'trackable'. | ||
* https://github.com/postlight/lux/issues/75 | ||
*/ | ||
class Action extends Model { | ||
static attributes = { | ||
trackableId: { | ||
type: 'integer', | ||
size: 4 | ||
}, | ||
|
||
trackableType: { | ||
type: 'text' | ||
static hooks = { | ||
async afterCreate(action) { | ||
await action.notifyOwner(); | ||
} | ||
}; | ||
|
||
static hasOne = { | ||
user: { | ||
model: 'user', | ||
reverse: 'actions' | ||
async notifyOwner() { | ||
const { trackableId, trackableType } = this; | ||
let params; | ||
|
||
if (trackableType === 'Comment') { | ||
const { | ||
postId, | ||
userId | ||
} = await Comment.find(trackableId, { | ||
select: ['postId', 'userId'] | ||
}); | ||
|
||
const [ | ||
{ name: userName }, | ||
{ userId: recipientId } | ||
] = await Promise.all([ | ||
User.find(userId, { select: ['name'] }), | ||
Post.find(postId, { select: ['userId'] }) | ||
]); | ||
|
||
params = { | ||
recipientId, | ||
message: `${userName} commented on your post!` | ||
}; | ||
} else if (trackableType === 'Reaction') { | ||
let reactableId; | ||
let reactableModel = Post; | ||
|
||
const { | ||
commentId, | ||
postId, | ||
type, | ||
userId | ||
} = await Reaction.find(trackableId, { | ||
select: [ | ||
'commentId', | ||
'postId', | ||
'type', | ||
'userId' | ||
] | ||
}); | ||
|
||
if (!postId) { | ||
reactableId = commentId; | ||
reactableModel = Comment; | ||
} else { | ||
reactableId = postId; | ||
} | ||
|
||
const [ | ||
{ name: userName }, | ||
{ userId: recipientId } | ||
] = await Promise.all([ | ||
User.find(userId, { select: ['name'] }), | ||
reactableModel.find(reactableId, { select: ['userId'] }) | ||
]); | ||
|
||
params = { | ||
recipientId, | ||
message: `${userName} reacted with ${type} to your ` + | ||
`${reactableModel.name.toLowerCase()}!` | ||
}; | ||
} | ||
}; | ||
|
||
if (params) { | ||
return await Notification.create(params); | ||
} | ||
} | ||
} | ||
|
||
export default Action; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.